summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Brown <jeffbrown@google.com> 2011-10-07 13:28:18 -0700
committer Jeff Brown <jeffbrown@google.com> 2011-10-07 13:28:18 -0700
commitde27227026e01c26a9debef77e4e268f242e713e (patch)
tree267a1bbe60b4a1a5f5955e55517dce699c8c9e0f
parentcc0bf53f214d8c9029ce27ac3985dc5c18d5130a (diff)
Fix regression in CursorWindow.copyStingToBuffer.
Bug: 5332296 Change-Id: Iff9eed786f0a8293b6156f883a66a322ddad5e99
-rw-r--r--include/utils/Unicode.h7
-rw-r--r--libs/utils/Unicode.cpp13
2 files changed, 14 insertions, 6 deletions
diff --git a/include/utils/Unicode.h b/include/utils/Unicode.h
index 6afb291f4a..9273533770 100644
--- a/include/utils/Unicode.h
+++ b/include/utils/Unicode.h
@@ -150,6 +150,13 @@ void utf8_to_utf32(const char* src, size_t src_len, char32_t* dst);
ssize_t utf8_to_utf16_length(const uint8_t* src, size_t srcLen);
/**
+ * Convert UTF-8 to UTF-16 including surrogate pairs.
+ * Returns a pointer to the end of the string (where a null terminator might go
+ * if you wanted to add one).
+ */
+char16_t* utf8_to_utf16_no_null_terminator(const uint8_t* src, size_t srcLen, char16_t* dst);
+
+/**
* Convert UTF-8 to UTF-16 including surrogate pairs. The destination buffer
* must be large enough to hold the result as measured by utf8_to_utf16_length
* plus an added NULL terminator.
diff --git a/libs/utils/Unicode.cpp b/libs/utils/Unicode.cpp
index 78c61b4fc6..41cbf035e5 100644
--- a/libs/utils/Unicode.cpp
+++ b/libs/utils/Unicode.cpp
@@ -542,11 +542,7 @@ ssize_t utf8_to_utf16_length(const uint8_t* u8str, size_t u8len)
return u16measuredLen;
}
-/**
- * Convert a UTF-8 string to UTF-16. The destination UTF-16 buffer must have
- * space for NULL at the end.
- */
-void utf8_to_utf16(const uint8_t* u8str, size_t u8len, char16_t* u16str)
+char16_t* utf8_to_utf16_no_null_terminator(const uint8_t* u8str, size_t u8len, char16_t* u16str)
{
const uint8_t* const u8end = u8str + u8len;
const uint8_t* u8cur = u8str;
@@ -569,7 +565,12 @@ void utf8_to_utf16(const uint8_t* u8str, size_t u8len, char16_t* u16str)
u8cur += u8len;
}
- *u16cur = 0;
+ return u16cur;
+}
+
+void utf8_to_utf16(const uint8_t* u8str, size_t u8len, char16_t* u16str) {
+ char16_t* end = utf8_to_utf16_no_null_terminator(u8str, u8len, u16str);
+ *end = 0;
}
}