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

Function yaml_validate_utf8

src/cli/config_yaml_edit.c:2229–2268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2227}
2228
2229static int yaml_validate_utf8(const char *value, size_t len) {
2230 const unsigned char *bytes = (const unsigned char *)value;
2231 for (size_t i = 0U; i < len;) {
2232 unsigned char first = bytes[i];
2233 if (first < 0x80U) {
2234 i++;
2235 continue;
2236 }
2237 if (first >= 0xC2U && first <= 0xDFU) {
2238 if (i + YAML_UNIT >= len || (bytes[i + YAML_UNIT] & 0xC0U) != 0x80U) {
2239 return YAML_ERROR;
2240 }
2241 i += YAML_ENTRY_INDENT;
2242 continue;
2243 }
2244 if (first >= 0xE0U && first <= 0xEFU) {
2245 if (i + YAML_ENTRY_INDENT >= len || (bytes[i + YAML_UNIT] & 0xC0U) != 0x80U ||
2246 (bytes[i + YAML_ENTRY_INDENT] & 0xC0U) != 0x80U ||
2247 (first == 0xE0U && bytes[i + YAML_UNIT] < 0xA0U) ||
2248 (first == 0xEDU && bytes[i + YAML_UNIT] >= 0xA0U)) {
2249 return YAML_ERROR;
2250 }
2251 i += YAML_DOC_MARKER_LEN;
2252 continue;
2253 }
2254 if (first >= 0xF0U && first <= 0xF4U) {
2255 if (i + YAML_DOC_MARKER_LEN >= len || (bytes[i + YAML_UNIT] & 0xC0U) != 0x80U ||
2256 (bytes[i + YAML_ENTRY_INDENT] & 0xC0U) != 0x80U ||
2257 (bytes[i + YAML_DOC_MARKER_LEN] & 0xC0U) != 0x80U ||
2258 (first == 0xF0U && bytes[i + YAML_UNIT] < 0x90U) ||
2259 (first == 0xF4U && bytes[i + YAML_UNIT] >= 0x90U)) {
2260 return YAML_ERROR;
2261 }
2262 i += YAML_VALUE_INDENT;
2263 continue;
2264 }
2265 return YAML_ERROR;
2266 }
2267 return 0;
2268}
2269
2270static int yaml_validate_scalar_value(const char *value, size_t *out_len) {
2271 size_t len = 0U;

Callers 3

yaml_decode_scalarFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected