OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> | 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 bool equalUTF16WithUTF8(const UChar* a, const UChar* aEnd, const char* b, const char* bEnd) | 435 bool equalUTF16WithUTF8(const UChar* a, const UChar* aEnd, const char* b, const char* bEnd) |
436 { | 436 { |
437 return equalWithUTF8Internal(a, aEnd, b, bEnd); | 437 return equalWithUTF8Internal(a, aEnd, b, bEnd); |
438 } | 438 } |
439 | 439 |
440 bool equalLatin1WithUTF8(const LChar* a, const LChar* aEnd, const char* b, const char* bEnd) | 440 bool equalLatin1WithUTF8(const LChar* a, const LChar* aEnd, const char* b, const char* bEnd) |
441 { | 441 { |
442 return equalWithUTF8Internal(a, aEnd, b, bEnd); | 442 return equalWithUTF8Internal(a, aEnd, b, bEnd); |
443 } | 443 } |
444 | 444 |
445 bool isUTF8Encoded(const char* data, size_t length) | |
446 { | |
447 // This cast is necessary because U8_NEXT uses int32_ts. | |
tkent
2016/03/02 00:55:55
is it possible that |length| is greater than 2^31?
Jinsuk Kim
2016/03/02 01:14:31
The document data (HTML, CSS, JS, etc) can be theo
tkent
2016/03/02 01:36:39
ok. Even if |length| is larger than the maximum v
| |
448 int32_t srcLen = static_cast<int32_t>(length); | |
449 int32_t charIndex = 0; | |
450 bool markDetected = false; | |
451 | |
452 while (charIndex < srcLen) { | |
453 int32_t codePoint; | |
454 if ((uint8_t)(data[charIndex]) >= 0x80) | |
tkent
2016/03/02 00:55:55
Please do not use C-style type cast.
Jinsuk Kim
2016/03/02 01:14:31
Done.
| |
455 markDetected = true; | |
456 U8_NEXT(data, charIndex, srcLen, codePoint); | |
457 if (!U_IS_UNICODE_CHAR(codePoint)) | |
458 return false; | |
459 } | |
460 return markDetected; | |
461 } | |
462 | |
445 } // namespace Unicode | 463 } // namespace Unicode |
446 } // namespace WTF | 464 } // namespace WTF |
OLD | NEW |