summaryrefslogtreecommitdiff
path: root/android/PhoneticStringUtils.cpp
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2010-11-15 11:37:04 -0800
committerKenny Root <kroot@google.com>2010-11-15 11:37:36 -0800
commit0b161e0ce405b617a85d0f1b717bd3d7df056ced (patch)
treed9776d5101ed49ea1eb8d3717067eae938aca016 /android/PhoneticStringUtils.cpp
parent6c75f0d20ef5ade654dc32eae196b6d212e9d353 (diff)
Update to new Unicode.h includes
Change-Id: Ibb9ca5833f9c0b3313ff0e9bc70348d268aaf4e2
Diffstat (limited to 'android/PhoneticStringUtils.cpp')
-rw-r--r--android/PhoneticStringUtils.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/android/PhoneticStringUtils.cpp b/android/PhoneticStringUtils.cpp
index dbf1f4f..0b971d2 100644
--- a/android/PhoneticStringUtils.cpp
+++ b/android/PhoneticStringUtils.cpp
@@ -18,7 +18,7 @@
#include <stdlib.h>
#include "PhoneticStringUtils.h"
-#include <utils/String8.h>
+#include <utils/Unicode.h>
// We'd like 0 length string last of sorted list. So when input string is NULL
// or 0 length string, we use these instead.
@@ -223,21 +223,22 @@ static bool GetExpectedString(
char32_t codepoints[MAX_CODEPOINTS]; // if array size is changed the for loop needs to be changed
- size_t src_len = utf8_length(src);
- if (src_len == 0) {
+ ssize_t src_len = utf8_length(src);
+ if (src_len <= 0) {
return false;
}
+
bool next_is_consumed;
size_t j = 0;
- for (size_t i = 0; i < src_len && j < MAX_CODEPOINTS;) {
- int32_t ret = utf32_at(src, src_len, i, &i);
+ for (size_t i = 0; i < (size_t)src_len && j < MAX_CODEPOINTS;) {
+ int32_t ret = utf32_from_utf8_at(src, src_len, i, &i);
if (ret < 0) {
// failed to parse UTF-8
return false;
}
ret = get_codepoint_function(
static_cast<char32_t>(ret),
- i + 1 < src_len ? src[i + 1] : 0,
+ i + 1 < (size_t)src_len ? src[i + 1] : 0,
&next_is_consumed);
if (ret > 0) {
codepoints[j] = static_cast<char32_t>(ret);
@@ -256,18 +257,18 @@ static bool GetExpectedString(
length = 1;
}
- size_t new_len = utf8_length_from_utf32(codepoints, length);
- *dst = static_cast<char *>(malloc(new_len + 1));
- if (*dst == NULL) {
+ ssize_t new_len = utf32_to_utf8_length(codepoints, length);
+ if (new_len < 0) {
return false;
}
- if (utf32_to_utf8(codepoints, length, *dst, new_len + 1) != new_len) {
- free(*dst);
- *dst = NULL;
+ *dst = static_cast<char *>(malloc(new_len + 1));
+ if (*dst == NULL) {
return false;
}
+ utf32_to_utf8(codepoints, length, *dst);
+
*dst_len = new_len;
return true;
}