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"
34 C4_ALWAYS_INLINE
bool valid() const noexcept {
return str.str !=
nullptr; }
36 C4_ALWAYS_INLINE csubstr
get()
const { _RYML_ASSERT_BASIC(
valid());
return str; }
43 C4_ALWAYS_INLINE
bool valid() const noexcept {
return str.str !=
nullptr; }
45 C4_ALWAYS_INLINE csubstr
get()
const { _RYML_ASSERT_BASIC(
valid());
return str; }
67 _RYML_ASSERT_BASIC(!
dst.overlaps(
src));
70 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_) noexcept {
wpos = wpos_; }
71 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_) noexcept {
rpos = rpos_;
wpos = wpos_; }
75 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { _RYML_ASSERT_BASIC(maxpos <=
src.len);
return rpos < maxpos; }
77 C4_ALWAYS_INLINE csubstr
rem() const noexcept {
return src.sub(
rpos); }
87 C4_ALWAYS_INLINE
char curr() const noexcept { _RYML_ASSERT_BASIC(
rpos <
src.len);
return src[
rpos]; }
91 C4_ALWAYS_INLINE
void skip() noexcept { ++
rpos; }
92 C4_ALWAYS_INLINE
void skip(
size_t num) noexcept {
rpos += num; }
94 C4_ALWAYS_INLINE
void set_at(
size_t pos,
char c) noexcept
96 _RYML_ASSERT_BASIC(pos <
wpos);
99 C4_ALWAYS_INLINE
void set(
char c) noexcept
105 C4_ALWAYS_INLINE
void set(
char c,
size_t num) noexcept
107 _RYML_ASSERT_BASIC(num > 0);
109 memset(
dst.str +
wpos, c, num);
113 C4_ALWAYS_INLINE
void copy() noexcept
115 _RYML_ASSERT_BASIC(
rpos <
src.len);
121 C4_ALWAYS_INLINE
void copy(
size_t num) noexcept
123 _RYML_ASSERT_BASIC(num);
124 _RYML_ASSERT_BASIC(
rpos+num <=
src.len);
140 _RYML_ASSERT_BASIC(nw > 0);
141 _RYML_ASSERT_BASIC(nr > 0);
142 _RYML_ASSERT_BASIC(
rpos+nr <=
src.len);
160 #if defined(RYML_DBG) && 0
161 #define _c4dbgip(...) _c4dbgpf(__VA_ARGS__)
163 #define _c4dbgip(...)
185 _RYML_ASSERT_BASIC(
wcap >=
src.len);
188 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_) noexcept {
wpos = wpos_; }
189 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_) noexcept {
rpos = rpos_;
wpos = wpos_; }
193 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { _RYML_ASSERT_BASIC(maxpos <=
src.len);
return rpos < maxpos; }
204 C4_ALWAYS_INLINE csubstr
rem() const noexcept {
return src.sub(
rpos); }
206 C4_ALWAYS_INLINE
char curr() const noexcept { _RYML_ASSERT_BASIC(
rpos <
src.len);
return src[
rpos]; }
210 C4_ALWAYS_INLINE
void skip(
size_t num) noexcept {
rpos += num; }
214 _RYML_ASSERT_BASIC(pos <
wpos);
215 const size_t save =
wpos;
226 void set(
char c,
size_t num) noexcept
228 _RYML_ASSERT_BASIC(num);
230 memset(
src.str +
wpos, c, num);
237 _RYML_ASSERT_BASIC(
rpos <
src.len);
245 _RYML_ASSERT_BASIC(num);
246 _RYML_ASSERT_BASIC(
rpos+num <=
src.len);
261 _RYML_ASSERT_BASIC(
rpos + 2 <=
src.len);
271 _RYML_ASSERT_BASIC(nw > 0);
272 _RYML_ASSERT_BASIC(nr > 0);
273 _RYML_ASSERT_BASIC(nw <= nr + 1u);
274 _RYML_ASSERT_BASIC(
rpos+nr <=
src.len);
276 const size_t wpos_next =
wpos + nw;
277 const size_t rpos_next =
rpos + nr + 1u;
278 _RYML_ASSERT_BASIC(wpos_next <= rpos_next);
279 if(wpos_next <=
wcap)
324 _RYML_ASSERT_BASIC(
wcap >=
src.len);
327 C4_ALWAYS_INLINE
void setwpos(
size_t wpos_) noexcept {
wpos = wpos_; }
328 C4_ALWAYS_INLINE
void setpos(
size_t rpos_,
size_t wpos_) noexcept {
rpos = rpos_;
wpos = wpos_; }
332 C4_ALWAYS_INLINE
bool has_more_chars(
size_t maxpos)
const noexcept { _RYML_ASSERT_BASIC(maxpos <=
src.len);
return rpos < maxpos; }
336 _c4dbgip(
"inplace: wpos={} wcap={} unfiltered={} maxcap={}", this->wpos, this->wcap, this->unfiltered_chars, this->maxcap);
344 C4_ALWAYS_INLINE csubstr
rem() const noexcept {
return src.sub(
rpos); }
346 C4_ALWAYS_INLINE
char curr() const noexcept { _RYML_ASSERT_BASIC(
rpos <
src.len);
return src[
rpos]; }
350 C4_ALWAYS_INLINE
void skip(
size_t num) noexcept {
rpos += num; }
354 _RYML_ASSERT_BASIC(pos <
wpos);
355 const size_t save =
wpos;
375 void set(
char c,
size_t num) noexcept
377 _RYML_ASSERT_BASIC(num);
381 memset(
src.str +
wpos, c, num);
394 _RYML_ASSERT_BASIC(
rpos <
src.len);
402 _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));
411 _RYML_ASSERT_BASIC(num);
412 _RYML_ASSERT_BASIC(
rpos+num <=
src.len);
435 _RYML_ASSERT_BASIC(
rpos + 2 <=
src.len);
453 _RYML_ASSERT_BASIC(nw > 0);
454 _RYML_ASSERT_BASIC(nr > 0);
455 _RYML_ASSERT_BASIC(nr+1u >= nw);
456 const size_t wpos_next =
wpos + nw;
457 const size_t rpos_next =
rpos + nr + 1u;
458 if(wpos_next <=
wcap)
475 _RYML_ASSERT_BASIC(nw > 0);
476 _RYML_ASSERT_BASIC(nr > 0);
477 _RYML_ASSERT_BASIC(
rpos+nr <=
src.len);
478 const size_t wpos_next =
wpos + nw;
479 const size_t rpos_next =
rpos + nr + 1u;
480 if(wpos_next <= rpos_next)
490 const size_t excess = wpos_next - rpos_next;
491 _RYML_ASSERT_BASIC(wpos_next > rpos_next);
494 _RYML_ASSERT_BASIC(
rpos+nr+excess <=
src.len);
495 if(wpos_next <=
wcap)
499 memmove(
src.str + wpos_next,
src.str + rpos_next,
src.len - rpos_next);
508 _c4dbgip(
"inplace: add unfiltered {}->{} maxcap={}->{}!",
unfiltered_chars,
true);
519 _RYML_ASSERT_BASIC(rpos_next <=
src.len);
520 const size_t required_size = wpos_next + (
src.len - rpos_next);
522 _RYML_ASSERT_BASIC(required_size >
wcap);
Lightweight generic type-safe wrappers for converting individual values to/from strings.
Error utilities used by ryml.
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
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
Abstracts the fact that a scalar filter result may not fit in the intended memory.
bool valid() const noexcept
size_t required_len() const noexcept
Abstracts the fact that a scalar filter result may not fit in the intended memory.
size_t required_len() const noexcept
bool valid() const noexcept