rapidyaml  0.8.0
parse and emit YAML, and do it fast
c4::yml::FilterProcessorSrcDst Struct Reference

Filters an input string into a different output string. More...

#include <filter_processor.hpp>

Public Member Functions

 FilterProcessorSrcDst (csubstr src_, substr dst_) noexcept
 
void setwpos (size_t wpos_) noexcept
 
void setpos (size_t rpos_, size_t wpos_) noexcept
 
void set_at_end () noexcept
 
bool has_more_chars () const noexcept
 
bool has_more_chars (size_t maxpos) const noexcept
 
csubstr rem () const noexcept
 
csubstr sofar () const noexcept
 
FilterResult result () const noexcept
 
char curr () const noexcept
 
char next () const noexcept
 
bool skipped_chars () const noexcept
 
void skip () noexcept
 
void skip (size_t num) noexcept
 
void set_at (size_t pos, char c) noexcept
 
void set (char c) noexcept
 
void set (char c, size_t num) noexcept
 
void copy () noexcept
 
void copy (size_t num) noexcept
 
void translate_esc (char c) noexcept
 
void translate_esc_bulk (const char *s, size_t nw, size_t nr) noexcept
 
void translate_esc_extending (const char *s, size_t nw, size_t nr) noexcept
 

Public Attributes

csubstr src
 
substr dst
 
size_t rpos
 read position More...
 
size_t wpos
 write position More...
 

Detailed Description

Filters an input string into a different output string.

Definition at line 26 of file filter_processor.hpp.

Constructor & Destructor Documentation

◆ FilterProcessorSrcDst()

c4::yml::FilterProcessorSrcDst::FilterProcessorSrcDst ( csubstr  src_,
substr  dst_ 
)
inlinenoexcept

Definition at line 33 of file filter_processor.hpp.

34  : src(src_)
35  , dst(dst_)
36  , rpos(0)
37  , wpos(0)
38  {
39  RYML_ASSERT(!dst.overlaps(src));
40  }

References dst, and src.

Member Function Documentation

◆ setwpos()

void c4::yml::FilterProcessorSrcDst::setwpos ( size_t  wpos_)
inlinenoexcept

Definition at line 42 of file filter_processor.hpp.

42 { wpos = wpos_; }

References wpos.

◆ setpos()

void c4::yml::FilterProcessorSrcDst::setpos ( size_t  rpos_,
size_t  wpos_ 
)
inlinenoexcept

Definition at line 43 of file filter_processor.hpp.

43 { rpos = rpos_; wpos = wpos_; }

References rpos, and wpos.

◆ set_at_end()

void c4::yml::FilterProcessorSrcDst::set_at_end ( )
inlinenoexcept

Definition at line 44 of file filter_processor.hpp.

44 { skip(src.len - rpos); }

References rpos, skip(), and src.

◆ has_more_chars() [1/2]

bool c4::yml::FilterProcessorSrcDst::has_more_chars ( ) const
inlinenoexcept

Definition at line 46 of file filter_processor.hpp.

46 { return rpos < src.len; }

References rpos, and src.

◆ has_more_chars() [2/2]

bool c4::yml::FilterProcessorSrcDst::has_more_chars ( size_t  maxpos) const
inlinenoexcept

Definition at line 47 of file filter_processor.hpp.

47 { RYML_ASSERT(maxpos <= src.len); return rpos < maxpos; }

References rpos, and src.

◆ rem()

csubstr c4::yml::FilterProcessorSrcDst::rem ( ) const
inlinenoexcept

Definition at line 49 of file filter_processor.hpp.

49 { return src.sub(rpos); }

References rpos, and src.

◆ sofar()

csubstr c4::yml::FilterProcessorSrcDst::sofar ( ) const
inlinenoexcept

Definition at line 50 of file filter_processor.hpp.

50 { return csubstr(dst.str, wpos <= dst.len ? wpos : dst.len); }

References dst, and wpos.

◆ result()

FilterResult c4::yml::FilterProcessorSrcDst::result ( ) const
inlinenoexcept

Definition at line 51 of file filter_processor.hpp.

52  {
53  FilterResult ret;
54  ret.str.str = wpos <= dst.len ? dst.str : nullptr;
55  ret.str.len = wpos;
56  return ret;
57  }

References dst, and wpos.

◆ curr()

char c4::yml::FilterProcessorSrcDst::curr ( ) const
inlinenoexcept

Definition at line 59 of file filter_processor.hpp.

59 { RYML_ASSERT(rpos < src.len); return src[rpos]; }

References rpos, and src.

◆ next()

char c4::yml::FilterProcessorSrcDst::next ( ) const
inlinenoexcept

Definition at line 60 of file filter_processor.hpp.

60 { return rpos+1 < src.len ? src[rpos+1] : '\0'; }

