1#ifndef C4_YML_FILTER_PROCESSOR_HPP_
2#define C4_YML_FILTER_PROCESSOR_HPP_
4#ifndef C4_YML_ERROR_HPP_
10#include "c4/yml/detail/dbgprint.hpp"
28 C4_ALWAYS_INLINE
bool valid() const noexcept {
return str.str !=
nullptr; }
37 C4_ALWAYS_INLINE
bool valid() const noexcept {
return str.str !=
nullptr; }
61 RYML_ASSERT_BASIC_(!
dst.overlaps(
src));
64 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_)
noexcept {
wpos = wpos_; }
65 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_)
noexcept {
rpos = rpos_;
wpos = wpos_; }
69 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { RYML_ASSERT_BASIC_(maxpos <=
src.len);
return rpos < maxpos; }
81 C4_ALWAYS_INLINE
char curr() const noexcept { RYML_ASSERT_BASIC_(
rpos <
src.len);
return src[
rpos]; }
85 C4_ALWAYS_INLINE
void skip() noexcept { ++
rpos; }
86 C4_ALWAYS_INLINE
void skip(
size_t num)
noexcept {
rpos += num; }
88 C4_ALWAYS_INLINE
void set_at(
size_t pos,
char c)
noexcept
90 RYML_ASSERT_BASIC_(pos <
wpos);
93 C4_ALWAYS_INLINE
void set(
char c)
noexcept
99 C4_ALWAYS_INLINE
void set(
char c,
size_t num)
noexcept
101 RYML_ASSERT_BASIC_(num > 0);
103 memset(
dst.str +
wpos, c, num);
107 C4_ALWAYS_INLINE
void copy() noexcept
109 RYML_ASSERT_BASIC_(
rpos <
src.len);
115 C4_ALWAYS_INLINE
void copy(
size_t num)
noexcept
117 RYML_ASSERT_BASIC_(num);
118 RYML_ASSERT_BASIC_(
rpos+num <=
src.len);
134 RYML_ASSERT_BASIC_(nw > 0);
135 RYML_ASSERT_BASIC_(nr > 0);
136 RYML_ASSERT_BASIC_(
rpos+nr <=
src.len);
154#if defined(RYML_DBG) && 0
155#define _c4dbgip(...) _c4dbgpf(__VA_ARGS__)
179 RYML_ASSERT_BASIC_(
wcap >=
src.len);
182 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_)
noexcept {
wpos = wpos_; }
183 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_)
noexcept {
rpos = rpos_;
wpos = wpos_; }
187 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { RYML_ASSERT_BASIC_(maxpos <=
src.len);
return rpos < maxpos; }
200 C4_ALWAYS_INLINE
char curr() const noexcept { RYML_ASSERT_BASIC_(
rpos <
src.len);
return src[
rpos]; }
204 C4_ALWAYS_INLINE
void skip(
size_t num)
noexcept {
rpos += num; }
208 RYML_ASSERT_BASIC_(pos <
wpos);
209 const size_t save =
wpos;
220 void set(
char c,
size_t num)
noexcept
222 RYML_ASSERT_BASIC_(num);
224 memset(
src.str +
wpos, c, num);
231 RYML_ASSERT_BASIC_(
rpos <
src.len);
239 RYML_ASSERT_BASIC_(num);
240 RYML_ASSERT_BASIC_(
rpos+num <=
src.len);
255 RYML_ASSERT_BASIC_(
rpos + 2 <=
src.len);
265 RYML_ASSERT_BASIC_(nw > 0);
266 RYML_ASSERT_BASIC_(nr > 0);
267 RYML_ASSERT_BASIC_(nw <= nr + 1u);
268 RYML_ASSERT_BASIC_(
rpos+nr <=
src.len);
270 const size_t wpos_next =
wpos + nw;
271 const size_t rpos_next =
rpos + nr + 1u;
272 RYML_ASSERT_BASIC_(wpos_next <= rpos_next);
273 if(wpos_next <=
wcap)
318 RYML_ASSERT_BASIC_(
wcap >=
src.len);
321 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_)
noexcept {
wpos = wpos_; }
322 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_)
noexcept {
rpos = rpos_;
wpos = wpos_; }
326 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { RYML_ASSERT_BASIC_(maxpos <=
src.len);
return rpos < maxpos; }
330 _c4dbgip(
"inplace: wpos={} wcap={} unfiltered={} maxcap={}", this->wpos, this->wcap, this->unfiltered_chars, this->maxcap);
340 C4_ALWAYS_INLINE
char curr() const noexcept { RYML_ASSERT_BASIC_(
rpos <
src.len);
return src[
rpos]; }
344 C4_ALWAYS_INLINE
void skip(
size_t num)
noexcept {
rpos += num; }
348 RYML_ASSERT_BASIC_(pos <
wpos);
349 const size_t save =
wpos;
369 void set(
char c,
size_t num)
noexcept
371 RYML_ASSERT_BASIC_(num);
375 memset(
src.str +
wpos, c, num);
388 RYML_ASSERT_BASIC_(
rpos <
src.len);
396 _c4dbgip(
"inplace: add unwritten {}->{} (wpos={}!=rpos={})={} (wpos={}<wcap={}) maxcap={}->{}!",
unfiltered_chars,
true,
wpos,
rpos,
wpos!=
rpos,
wpos,
wcap,
wpos<
wcap,
maxcap, (
wpos+1u >
maxcap ?
wpos+1u :
maxcap));
405 RYML_ASSERT_BASIC_(num);
406 RYML_ASSERT_BASIC_(
rpos+num <=
src.len);
429 RYML_ASSERT_BASIC_(
rpos + 2 <=
src.len);
447 RYML_ASSERT_BASIC_(nw > 0);
448 RYML_ASSERT_BASIC_(nr > 0);
449 RYML_ASSERT_BASIC_(nr+1u >= nw);
450 const size_t wpos_next =
wpos + nw;
451 const size_t rpos_next =
rpos + nr + 1u;
452 if(wpos_next <=
wcap)
469 RYML_ASSERT_BASIC_(nw > 0);
470 RYML_ASSERT_BASIC_(nr > 0);
471 RYML_ASSERT_BASIC_(
rpos+nr <=
src.len);
472 const size_t wpos_next =
wpos + nw;
473 const size_t rpos_next =
rpos + nr + 1u;
474 if(wpos_next <= rpos_next)
484 const size_t excess = wpos_next - rpos_next;
485 RYML_ASSERT_BASIC_(wpos_next > rpos_next);
488 RYML_ASSERT_BASIC_(
rpos+nr+excess <=
src.len);
489 if(wpos_next <=
wcap)
493 memmove(
src.str + wpos_next,
src.str + rpos_next,
src.len - rpos_next);
502 _c4dbgip(
"inplace: add unfiltered {}->{} maxcap={}->{}!",
unfiltered_chars,
true);
513 RYML_ASSERT_BASIC_(rpos_next <=
src.len);
514 const size_t required_size = wpos_next + (
src.len - rpos_next);
516 RYML_ASSERT_BASIC_(required_size >
wcap);
Lightweight generic type-safe wrappers for converting individual values to/from strings.
Error utilities used by ryml.
basic_substring< char > substr
a mutable string view
basic_substring< const char > csubstr
an immutable string view
size_t len
the length of the substring
C * str
a restricted pointer to the first character of the substring
char curr() const noexcept
substr src
the subject string
size_t wpos
write position
FilterProcessorInplaceEndExtending(substr src_, size_t wcap_) noexcept
csubstr rem() const noexcept
void set_at_end() noexcept
size_t wcap
write capacity - the capacity of the subject string's buffer
void skip(size_t num) noexcept
void setwpos(size_t wpos_) noexcept
void setpos(size_t rpos_, size_t wpos_) noexcept
void translate_esc_extending(const char *s, size_t nw, size_t nr) noexcept
void translate_esc(char c) noexcept
char next() const noexcept
void set(char c) noexcept
void set(char c, size_t num) noexcept
void copy(size_t num) noexcept
FilterResult result() const noexcept
void translate_esc_bulk(const char *s, size_t nw, size_t nr) noexcept
csubstr sofar() const noexcept
bool has_more_chars(size_t maxpos) const noexcept
void set_at(size_t pos, char c) noexcept
bool has_more_chars() const noexcept
bool has_more_chars() const noexcept
csubstr rem() const noexcept
void setwpos(size_t wpos_) noexcept
void set_at_end() noexcept
char curr() const noexcept
FilterResultExtending result() const noexcept
void translate_esc_extending(const char *s, size_t nw, size_t nr) noexcept
char next() const noexcept
void translate_esc_bulk(const char *s, size_t nw, size_t nr) noexcept
void translate_esc(char c) noexcept
FilterProcessorInplaceMidExtending(substr src_, size_t wcap_) noexcept
void skip(size_t num) noexcept
substr src
the subject string
csubstr sofar() const noexcept
size_t maxcap
the max capacity needed for filtering the string. This may be larger than the final string size.
bool has_more_chars(size_t maxpos) const noexcept
size_t wpos
write position
void setpos(size_t rpos_, size_t wpos_) noexcept
void set_at(size_t pos, char c) noexcept
size_t wcap
write capacity - the capacity of the subject string's buffer
bool unfiltered_chars
number of characters that were not added to wpos from lack of capacity
void set(char c, size_t num) noexcept
void copy(size_t num) noexcept
void set(char c) noexcept
void translate_esc_bulk(const char *s, size_t nw, size_t nr) noexcept
void set_at(size_t pos, char c) noexcept
void set_at_end() noexcept
void setpos(size_t rpos_, size_t wpos_) noexcept
void copy(size_t num) noexcept
csubstr rem() const noexcept
FilterResult result() const noexcept
void skip(size_t num) noexcept
size_t wpos
write position
void set(char c) noexcept
FilterProcessorSrcDst(csubstr src_, substr dst_) noexcept
void setwpos(size_t wpos_) noexcept
bool has_more_chars() const noexcept
void translate_esc(char c) noexcept
char curr() const noexcept
bool skipped_chars() const noexcept
csubstr sofar() const noexcept
void translate_esc_extending(const char *s, size_t nw, size_t nr) noexcept
char next() const noexcept
void set(char c, size_t num) noexcept
bool has_more_chars(size_t maxpos) const noexcept
Result for filtering a scalar which not fit in the intended memory.
bool valid() const noexcept
size_t required_len() const noexcept
Result for filtering a scalar which not fit in the intended memory.
size_t required_len() const noexcept
bool valid() const noexcept