MCPcopy Create free account
hub / github.com/coreutils/coreutils / mbs_offset_to_chars

Function mbs_offset_to_chars

src/expr.c:215–222  ·  view source on GitHub ↗

Return the number of logical characters (possibly multibyte) that are in string S in the first OFS octets. Example in UTF-8: "\xE2\x9D\xA7" is "U+2767 ROTATED FLORAL HEART BULLET". In the string below, there are only two characters up to the first 4 bytes (The U+2767 which occupies 3 bytes and 'x'): mbs_count_to_offset ("\xE2\x9D\xA7xyz", 4) => 2 */

Source from the content-addressed store, hash-verified

213 up to the first 4 bytes (The U+2767 which occupies 3 bytes and 'x'):
214 mbs_count_to_offset ("\xE2\x9D\xA7xyz", 4) => 2 */
215static size_t
216mbs_offset_to_chars (char const *s, size_t ofs)
217{
218 size_t c = 0;
219 for (size_t d = 0; d < ofs && s[d]; d += mcel_scanz (s + d).len)
220 c++;
221 return c;
222}
223
224
225

Callers 1

docolonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected