| 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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } | 457 } |
| 458 | 458 |
| 459 template <typename CharType> | 459 template <typename CharType> |
| 460 CString TextCodecUTF8::EncodeCommon(const CharType* characters, size_t length) { | 460 CString TextCodecUTF8::EncodeCommon(const CharType* characters, size_t length) { |
| 461 // The maximum number of UTF-8 bytes needed per UTF-16 code unit is 3. | 461 // The maximum number of UTF-8 bytes needed per UTF-16 code unit is 3. |
| 462 // BMP characters take only one UTF-16 code unit and can take up to 3 bytes | 462 // BMP characters take only one UTF-16 code unit and can take up to 3 bytes |
| 463 // (3x). | 463 // (3x). |
| 464 // Non-BMP characters take two UTF-16 code units and can take up to 4 bytes | 464 // Non-BMP characters take two UTF-16 code units and can take up to 4 bytes |
| 465 // (2x). | 465 // (2x). |
| 466 if (length > std::numeric_limits<size_t>::max() / 3) | 466 if (length > std::numeric_limits<size_t>::max() / 3) |
| 467 CRASH(); | 467 IMMEDIATE_CRASH(); |
| 468 Vector<uint8_t> bytes(length * 3); | 468 Vector<uint8_t> bytes(length * 3); |
| 469 | 469 |
| 470 size_t i = 0; | 470 size_t i = 0; |
| 471 size_t bytes_written = 0; | 471 size_t bytes_written = 0; |
| 472 while (i < length) { | 472 while (i < length) { |
| 473 UChar32 character; | 473 UChar32 character; |
| 474 U16_NEXT(characters, i, length, character); | 474 U16_NEXT(characters, i, length, character); |
| 475 // U16_NEXT will simply emit a surrogate code point if an unmatched | 475 // U16_NEXT will simply emit a surrogate code point if an unmatched |
| 476 // surrogate is encountered; we must convert it to a | 476 // surrogate is encountered; we must convert it to a |
| 477 // U+FFFD (REPLACEMENT CHARACTER) here. | 477 // U+FFFD (REPLACEMENT CHARACTER) here. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 489 return EncodeCommon(characters, length); | 489 return EncodeCommon(characters, length); |
| 490 } | 490 } |
| 491 | 491 |
| 492 CString TextCodecUTF8::Encode(const LChar* characters, | 492 CString TextCodecUTF8::Encode(const LChar* characters, |
| 493 size_t length, | 493 size_t length, |
| 494 UnencodableHandling) { | 494 UnencodableHandling) { |
| 495 return EncodeCommon(characters, length); | 495 return EncodeCommon(characters, length); |
| 496 } | 496 } |
| 497 | 497 |
| 498 } // namespace WTF | 498 } // namespace WTF |
| OLD | NEW |