Differences From Artifact [e3e6e72034]:
- File src/OFString.m — part of check-in [e0b9167693] at 2016-02-21 15:37:42 on branch trunk — Make use of C99-style for loops (user: js, size: 56060) [annotate] [blame] [check-ins using]
To Artifact [b713fffc4b]:
- File
src/OFString.m
— part of check-in
[5e2ef97c35]
at
2016-03-13 11:19:13
on branch trunk
— Change of_string_utf8_decode() API
It now returns <= 0 on error, with negative values being the number of
bytes it would have needed * -1.This can be used to detect cut off and how many bytes are missing. (user: js, size: 56129) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
124 125 126 127 128 129 130 | buffer[i] = 0x80 | (character & 0x3F); return 4; } return 0; } | | > | | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | buffer[i] = 0x80 | (character & 0x3F); return 4; } return 0; } ssize_t of_string_utf8_decode(const char *buffer_, size_t length, of_unichar_t *ret) { /* FIXME: Check if the following bytes are indeed surrogates */ const uint8_t *buffer = (const uint8_t*)buffer_; if (!(*buffer & 0x80)) { *ret = buffer[0]; return 1; } if ((*buffer & 0xE0) == 0xC0) { if OF_UNLIKELY (length < 2) return -2; *ret = ((buffer[0] & 0x1F) << 6) | (buffer[1] & 0x3F); return 2; } if ((*buffer & 0xF0) == 0xE0) { if OF_UNLIKELY (length < 3) return -3; *ret = ((buffer[0] & 0x0F) << 12) | ((buffer[1] & 0x3F) << 6) | (buffer[2] & 0x3F); return 3; } if ((*buffer & 0xF8) == 0xF0) { if OF_UNLIKELY (length < 4) return -4; *ret = ((buffer[0] & 0x07) << 18) | ((buffer[1] & 0x3F) << 12) | ((buffer[2] & 0x3F) << 6) | (buffer[3] & 0x3F); return 4; } return 0; |
︙ | ︙ |