diff options
author | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 13:32:54 +0000 |
---|---|---|
committer | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 13:32:54 +0000 |
commit | 44756393341958f38360f7f35c4cda537d275344 (patch) | |
tree | 3b4c43e0bc6a9b6e90275068a07c598a14bc10a5 /base/word_iterator.cc | |
parent | c52e233831bbbf7c9a162f8ced0269ee7ed0c87d (diff) | |
download | chromium_src-44756393341958f38360f7f35c4cda537d275344.zip chromium_src-44756393341958f38360f7f35c4cda537d275344.tar.gz chromium_src-44756393341958f38360f7f35c4cda537d275344.tar.bz2 |
UTF16 vs 32 issues.
Review URL: http://chrome-reviews.prom.corp.google.com/1091
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@373 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/word_iterator.cc')
-rw-r--r-- | base/word_iterator.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/base/word_iterator.cc b/base/word_iterator.cc index 1291630..a21105c 100644 --- a/base/word_iterator.cc +++ b/base/word_iterator.cc @@ -60,9 +60,26 @@ bool WordIterator::Init() { NOTREACHED(); break_type = UBRK_LINE; } +#ifdef U_WCHAR_IS_UTF16 iter_ = ubrk_open(break_type, NULL, string_.data(), static_cast<int32_t>(string_.size()), &status); +#else // U_WCHAR_IS_UTF16 + // When wchar_t is wider than UChar (16 bits), transform |string_| into a + // UChar* string. Size the UChar* buffer to be large enough to hold twice + // as many UTF-16 code points as there are UCS-4 characters, in case each + // character translates to a UTF-16 surrogate pair, and leave room for a NUL + // terminator. + // TODO(avi): avoid this alloc + chars_.resize(wide.length() * sizeof(UChar) + 1); + + UErrorCode error = U_ZERO_ERROR; + int32_t destLength; + u_strFromWCS(&chars_[0], chars_.size(), &destLength, string_.data(), + string_.length(), &error); + + iter_ = ubrk_open(break_type, NULL, chars_, destLength, &status); +#endif if (U_FAILURE(status)) { NOTREACHED() << "ubrk_open failed"; return false; |