1/*
2 * Copyright (C) 2009 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
17#ifndef _ANDROID_PHONETIC_STRING_UTILS_H
18#define _ANDROID_PHONETIC_STRING_UTILS_H
19
20#include <string.h>  // For size_t.
21#include <utils/String8.h>
22
23namespace android {
24
25// Returns codepoint which is "normalized", whose definition depends on each
26// Locale. Note that currently this function normalizes only Japanese; the
27// other characters are remained as is.
28// The variable "next_is_consumed" is set to true if "next_codepoint"
29// is "consumed" (e.g. Japanese halfwidth katakana's voiced mark is consumed
30// when previous "codepoint" is appropriate, like half-width "ka").
31//
32// In Japanese, "normalized" means that half-width and full-width katakana is
33// appropriately converted to hiragana.
34int GetNormalizedCodePoint(char32_t codepoint,
35                           char32_t next_codepoint,
36                           bool *next_is_consumed);
37
38// Pushes Utf8 expression of "codepoint" to "dst". Returns true when successful.
39// If input is invalid or the length of the destination is not enough,
40// returns false.
41bool GetUtf8FromCodePoint(int codepoint, char *dst, size_t len, size_t *index);
42
43// Creates a "phonetically sortable" Utf8 string and push it into "dst".
44// *dst must be freed after being used outside.
45// If "src" is NULL or its length is 0, "dst" is set to \uFFFF.
46//
47// Note that currently this function considers only Japanese.
48bool GetPhoneticallySortableString(const char *src, char **dst, size_t *len);
49
50// Creates a "normalized" Utf8 string and push it into "dst". *dst must be
51// freed after being used outside.
52// If "src" is NULL or its length is 0, "dst" is set to \uFFFF.
53//
54// Note that currently this function considers only Japanese.
55bool GetNormalizedString(const char *src, char **dst, size_t *len);
56
57}  // namespace android
58
59#endif
60