| 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 // 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 |
| OLD | NEW |