13aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes/*
23aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * Copyright (C) 2013 The Android Open Source Project
33aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes *
43aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
53aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * you may not use this file except in compliance with the License.
63aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * You may obtain a copy of the License at
73aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes *
83aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
93aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes *
103aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * Unless required by applicable law or agreed to in writing, software
113aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
123aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * See the License for the specific language governing permissions and
143aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes * limitations under the License.
153aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes */
163aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes
173aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughespackage libcore.icu;
183aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes
19860b3c5989a8dd9de73639d8057443aa12fe7b16Elliott Hughes/**
20860b3c5989a8dd9de73639d8057443aa12fe7b16Elliott Hughes * Exposes icu4c's Transliterator.
21860b3c5989a8dd9de73639d8057443aa12fe7b16Elliott Hughes */
223aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughespublic final class Transliterator {
23f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  private long peer;
24f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner
25f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  /**
26f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner   * Creates a new Transliterator for the given id.
27f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner   */
28f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  public Transliterator(String id) {
29f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner    peer = create(id);
30f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  }
31f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner
32f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  @Override protected synchronized void finalize() throws Throwable {
33f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner    try {
34f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner      destroy(peer);
35f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner      peer = 0;
36f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner    } finally {
37f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner      super.finalize();
38f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner    }
39f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  }
40f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner
413aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes  /**
423aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes   * Returns the ids of all known transliterators.
433aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes   */
443aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes  public static native String[] getAvailableIDs();
453aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes
463aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes  /**
47f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner   * Transliterates the specified string.
483aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes   */
49f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  public String transliterate(String s) {
50f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner    return transliterate(peer, s);
51f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  }
523aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes
53f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  private static native long create(String id);
54f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  private static native void destroy(long peer);
55f273ce458c68f5f2b468927392aededc52b8d814Jay Shrauner  private static native String transliterate(long peer, String s);
563aac4ddc4d17c07fa8b4908069d23d5401a77993Elliott Hughes}
57