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

Side by Side Diff: src/objects.cc

Issue 121173009: String:WriteUtf8: Add REPLACE_INVALID_UTF8 option (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: DISALLOW_INVALID_UTF8 flag and fixes Created 6 years, 11 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 8294 matching lines...) Expand 10 before | Expand all | Expand 10 after
8305 // Convert the UTF-16 string to a UTF-8 buffer. Start at the specified offset. 8305 // Convert the UTF-16 string to a UTF-8 buffer. Start at the specified offset.
8306 stream.Reset(this, offset); 8306 stream.Reset(this, offset);
8307 character_position = offset; 8307 character_position = offset;
8308 int utf8_byte_position = 0; 8308 int utf8_byte_position = 0;
8309 last = unibrow::Utf16::kNoPreviousCharacter; 8309 last = unibrow::Utf16::kNoPreviousCharacter;
8310 while (stream.HasMore() && character_position++ < offset + length) { 8310 while (stream.HasMore() && character_position++ < offset + length) {
8311 uint16_t character = stream.GetNext(); 8311 uint16_t character = stream.GetNext();
8312 if (allow_nulls == DISALLOW_NULLS && character == 0) { 8312 if (allow_nulls == DISALLOW_NULLS && character == 0) {
8313 character = ' '; 8313 character = ' ';
8314 } 8314 }
8315 // @TODO Fix this Utf8::Encode call site somehow.
8315 utf8_byte_position += 8316 utf8_byte_position +=
8316 unibrow::Utf8::Encode(result + utf8_byte_position, character, last); 8317 unibrow::Utf8::Encode(result + utf8_byte_position, character, last);
8317 last = character; 8318 last = character;
8318 } 8319 }
8319 result[utf8_byte_position] = 0; 8320 result[utf8_byte_position] = 0;
8320 return SmartArrayPointer<char>(result); 8321 return SmartArrayPointer<char>(result);
8321 } 8322 }
8322 8323
8323 8324
8324 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls, 8325 SmartArrayPointer<char> String::ToCString(AllowNullsFlag allow_nulls,
(...skipping 8341 matching lines...) Expand 10 before | Expand all | Expand 10 after
16666 #define ERROR_MESSAGES_TEXTS(C, T) T, 16667 #define ERROR_MESSAGES_TEXTS(C, T) T,
16667 static const char* error_messages_[] = { 16668 static const char* error_messages_[] = {
16668 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16669 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16669 }; 16670 };
16670 #undef ERROR_MESSAGES_TEXTS 16671 #undef ERROR_MESSAGES_TEXTS
16671 return error_messages_[reason]; 16672 return error_messages_[reason];
16672 } 16673 }
16673 16674
16674 16675
16675 } } // namespace v8::internal 16676 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698