Skip to content

JReadString

Description

Read a quoted string, handling escape sequences.

\uXXXX escapes are recognised but not decoded – the parser logs a warning and skips the six bytes so the surrounding string still parses. See the top-of-file v1 scope note.

Parameters

Name Direction Description
si in Current reading position in input string
str out Output string to store parsed result

Success

Returns StrIter advanced past closing quote

Failure

Returns original StrIter on error (invalid escape, missing quote, etc.)

Usage example (Cross-references)

Usage examples (Cross-references)
    
            // key start
            read_si = JReadString(si, &key);
            if (StrIterIndex(&read_si) == StrIterIndex(&si)) {
                LOG_ERROR("Failed to read string key in object. Invalid JSON");
    }
    
    StrIter JReadString(StrIter si, Str *str) {
        if (!StrIterRemainingLength(&si)) {
            return si;
            DefaultAllocator scratch = DefaultAllocatorInit();
            Str              s       = StrInit(&scratch);
            si                       = JReadString(si, &s);
            StrDeinit(&s);
            DefaultAllocatorDeinit(&scratch);
                }                                                                                                          \
                Str key       = StrInit(&alloc);                                                                           \
                UNPL(read_si) = JReadString(si, &key);                                                                     \
                if (StrIterIndex(&UNPL(read_si)) == StrIterIndex(&si)) {                                                   \
                    LOG_ERROR("Failed to read string key in object. Invalid JSON");                                        \
        do {                                                                                                               \
            Str UNPL(my_str) = StrInit(&alloc);                                                                            \
            si               = JReadString((si), &UNPL(my_str));                                                           \
            (str)            = UNPL(my_str);                                                                               \
        } while (0)
            if (!StrCmp(&key, (k))) {                                                                                      \
                Str UNPL(my_str) = StrInit(&alloc);                                                                        \
                si               = JReadString((si), &UNPL(my_str));                                                       \
                (str)            = UNPL(my_str);                                                                           \
            }                                                                                                              \
        do {                                                                                                               \
            Str UNPL(my_str) = StrInit();                                                                                  \
            si               = JReadString((si), &UNPL(my_str));                                                           \
            (str)            = UNPL(my_str);                                                                               \
        } while (0)
            if (!StrCmp(&key, (k))) {                                                                                      \
                Str UNPL(my_str) = StrInit();                                                                              \
                si               = JReadString((si), &UNPL(my_str));                                                       \
                (str)            = UNPL(my_str);                                                                           \
            }                                                                                                              \
                                                                                                                           \
                /* key start */                                                                                            \
                UNPL(read_si) = JReadString(si, &key);                                                                     \
                if (StrIterIndex(&UNPL(read_si)) == StrIterIndex(&si)) {                                                   \
                    LOG_ERROR("Failed to read string key in object. Invalid JSON");                                        \
Last updated on