ZstrProcessEscape
Description
Decode one escape sequence starting at *str. *str must point at the leading \\; on success the pointer is advanced past the consumed escape. Handles single-character escapes (\\n/\\r/\\t/\\b/\\f/\\v/\\a/\\\\/\\"/\\'/\\0), hex escapes (\\xNN), and \\u{...} Unicode escapes that fit in a single byte.
Parameters
| Name | Direction | Description |
|---|---|---|
str |
in,out | Address of a Zstr cursor. Advanced past the consumed escape on success. |
Success
Returns the decoded byte; *str is advanced past the escape.
Failure
Returns 0; logs the malformed escape; *str may have been partially advanced.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:2296:
#endif // FEATURE_FLOAT
char ZstrProcessEscape(Zstr *str) {
if (!str || !*str)
return 0;- In
Io.c:2302:
Zstr s = *str;
if (*s != '\\') {
LOG_ERROR("ZstrProcessEscape called on non-escape sequence");
return 0;
}- In
Io.c:2395:
if (*i == '\\') {
Zstr curr = i;
char c = ZstrProcessEscape(&curr);
if (c == 0) {
StrDeinit(s);- In
Io.c:2434:
if (*i == '\\') {
Zstr curr = i;
char c = ZstrProcessEscape(&curr);
if (c == 0) {
StrDeinit(s);- In
Write.c:965:
static char decode_hex_escape(Zstr lit) {
Zstr p = lit;
return ZstrProcessEscape(&p);
}- In
Write.c:1348:
static bool test_m11_hex_two_digits_not_truncated(void) {
Zstr p = "\\x41"; // 'A'
char c = ZstrProcessEscape(&p);
return c == 'A';
}- In
Write.c:1357:
static bool test_m11_hex_value_is_decoded_not_42(void) {
Zstr p = "\\x41"; // must yield 65 ('A'), not 42 ('*')
char c = ZstrProcessEscape(&p);
return c == (char)65;
}- In
Write.c:1365:
static bool test_m11_hex_ff(void) {
Zstr p = "\\xff";
char c = ZstrProcessEscape(&p);
return (unsigned char)c == 0xFFu;
}- In
Write.c:1374:
static bool test_m11_hex_valid_not_rejected(void) {
Zstr p = "\\x41";
return ZstrProcessEscape(&p) == 'A';
}- In
Write.c:1384:
char buf[] = {'\\', 'x', '0', '0', 'Z', '\0'};
const char *p = buf;
char c = ZstrProcessEscape(&p);
// real: decodes NUL byte and advances p to the last consumed hex digit
// (buf[3]); mutant (<=0) errors out and leaves p == buf.
- In
Write.c:1394:
static bool test_m11_hex_result_assigned_from_value(void) {
Zstr p = "\\x41";
return ZstrProcessEscape(&p) == (char)65;
}- In
Write.c:1401:
static bool test_m11_hex_invalid_returns_zero(void) {
Zstr p = "\\xZZ";
return ZstrProcessEscape(&p) == 0;
}- In
Read.c:1077:
static bool test_m11_simple_escape_decodes(void) {
Zstr p = "\\n";
char c = ZstrProcessEscape(&p);
return c == '\n';
}- In
Read.c:1087:
static bool test_m11_escape_n(void) {
Zstr p = "\\n";
return ZstrProcessEscape(&p) == '\n';
}
static bool test_m11_escape_r(void) {- In
Read.c:1091:
static bool test_m11_escape_r(void) {
Zstr p = "\\r";
return ZstrProcessEscape(&p) == '\r';
}
static bool test_m11_escape_t(void) {- In
Read.c:1095:
static bool test_m11_escape_t(void) {
Zstr p = "\\t";
return ZstrProcessEscape(&p) == '\t';
}
static bool test_m11_escape_b(void) {- In
Read.c:1099:
static bool test_m11_escape_b(void) {
Zstr p = "\\b";
return ZstrProcessEscape(&p) == '\b';
}
static bool test_m11_escape_f(void) {- In
Read.c:1103:
static bool test_m11_escape_f(void) {
Zstr p = "\\f";
return ZstrProcessEscape(&p) == '\f';
}
static bool test_m11_escape_v(void) {- In
Read.c:1107:
static bool test_m11_escape_v(void) {
Zstr p = "\\v";
return ZstrProcessEscape(&p) == '\v';
}
static bool test_m11_escape_a(void) {- In
Read.c:1111:
static bool test_m11_escape_a(void) {
Zstr p = "\\a";
return ZstrProcessEscape(&p) == '\a';
}
static bool test_m11_escape_backslash(void) {- In
Read.c:1115:
static bool test_m11_escape_backslash(void) {
Zstr p = "\\\\";
return ZstrProcessEscape(&p) == '\\';
}
static bool test_m11_escape_dquote(void) {- In
Read.c:1119:
static bool test_m11_escape_dquote(void) {
Zstr p = "\\\"";
return ZstrProcessEscape(&p) == '"';
}
static bool test_m11_escape_squote(void) {- In
Read.c:1123:
static bool test_m11_escape_squote(void) {
Zstr p = "\\'";
return ZstrProcessEscape(&p) == '\'';
}
// case '0' -> result = '\0'; cxx_assign_const(42) at 2216 makes it '*'.
- In
Read.c:1128:
static bool test_m11_escape_nul(void) {
Zstr p = "\\0";
return ZstrProcessEscape(&p) == '\0';
}
Last updated on