Changes in uspace/lib/c/generic/str.c [568693b:be2a38ad] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
r568693b rbe2a38ad 134 134 135 135 return ch; 136 }137 138 /** Decode a single character from a string to the left.139 *140 * Decode a single character from a string of size @a size. Decoding starts141 * at @a offset and this offset is moved to the beginning of the previous142 * character. In case of decoding error, offset generally decreases at least143 * by one. However, offset is never moved before 0.144 *145 * @param str String (not necessarily NULL-terminated).146 * @param offset Byte offset in string where to start decoding.147 * @param size Size of the string (in bytes).148 *149 * @return Value of decoded character, U_SPECIAL on decoding error or150 * NULL if attempt to decode beyond @a start of str.151 *152 */153 wchar_t str_decode_reverse(const char *str, size_t *offset, size_t size)154 {155 if (*offset == 0)156 return 0;157 158 size_t processed = 0;159 /* Continue while continuation bytes found */160 while (*offset > 0 && processed < 4) {161 uint8_t b = (uint8_t) str[--(*offset)];162 163 if (processed == 0 && (b & 0x80) == 0) {164 /* 0xxxxxxx (Plain ASCII) */165 return b & 0x7f;166 }167 else if ((b & 0xe0) == 0xc0 || (b & 0xf0) == 0xe0 ||168 (b & 0xf8) == 0xf0) {169 /* Start byte */170 size_t start_offset = *offset;171 return str_decode(str, &start_offset, size);172 }173 else if ((b & 0xc0) != 0x80) {174 /* Not a continuation byte */175 return U_SPECIAL;176 }177 processed++;178 }179 /* Too many continuation bytes */180 return U_SPECIAL;181 136 } 182 137
Note:
See TracChangeset
for help on using the changeset viewer.