blob: 68a49280245f90479c157ebaea258474665deffe [file] [log] [blame]
The Android Open Source Project455ed292009-03-13 13:04:22 -07001/*
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
22namespace android {
23
24// Returns Unicode codepoint relevant to string "src", and set "next" to the
25// next index. Returns negative value when input is invalid.
26int GetCodePointFromUtf8(const char *src, size_t len, size_t index, int *next);
27
28// Returns codepoint which is "phonetically sortable", whose definition
29// depends on each Locale. Note that currently this function considers only
30// Japanese. The variable "next_is_consumed" is set to true if "next_codepoint"
31// is "consumed" (e.g. Japanese halfwidth katakana's voiced mark is consumed
Daisuke Miyakawa0c45e822009-03-27 19:41:52 -070032// when previous "codepoint" is appropriate). If the codepoint should not be
33// considered when sorting (e.g. whitespaces), -1 is returned.
The Android Open Source Project455ed292009-03-13 13:04:22 -070034int GetPhoneticallySortableCodePoint(int codepoint,
35 int next_codepoint,
36 bool *next_is_consumed);
37
Daisuke Miyakawad28cdc42009-05-18 14:51:52 +090038// Returns codepoint which is "normalized", whose definition depends on each
39// Locale. Note that currently this function normalizes only Japanese; the
40// other characters are remained as is.
41// The variable "next_is_consumed" is set to true if "next_codepoint"
42// is "consumed" (e.g. Japanese halfwidth katakana's voiced mark is consumed
43// when previous "codepoint" is appropriate, like half-width "ka").
44//
45// In Japanese, "normalized" means that half-width and full-width katakana is
46// appropriately converted to hiragana.
47int GetNormalizedCodePoint(int codepoint,
48 int next_codepoint,
49 bool *next_is_consumed);
50
The Android Open Source Project455ed292009-03-13 13:04:22 -070051// Pushes Utf8 expression of "codepoint" to "dst". Returns true when successful.
52// If input is invalid or the length of the destination is not enough,
53// returns false.
54bool GetUtf8FromCodePoint(int codepoint, char *dst, size_t len, size_t *index);
55
56// Creates a "phonetically sortable" Utf8 string and push it into "dst".
57// *dst must be freed after being used outside.
58// If "src" is NULL or its length is 0, "dst" is set to \uFFFF.
59//
60// Note that currently this function considers only Japanese.
61bool GetPhoneticallySortableString(const char *src, char **dst, size_t *len);
62
Daisuke Miyakawad28cdc42009-05-18 14:51:52 +090063// Creates a "normalized" Utf8 string and push it into "dst". *dst must be
64// freed after being used outside.
65// If "src" is NULL or its length is 0, "dst" is set to \uFFFF.
66//
67// Note that currently this function considers only Japanese.
68bool GetNormalizedString(const char *src, char **dst, size_t *len);
69
The Android Open Source Project455ed292009-03-13 13:04:22 -070070} // namespace android
71
72#endif