History

Various work for tool support in the VM. Update some type names (i.e. _t) and alter API signatures to be more consistent.

arr committed 10 years ago

Commit e5d3f861 parent bcb413516 files · +514 −45Browse files

Showing the changes to src/vm/utf8.cpp (1 of 16 files). Show all

Unified · Split

src/vm/utf8.cpp+8−8
@@ -40,15 +40,15 @@ namespace · 39 unmodified lines
40}40}
41 41
42// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.42// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
43utf8::decode_state disvm::runtime::utf8::decode_step(utf8::decode_state &state, rune_t &codepoint, uint8_t byte)43utf8::decode_state_t disvm::runtime::utf8::decode_step(utf8::decode_state_t &state, rune_t &codepoint, uint8_t byte)
44{44{
45 auto type = uint32_t{ utf8d[byte] };45 auto type = uint32_t{ utf8d[byte] };
46 46
47 codepoint = (state != utf8::decode_state::accept) ?47 codepoint = (state != utf8::decode_state_t::accept) ?
48 (byte & 0x3fu) | (codepoint << 6) :48 (byte & 0x3fu) | (codepoint << 6) :
49 (0xff >> type) & (byte);49 (0xff >> type) & (byte);
50 50
51 state = static_cast<utf8::decode_state>(utf8d[256 + static_cast<uint32_t>(state) + type]);51 state = static_cast<utf8::decode_state_t>(utf8d[256 + static_cast<uint32_t>(state) + type]);
52 return state;52 return state;
53}53}
54 54
@@ -59,15 +59,15 @@ std::size_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, const std · 4 unmodified lines
59 assert(str != nullptr);59 assert(str != nullptr);
60 auto single_character = rune_t{};60 auto single_character = rune_t{};
61 auto points = std::size_t{ 0 };61 auto points = std::size_t{ 0 };
62 auto state = utf8::decode_state::accept;62 auto state = utf8::decode_state_t::accept;
63 63
64 for (auto i = std::size_t{ 0 }; i < max_len; ++i)64 for (auto i = std::size_t{ 0 }; i < max_len; ++i)
65 {65 {
66 if (utf8::decode_state::accept == utf8::decode_step(state, single_character, str[i]))66 if (utf8::decode_state_t::accept == utf8::decode_step(state, single_character, str[i]))
67 points++;67 points++;
68 }68 }
69 69
70 if (state != utf8::decode_state::accept)70 if (state != utf8::decode_state_t::accept)
71 throw invalid_utf8{};71 throw invalid_utf8{};
72 72
73 return points;73 return points;
@@ -76,7 +76,7 @@ std::size_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, const std · 2 unmodified lines
76std::size_t disvm::runtime::utf8::decode(const uint8_t *str, rune_t &codepoint)76std::size_t disvm::runtime::utf8::decode(const uint8_t *str, rune_t &codepoint)
77{77{
78 assert(str != nullptr);78 assert(str != nullptr);
79 auto state = utf8::decode_state::accept;79 auto state = utf8::decode_state_t::accept;
80 80
81 codepoint = 0;81 codepoint = 0;
82 auto begin = str;82 auto begin = str;
@@ -86,7 +86,7 @@ std::size_t disvm::runtime::utf8::decode(const uint8_t *str, rune_t &codepoint) · 3 unmodified lines
86 {86 {
87 curr++;87 curr++;
88 state = utf8::decode_step(state, codepoint, c);88 state = utf8::decode_step(state, codepoint, c);
89 if (state == utf8::decode_state::accept)89 if (state == utf8::decode_state_t::accept)
90 return (curr - begin);90 return (curr - begin);
91 }91 }
92 92