Elliott Hughes | 814e403 | 2011-08-23 12:07:56 -0700 | [diff] [blame^] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_UTF_H_ |
| 4 | #define ART_SRC_UTF_H_ |
| 5 | |
| 6 | #include <stddef.h> |
| 7 | #include <stdint.h> |
| 8 | |
| 9 | namespace art { |
| 10 | |
| 11 | /* |
| 12 | * Returns the number of UTF-16 characters in the given modified UTF-8 string. |
| 13 | */ |
| 14 | size_t CountModifiedUtf8Chars(const char* utf8); |
| 15 | |
| 16 | /* |
| 17 | * Returns the number of modified UTF-8 bytes needed to represent the given |
| 18 | * UTF-16 string. |
| 19 | */ |
| 20 | size_t CountUtf8Bytes(const uint16_t* chars, size_t char_count); |
| 21 | |
| 22 | /* |
| 23 | * Convert Modified UTF-8 to UTF-16. |
| 24 | * http://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8 |
| 25 | */ |
| 26 | void ConvertModifiedUtf8ToUtf16(uint16_t* utf16_data_out, const char* utf8_data_in); |
| 27 | |
| 28 | /* |
| 29 | * The java.lang.String hashCode() algorithm. |
| 30 | */ |
| 31 | int32_t ComputeUtf16Hash(const uint16_t* chars, size_t char_count); |
| 32 | |
| 33 | /* |
| 34 | * Retrieve the next UTF-16 character from a UTF-8 string. |
| 35 | * |
| 36 | * Advances "*utf8_data_in" to the start of the next character. |
| 37 | * |
| 38 | * WARNING: If a string is corrupted by dropping a '\0' in the middle |
| 39 | * of a 3-byte sequence, you can end up overrunning the buffer with |
| 40 | * reads (and possibly with the writes if the length was computed and |
| 41 | * cached before the damage). For performance reasons, this function |
| 42 | * assumes that the string being parsed is known to be valid (e.g., by |
| 43 | * already being verified). Most strings we process here are coming |
| 44 | * out of dex files or other internal translations, so the only real |
| 45 | * risk comes from the JNI NewStringUTF call. |
| 46 | */ |
| 47 | uint16_t GetUtf16FromUtf8(const char** utf8_data_in); |
| 48 | |
| 49 | } // namespace art |
| 50 | |
| 51 | #endif // ART_SRC_UTF_H_ |