Function preprocess_rxmap

Summary

#include <src/c4/yml/preprocess.hpp>

(1) size_t preprocess_rxmap(csubstr s, substr buf)

(2) template <class CharContainer>
    substr preprocess_rxmap(csubstr rxmap, CharContainer *out)

(3) template <class CharContainer>
    CharContainer preprocess_rxmap(csubstr rxmap)

Function overload

Synopsis

#include <src/c4/yml/preprocess.hpp>

size_t preprocess_rxmap(csubstr s, substr buf)

Description

Write into a given output buffer. This function is safe to call with empty or small buffers; it won't write beyond the end of the buffer.

Returns
the number of characters required for output

Mentioned in

Source

Lines 169-240 in src/c4/yml/preprocess.cpp. Line 118 in src/c4/yml/preprocess.hpp.

size_t preprocess_rxmap(csubstr s, substr buf)
{
    _SubstrWriter _append(buf);
    _ppstate state = kReadPending;
    size_t last = 0;

    if(s.begins_with('{'))
    {
        RYML_CHECK(s.ends_with('}'));
        s = s.offs(1, 1);
    }

    _append('{');

    for(size_t i = 0; i < s.len; ++i)
    {
        const char curr = s[i];
        const char next = i+1 < s.len ? s[i+1] : '\0';

        if(curr == '\'' || curr == '"')
        {
            csubstr ss = s.sub(i).pair_range_esc(curr, '\\');
            i += static_cast<size_t>(ss.end() - (s.str + i));
            state = _next(state);
        }
        else if(state == kReadPending && _is_idchar(curr))
        {
            state = _next(state);
        }

        switch(state)
        {
        case kKeyPending:
        {
            if(curr == ':' && next == ' ')
            {
                state = _next(state);
            }
            else if(curr == ',' && next == ' ')
            {
                _append(s.range(last, i));
                _append(": 1, ");
                last = i + 2;
            }
            break;
        }
        case kValPending:
        {
            if(curr == '[' || curr == '{' || curr == '(')
            {
                csubstr ss = s.sub(i).pair_range_nested(curr, '\\');
                i += static_cast<size_t>(ss.end() - (s.str + i));
                state = _next(state);
            }
            else if(curr == ',' && next == ' ')
            {
                state = _next(state);
            }
            break;
        }
        default:
            // nothing to do
            break;
        }
    }

    _append(s.sub(last));
    if(state == kKeyPending) _append(": 1");
    _append('}');

    return _append.pos;
}

Synopsis

#include <src/c4/yml/preprocess.hpp>

template <class CharContainer>
substr preprocess_rxmap(csubstr rxmap, CharContainer *out)

Description

No description yet.

Mentioned in

Source

Lines 124-128 in src/c4/yml/preprocess.hpp.

template<class CharContainer>
substr preprocess_rxmap(csubstr rxmap, CharContainer *out)
{
    return detail::preprocess_into_container<preprocess_rxmap>(rxmap, out);
}

Synopsis

#include <src/c4/yml/preprocess.hpp>

template <class CharContainer>
CharContainer preprocess_rxmap(csubstr rxmap)

Description

No description yet.

Mentioned in

Source

Lines 133-139 in src/c4/yml/preprocess.hpp.

template<class CharContainer>
CharContainer preprocess_rxmap(csubstr rxmap)
{
    CharContainer out;
    preprocess_rxmap(rxmap, &out);
    return out;
}





Add Discussion as Guest

Log in