References rpos, and src.

◆ skipped_chars()

bool c4::yml::FilterProcessorSrcDst::skipped_chars ( ) const
inlinenoexcept

Definition at line 61 of file filter_processor.hpp.

61 { return wpos != rpos; }

References rpos, and wpos.

◆ skip() [1/2]

void c4::yml::FilterProcessorSrcDst::skip ( )
inlinenoexcept

Definition at line 63 of file filter_processor.hpp.

63 { ++rpos; }

References rpos.

Referenced by set_at_end().

◆ skip() [2/2]

void c4::yml::FilterProcessorSrcDst::skip ( size_t  num)
inlinenoexcept

Definition at line 64 of file filter_processor.hpp.

64 { rpos += num; }

References rpos.

◆ set_at()

void c4::yml::FilterProcessorSrcDst::set_at ( size_t  pos,
char  c 
)
inlinenoexcept

Definition at line 66 of file filter_processor.hpp.

67  {
68  RYML_ASSERT(pos < wpos);
69  dst.str[pos] = c;
70  }

References dst, and wpos.

◆ set() [1/2]

void c4::yml::FilterProcessorSrcDst::set ( char  c)
inlinenoexcept

Definition at line 71 of file filter_processor.hpp.

72  {
73  if(wpos < dst.len)
74  dst.str[wpos] = c;
75  ++wpos;
76  }

References dst, and wpos.

◆ set() [2/2]

void c4::yml::FilterProcessorSrcDst::set ( char  c,
size_t  num 
)
inlinenoexcept

Definition at line 77 of file filter_processor.hpp.

78  {
79  RYML_ASSERT(num > 0);
80  if(wpos + num <= dst.len)
81  memset(dst.str + wpos, c, num);
82  wpos += num;
83  }

References dst, and wpos.

◆ copy() [1/2]

void c4::yml::FilterProcessorSrcDst::copy ( )
inlinenoexcept

Definition at line 85 of file filter_processor.hpp.

86  {
87  RYML_ASSERT(rpos < src.len);
88  if(wpos < dst.len)
89  dst.str[wpos] = src.str[rpos];
90  ++wpos;
91  ++rpos;
92  }

References dst, rpos, src, and wpos.

◆ copy() [2/2]

void c4::yml::FilterProcessorSrcDst::copy ( size_t  num)
inlinenoexcept

Definition at line 93 of file filter_processor.hpp.

94  {
95  RYML_ASSERT(num);
96  RYML_ASSERT(rpos+num <= src.len);
97  if(wpos + num <= dst.len)
98  memcpy(dst.str + wpos, src.str + rpos, num);
99  wpos += num;
100  rpos += num;
101  }

References dst, rpos, src, and wpos.

◆ translate_esc()

void c4::yml::FilterProcessorSrcDst::translate_esc ( char  c)
inlinenoexcept

Definition at line 103 of file filter_processor.hpp.

104  {
105  if(wpos < dst.len)
106  dst.str[wpos] = c;
107  ++wpos;
108  rpos += 2;
109  }

References dst, rpos, and wpos.

◆ translate_esc_bulk()

void c4::yml::FilterProcessorSrcDst::translate_esc_bulk ( const char *  s,
size_t  nw,
size_t  nr 
)
inlinenoexcept

Definition at line 110 of file filter_processor.hpp.

111  {
112  RYML_ASSERT(nw > 0);
113  RYML_ASSERT(nr > 0);
114  RYML_ASSERT(rpos+nr <= src.len);
115  if(wpos+nw <= dst.len)
116  memcpy(dst.str + wpos, s, nw);
117  wpos += nw;
118  rpos += 1 + nr;
119  }

References dst, rpos, src, and wpos.

Referenced by translate_esc_extending().

◆ translate_esc_extending()

void c4::yml::FilterProcessorSrcDst::translate_esc_extending ( const char *  s,
size_t  nw,
size_t  nr 
)
inlinenoexcept

Definition at line 120 of file filter_processor.hpp.

121  {
122  translate_esc_bulk(s, nw, nr);
123  }
void translate_esc_bulk(const char *s, size_t nw, size_t nr) noexcept

References translate_esc_bulk().

Member Data Documentation

◆ src

csubstr c4::yml::FilterProcessorSrcDst::src

◆ dst

substr c4::yml::FilterProcessorSrcDst::dst

◆ rpos

size_t c4::yml::FilterProcessorSrcDst::rpos

◆ wpos

size_t c4::yml::FilterProcessorSrcDst::wpos

write position

Definition at line 31 of file filter_processor.hpp.

Referenced by copy(), result(), set(), set_at(), setpos(), setwpos(), skipped_chars(), sofar(), translate_esc(), and translate_esc_bulk().


The documentation for this struct was generated from the following file: