Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(961)

Unified Diff: runtime/vm/unicode.cc

Issue 11365243: Revert OneByteString back to ISO Latin-1 instead of ASCII (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/unicode.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/unicode.cc
===================================================================
--- runtime/vm/unicode.cc (revision 14982)
+++ runtime/vm/unicode.cc (working copy)
@@ -58,8 +58,8 @@
}
-static bool IsAsciiSequenceStart(uint8_t code_unit) {
- // Check is codepoint is <= U+007F
+static bool IsLatin1SequenceStart(uint8_t code_unit) {
+ // Check is codepoint is <= U+00FF
return (code_unit <= Utf8::kMaxOneByteChar);
}
@@ -101,17 +101,17 @@
intptr_t array_len,
Type* type) {
intptr_t len = 0;
- Type char_type = kAscii;
+ Type char_type = kLatin1;
for (intptr_t i = 0; i < array_len; i++) {
uint8_t code_unit = utf8_array[i];
if (!IsTrailByte(code_unit)) {
++len;
}
- if (!IsAsciiSequenceStart(code_unit)) { // > U+007F
+ if (!IsLatin1SequenceStart(code_unit)) { // > U+00FF
if (IsSmpSequenceStart(code_unit)) { // >= U+10000
char_type = kSMP;
++len;
- } else if (char_type == kAscii) {
+ } else if (char_type == kLatin1) {
char_type = kBMP;
}
}
@@ -251,19 +251,26 @@
}
-bool Utf8::DecodeToAscii(const uint8_t* utf8_array,
- intptr_t array_len,
- uint8_t* dst,
- intptr_t len) {
- if (len < array_len) {
+bool Utf8::DecodeToLatin1(const uint8_t* utf8_array,
+ intptr_t array_len,
+ uint8_t* dst,
+ intptr_t len) {
+ intptr_t i = 0;
+ intptr_t j = 0;
+ intptr_t num_bytes;
+ for (; (i < array_len) && (j < len); i += num_bytes, ++j) {
+ int32_t ch;
+ ASSERT(IsLatin1SequenceStart(utf8_array[i]));
+ num_bytes = Utf8::Decode(&utf8_array[i], (array_len - i), &ch);
+ if (ch == -1) {
+ return false; // invalid input
+ }
+ ASSERT(ch <= 0xff);
+ dst[j] = ch;
+ }
+ if ((i < array_len) && (j == len)) {
return false; // output overflow
}
-#ifdef DEBUG
- for (intptr_t i = 0; i < array_len; i++) {
- ASSERT(IsAsciiSequenceStart(utf8_array[i]));
- }
-#endif
- memmove(dst, utf8_array, array_len);
return true; // success
}
« no previous file with comments | « runtime/vm/unicode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698