OLD | NEW |
---|---|
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 Loading... | |
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 if (0xD800 <= character && character <= 0xDFFF) | |
440 character = 0xFFFD; | |
jungshik at Google
2013/08/30 00:39:27
For a future code archaeologist, could you add a c
jsbell
2013/08/30 00:43:56
Will do. I'll also use WTF::Unicode::replacementCh
| |
439 U8_APPEND_UNSAFE(bytes.data(), bytesWritten, character); | 441 U8_APPEND_UNSAFE(bytes.data(), bytesWritten, character); |
440 } | 442 } |
441 | 443 |
442 return CString(reinterpret_cast<char*>(bytes.data()), bytesWritten); | 444 return CString(reinterpret_cast<char*>(bytes.data()), bytesWritten); |
443 } | 445 } |
444 | 446 |
445 CString TextCodecUTF8::encode(const UChar* characters, size_t length, Unencodabl eHandling) | 447 CString TextCodecUTF8::encode(const UChar* characters, size_t length, Unencodabl eHandling) |
446 { | 448 { |
447 return encodeCommon(characters, length); | 449 return encodeCommon(characters, length); |
448 } | 450 } |
449 | 451 |
450 CString TextCodecUTF8::encode(const LChar* characters, size_t length, Unencodabl eHandling) | 452 CString TextCodecUTF8::encode(const LChar* characters, size_t length, Unencodabl eHandling) |
451 { | 453 { |
452 return encodeCommon(characters, length); | 454 return encodeCommon(characters, length); |
453 } | 455 } |
454 | 456 |
455 } // namespace WTF | 457 } // namespace WTF |
OLD | NEW |