MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / ha_utf8_sequence_length

Function ha_utf8_sequence_length

src/cli/hook_augment.c:265–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263}
264
265static size_t ha_utf8_sequence_length(const unsigned char *input, size_t remaining) {
266 if (!input || remaining == 0U) {
267 return 0U;
268 }
269 unsigned char first = input[0];
270 if (first < 0x80U) {
271 return 1U;
272 }
273 if (first >= 0xc2U && first <= 0xdfU) {
274 return remaining >= 2U && ha_is_utf8_continuation(input[1]) ? 2U : 0U;
275 }
276 if (first >= 0xe0U && first <= 0xefU) {
277 if (remaining < 3U || !ha_is_utf8_continuation(input[2])) {
278 return 0U;
279 }
280 unsigned char second = input[1];
281 if (first == 0xe0U) {
282 return second >= 0xa0U && second <= 0xbfU ? 3U : 0U;
283 }
284 if (first == 0xedU) {
285 return second >= 0x80U && second <= 0x9fU ? 3U : 0U;
286 }
287 return ha_is_utf8_continuation(second) ? 3U : 0U;
288 }
289 if (first >= 0xf0U && first <= 0xf4U) {
290 if (remaining < 4U || !ha_is_utf8_continuation(input[2]) ||
291 !ha_is_utf8_continuation(input[3])) {
292 return 0U;
293 }
294 unsigned char second = input[1];
295 if (first == 0xf0U) {
296 return second >= 0x90U && second <= 0xbfU ? 4U : 0U;
297 }
298 if (first == 0xf4U) {
299 return second >= 0x80U && second <= 0x8fU ? 4U : 0U;
300 }
301 return ha_is_utf8_continuation(second) ? 4U : 0U;
302 }
303 return 0U;
304}
305
306/* Graph names and paths originate in the repository/index and are data, never
307 * hook instructions. Keep valid UTF-8 sequences, collapse ASCII controls to a

Callers 1

ha_sanitize_metadataFunction · 0.85

Calls 1

ha_is_utf8_continuationFunction · 0.85

Tested by

no test coverage detected