OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/wasm/utf8.h" |
| 6 |
| 7 #include "src/base/logging.h" |
| 8 |
| 9 #include "unicode/utf8.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 inline bool IsValidCharacter(uint32_t code_point) { |
| 14 // Excludes non-characters (U+FDD0..U+FDEF, and all codepoints ending in |
| 15 // 0xFFFE or 0xFFFF) from the set of valid code points. |
| 16 return code_point < 0xD800u || |
| 17 (code_point >= 0xE000u && code_point < 0xFDD0u) || |
| 18 (code_point > 0xFDEFu && code_point <= 0x10FFFFu && |
| 19 (code_point & 0xFFFEu) != 0xFFFEu); |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 24 namespace v8 { |
| 25 namespace internal { |
| 26 namespace wasm { |
| 27 |
| 28 bool IsValidUtf8(const uint8_t *buf, int32_t len) { |
| 29 int32_t char_index = 0; |
| 30 DCHECK(len >= 0); |
| 31 |
| 32 while (char_index < len) { |
| 33 int32_t code_point; |
| 34 U8_NEXT(buf, char_index, len, code_point); |
| 35 if (!IsValidCharacter(code_point)) return false; |
| 36 } |
| 37 return true; |
| 38 } |
| 39 |
| 40 } // namespace wasm |
| 41 } // namespace internal |
| 42 } // namespace v8 |
OLD | NEW |