Transliterator.java revision 1c025319e6fea7b68817a59f0a103dcf02672c8d
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package libcore.icu;
18
19/**
20 * Exposes icu4c's Transliterator.
21 */
22public final class Transliterator {
23  private long peer;
24
25  /**
26   * Creates a new Transliterator for the given id.
27   */
28  public Transliterator(String id) {
29    peer = create(id);
30  }
31
32  @Override protected synchronized void finalize() throws Throwable {
33    try {
34      destroy(peer);
35      peer = 0;
36    } finally {
37      super.finalize();
38    }
39  }
40
41  /**
42   * Returns the ids of all known transliterators.
43   */
44  public static native String[] getAvailableIDs();
45
46  /**
47   * Transliterates the specified string.
48   */
49  public String transliterate(String s) {
50    return transliterate(peer, s);
51  }
52
53  private static native long create(String id);
54  private static native void destroy(long peer);
55  private static native String transliterate(long peer, String s);
56}
57