1 #ifndef _C4_YML_FILTER_PROCESSOR_HPP_
2 #define _C4_YML_FILTER_PROCESSOR_HPP_
8 #include "c4/yml/detail/dbgprint.hpp"
39 RYML_ASSERT(!
dst.overlaps(
src));
42 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_) noexcept {
wpos = wpos_; }
43 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_) noexcept {
rpos = rpos_;
wpos = wpos_; }
47 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { RYML_ASSERT(maxpos <=
src.len);
return rpos < maxpos; }
49 C4_ALWAYS_INLINE csubstr
rem() const noexcept {
return src.sub(
rpos); }
51 C4_ALWAYS_INLINE FilterResult
result() const noexcept
54 ret.str.str =
wpos <=
dst.len ?
dst.str :
nullptr;
63 C4_ALWAYS_INLINE
void skip() noexcept { ++
rpos; }
64 C4_ALWAYS_INLINE
void skip(
size_t num) noexcept {
rpos += num; }
66 C4_ALWAYS_INLINE
void set_at(
size_t pos,
char c) noexcept
68 RYML_ASSERT(pos <
wpos);
71 C4_ALWAYS_INLINE
void set(
char c) noexcept
77 C4_ALWAYS_INLINE
void set(
char c,
size_t num) noexcept
85 C4_ALWAYS_INLINE
void copy() noexcept
93 C4_ALWAYS_INLINE
void copy(
size_t num) noexcept
96 RYML_ASSERT(
rpos+num <=
src.len);
114 RYML_ASSERT(
rpos+nr <=
src.len);
132 #if defined(RYML_DBG) && 0
133 #define _c4dbgip(...) _c4dbgpf(__VA_ARGS__)
135 #define _c4dbgip(...)
160 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_) noexcept {
wpos = wpos_; }
161 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_) noexcept {
rpos = rpos_;
wpos = wpos_; }
165 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { RYML_ASSERT(maxpos <=
src.len);
return rpos < maxpos; }
167 C4_ALWAYS_INLINE FilterResult
result() const noexcept
176 C4_ALWAYS_INLINE csubstr
rem() const noexcept {
return src.sub(
rpos); }
182 C4_ALWAYS_INLINE
void skip(
size_t num) noexcept {
rpos += num; }
186 RYML_ASSERT(pos <
wpos);
187 const size_t save =
wpos;
198 void set(
char c,
size_t num) noexcept
202 memset(
src.str +
wpos, c, num);
218 RYML_ASSERT(
rpos+num <=
src.len);
233 RYML_ASSERT(
rpos + 2 <=
src.len);
245 RYML_ASSERT(nw <= nr + 1u);
246 RYML_ASSERT(
rpos+nr <=
src.len);
248 const size_t wpos_next =
wpos + nw;
249 const size_t rpos_next =
rpos + nr + 1u;
250 RYML_ASSERT(wpos_next <= rpos_next);
251 if(wpos_next <=
wcap)
299 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_) noexcept {
wpos = wpos_; }
300 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_) noexcept {
rpos = rpos_;
wpos = wpos_; }
304 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { RYML_ASSERT(maxpos <=
src.len);
return rpos < maxpos; }
306 C4_ALWAYS_INLINE FilterResultExtending
result() const noexcept
308 _c4dbgip(
"inplace: wpos={} wcap={} unfiltered={} maxcap={}", this->wpos, this->wcap, this->unfiltered_chars, this->maxcap);
309 FilterResultExtending ret;
316 C4_ALWAYS_INLINE csubstr
rem() const noexcept {
return src.sub(
rpos); }
322 C4_ALWAYS_INLINE
void skip(
size_t num) noexcept {
rpos += num; }
326 RYML_ASSERT(pos <
wpos);
327 const size_t save =
wpos;
347 void set(
char c,
size_t num) noexcept
353 memset(
src.str +
wpos, c, num);
374 _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));
384 RYML_ASSERT(
rpos+num <=
src.len);
407 RYML_ASSERT(
rpos + 2 <=
src.len);
427 RYML_ASSERT(nr+1u >= nw);
428 const size_t wpos_next =
wpos + nw;
429 const size_t rpos_next =
rpos + nr + 1u;
430 if(wpos_next <=
wcap)
449 RYML_ASSERT(
rpos+nr <=
src.len);
450 const size_t wpos_next =
wpos + nw;
451 const size_t rpos_next =
rpos + nr + 1u;
452 if(wpos_next <= rpos_next)
462 const size_t excess = wpos_next - rpos_next;
463 RYML_ASSERT(wpos_next > rpos_next);
466 RYML_ASSERT(
rpos+nr+excess <=
src.len);
467 if(wpos_next <=
wcap)
471 memmove(
src.str + wpos_next,
src.str + rpos_next,
src.len - rpos_next);
480 _c4dbgip(
"inplace: add unfiltered {}->{} maxcap={}->{}!",
unfiltered_chars,
true);
491 RYML_ASSERT(rpos_next <=
src.len);
492 const size_t required_size = wpos_next + (
src.len - rpos_next);
494 RYML_ASSERT(required_size >
wcap);
Lightweight generic type-safe wrappers for converting individual values to/from strings.
Common utilities and infrastructure used by ryml.
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
Filters an input string into a different output string.
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