blob: 7ebf9e080eed1b1770a2eede13ad39fdb21ae133 [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
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} // namespace android
51
52#endif