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

Side by Side Diff: Source/wtf/text/TextCodecUTF8.cpp

Issue 23601010: Make UTF-8 encoding of unpaired surrogates match Encoding standard (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased test results Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/fast/encoding/char-encoding-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 // Non-BMP characters take two UTF-16 code units and can take up to 4 bytes (2x). 429 // Non-BMP characters take two UTF-16 code units and can take up to 4 bytes (2x).
430 if (length > numeric_limits<size_t>::max() / 3) 430 if (length > numeric_limits<size_t>::max() / 3)
431 CRASH(); 431 CRASH();
432 Vector<uint8_t> bytes(length * 3); 432 Vector<uint8_t> bytes(length * 3);
433 433
434 size_t i = 0; 434 size_t i = 0;
435 size_t bytesWritten = 0; 435 size_t bytesWritten = 0;
436 while (i < length) { 436 while (i < length) {
437 UChar32 character; 437 UChar32 character;
438 U16_NEXT(characters, i, length, character); 438 U16_NEXT(characters, i, length, character);
439 // U16_NEXT will simply emit a surrogate code point if an unmatched surr ogate
440 // is encountered; we must convert it to a U+FFFD (REPLACEMENT CHARACTER ) here.
441 if (0xD800 <= character && character <= 0xDFFF)
442 character = replacementCharacter;
439 U8_APPEND_UNSAFE(bytes.data(), bytesWritten, character); 443 U8_APPEND_UNSAFE(bytes.data(), bytesWritten, character);
440 } 444 }
441 445
442 return CString(reinterpret_cast<char*>(bytes.data()), bytesWritten); 446 return CString(reinterpret_cast<char*>(bytes.data()), bytesWritten);
443 } 447 }
444 448
445 CString TextCodecUTF8::encode(const UChar* characters, size_t length, Unencodabl eHandling) 449 CString TextCodecUTF8::encode(const UChar* characters, size_t length, Unencodabl eHandling)
446 { 450 {
447 return encodeCommon(characters, length); 451 return encodeCommon(characters, length);
448 } 452 }
449 453
450 CString TextCodecUTF8::encode(const LChar* characters, size_t length, Unencodabl eHandling) 454 CString TextCodecUTF8::encode(const LChar* characters, size_t length, Unencodabl eHandling)
451 { 455 {
452 return encodeCommon(characters, length); 456 return encodeCommon(characters, length);
453 } 457 }
454 458
455 } // namespace WTF 459 } // namespace WTF
OLDNEW
« no previous file with comments | « LayoutTests/fast/encoding/char-encoding-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698