2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * UTF-8 and Unicode string manipulation functions, plus convenience
18 * functions for working with java/lang/String.
20 #ifndef _DALVIK_STRING
21 #define _DALVIK_STRING
24 * Hash function for modified UTF-8 strings.
26 u4 dvmComputeUtf8Hash(const char* str);
29 * Hash function for string objects.
31 u4 dvmComputeStringHash(StringObject* strObj);
34 * Create a java/lang/String from a C string.
36 * The caller must call dvmReleaseTrackedAlloc() on the return value or
37 * use a non-default value for "allocFlags". It is never appropriate
38 * to use ALLOC_DONT_TRACK with this function.
40 * Returns NULL and throws an exception on failure.
42 StringObject* dvmCreateStringFromCstr(const char* utf8Str, int allocFlags);
45 * Create a java/lang/String from a C string, given its UTF-16 length
46 * (number of UTF-16 code points).
48 * The caller must call dvmReleaseTrackedAlloc() on the return value or
49 * use a non-default value for "allocFlags". It is never appropriate
50 * to use ALLOC_DONT_TRACK with this function.
52 * Returns NULL and throws an exception on failure.
54 StringObject* dvmCreateStringFromCstrAndLength(const char* utf8Str,
55 u4 utf16Length, int allocFlags);
58 * Compute the number of characters in a "modified UTF-8" string. This will
59 * match the result from strlen() so long as there are no multi-byte chars.
61 int dvmUtf8Len(const char* utf8Str);
64 * Convert a UTF-8 string to UTF-16. "utf16Str" must have enough room
67 void dvmConvertUtf8ToUtf16(u2* utf16Str, const char* utf8Str);
70 * Create a java/lang/String from a Unicode string.
72 * The caller must call dvmReleaseTrackedAlloc() on the return value.
74 StringObject* dvmCreateStringFromUnicode(const u2* unichars, int len);
77 * Create a UTF-8 C string from a java/lang/String. Caller must free
80 * Returns NULL if "jstr" is NULL.
82 char* dvmCreateCstrFromString(StringObject* jstr);
85 * Create a UTF-8 C string from a region of a java/lang/String. (Used by
86 * the JNI GetStringUTFRegion call.)
88 void dvmCreateCstrFromStringRegion(StringObject* jstr, int start, int len,
92 * Compute the length in bytes of the modified UTF-8 representation of a
95 int dvmStringUtf8ByteLen(StringObject* jstr);
98 * Get the length in Unicode characters of a string.
100 int dvmStringLen(StringObject* jstr);
103 * Get a pointer to the Unicode data.
105 const u2* dvmStringChars(StringObject* jstr);
108 * Compare two string objects. (This is a dvmHashTableLookup() callback.)
110 int dvmHashcmpStrings(const void* vstrObj1, const void* vstrObj2);
112 #endif /*_DALVIK_STRING*/