JReadString

Table of Contents

JReadString

Description

Read a quoted string, handling escape sequences.

Note

Unicode escape sequences like \uXXXX are not supported.

Parameters

NameDirectionDescription
siinCurrent reading position in input string
stroutOutput 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)

    do {                                                                                                               \
    Str my_str = StrInit();                                                                                        \
    si         = JReadString((si), &my_str);                                                                       \
    (str)      = my_str;                                                                                           \
    } while (0)
    if (!StrCmpZstr(&key, (k))) {                                                                                  \
    Str my_str = StrInit();                                                                                    \
    si         = JReadString((si), &my_str);                                                                   \
    (str)      = my_str;                                                                                       \
    }                                                                                                              \
    \
    /* key start */                                                                                            \
    read_si = JReadString(si, &key);                                                                           \
    if (read_si.pos == si.pos) {                                                                               \
    LOG_ERROR("Failed to read string key in object. Invalid JSON");                                        \
    
    // key start
    read_si = JReadString(si, &key);
    if (read_si.pos == si.pos) {
    LOG_ERROR("Failed to read string key in object. Invalid JSON");
    }
    
    StrIter JReadString(StrIter si, Str* str) {
    if (!StrIterRemainingLength(&si)) {
    return si;
    StrIter before_si = si;
    Str     s         = StrInit();
    si                = JReadString(si, &s);
    StrDeinit(&s);

Share :

Related Posts

JSkipWhitespace

JSkipWhitespace Description Skip whitespace from current reading position.

Read More