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

Filters in place. More...

#include <filter_processor.hpp>

Public Member Functions

 FilterProcessorInplaceEndExtending (substr src_, size_t wcap_) 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
 
FilterResult result () const noexcept
 
csubstr sofar () const noexcept
 
csubstr rem () const noexcept
 
char curr () const noexcept
 
char next () 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

substr src
 the subject string More...
 
size_t wcap
 write capacity - the capacity of the subject string's buffer More...
 
size_t rpos
 read position More...
 
size_t wpos
 write position More...
 

Detailed Description

Filters in place.

While the result may be larger than the source, any extending happens only at the end of the string. Consequently, it's impossible for characters to be left unfiltered.

See also
FilterProcessorInplaceMidExtending

Definition at line 144 of file filter_processor.hpp.

Constructor & Destructor Documentation

◆ FilterProcessorInplaceEndExtending()

c4::yml::FilterProcessorInplaceEndExtending::FilterProcessorInplaceEndExtending ( substr  src_,
size_t  wcap_ 
)
inlinenoexcept

Definition at line 151 of file filter_processor.hpp.

152  : src(src_)
153  , wcap(wcap_)
154  , rpos(0)
155  , wpos(0)
156  {
157  RYML_ASSERT(wcap >= src.len);
158  }
size_t wcap
write capacity - the capacity of the subject string's buffer

References src, and wcap.

Member Function Documentation

◆ setwpos()

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

Definition at line 160 of file filter_processor.hpp.

160 { wpos = wpos_; }

References wpos.

◆ setpos()

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

Definition at line 161 of file filter_processor.hpp.

161 { rpos = rpos_; wpos = wpos_; }

References rpos, and wpos.

◆ set_at_end()

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

Definition at line 162 of file filter_processor.hpp.

References rpos, skip(), and src.

◆ has_more_chars() [1/2]

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

Definition at line 164 of file filter_processor.hpp.

164 { return rpos < src.len; }

References rpos, and src.

◆ has_more_chars() [2/2]

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

Definition at line 165 of file filter_processor.hpp.

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

References rpos, and src.

◆ result()

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

Definition at line 167 of file filter_processor.hpp.

168  {
169  _c4dbgip("inplace: wpos={} wcap={} small={}", wpos, wcap, wpos > rpos);
170  FilterResult ret;
171  ret.str.str = (wpos <= wcap) ? src.str : nullptr;
172  ret.str.len = wpos;
173  return ret;
174  }

References rpos, src, wcap, and wpos.

◆ sofar()

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

Definition at line 175 of file filter_processor.hpp.

175 { return csubstr(src.str, wpos <= wcap ? wpos : wcap); }

References src, wcap, and wpos.

◆ rem()

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

Definition at line 176 of file filter_processor.hpp.

176 { return src.sub(rpos); }

References rpos, and src.

◆ curr()

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

Definition at line 178 of file filter_processor.hpp.

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

References rpos, and src.

◆ next()

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

Definition at line 179 of file filter_processor.hpp.

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

References rpos, and src.

◆ skip() [1/2]

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

Definition at line 181 of file filter_processor.hpp.

181 { ++rpos; }

References rpos.

Referenced by set_at_end().

◆ skip() [2/2]

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

Definition at line 182 of file filter_processor.hpp.

182 { rpos += num; }

References rpos.

◆ set_at()

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

Definition at line 184 of file filter_processor.hpp.

185  {
186  RYML_ASSERT(pos < wpos);
187  const size_t save = wpos;
188  wpos = pos;
189  set(c);
190  wpos = save;
191  }

References set(), and wpos.

◆ set() [1/2]

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

Definition at line 192 of file filter_processor.hpp.

193  {
194  if(wpos < wcap) // respect write-capacity
195  src.str[wpos] = c;
196  ++wpos;
197  }

References src, wcap, and wpos.

Referenced by set_at().

◆ set() [2/2]

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

Definition at line 198 of file filter_processor.hpp.

199  {
200  RYML_ASSERT(num);
201  if(wpos + num <= wcap) // respect write-capacity
202  memset(src.str + wpos, c, num);
203  wpos += num;
204  }

References src, wcap, and wpos.

◆ copy() [1/2]

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

Definition at line 206 of file filter_processor.hpp.

207  {
208  RYML_ASSERT(wpos <= rpos);
209  RYML_ASSERT(rpos < src.len);
210  if(wpos < wcap) // respect write-capacity
211  src.str[wpos] = src.str[rpos];
212  ++rpos;
213  ++wpos;
214  }

References rpos, src, wcap, and wpos.

◆ copy() [2/2]

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

Definition at line 215 of file filter_processor.hpp.

216  {
217  RYML_ASSERT(num);
218  RYML_ASSERT(rpos+num <= src.len);
219  RYML_ASSERT(wpos <= rpos);
220  if(wpos + num <= wcap) // respect write-capacity
221  {
222  if(wpos + num <= rpos) // there is no overlap
223  memcpy(src.str + wpos, src.str + rpos, num);
224  else // there is overlap
225  memmove(src.str + wpos, src.str + rpos, num);
226  }
227  rpos += num;
228  wpos += num;
229  }

References rpos, src, wcap, and wpos.

◆ translate_esc()

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

Definition at line 231 of file filter_processor.hpp.

232  {
233  RYML_ASSERT(rpos + 2 <= src.len);
234  RYML_ASSERT(wpos <= rpos);
235  if(wpos < wcap) // respect write-capacity
236  src.str[wpos] = c;
237  rpos += 2; // add 1u to account for the escape character
238  ++wpos;
239  }

References rpos, src, wcap, and wpos.

◆ translate_esc_bulk()

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

Definition at line 241 of file filter_processor.hpp.

242  {
243  RYML_ASSERT(nw > 0);
244  RYML_ASSERT(nr > 0);
245  RYML_ASSERT(nw <= nr + 1u);
246  RYML_ASSERT(rpos+nr <= src.len);
247  RYML_ASSERT(wpos <= rpos);
248  const size_t wpos_next = wpos + nw;
249  const size_t rpos_next = rpos + nr + 1u; // add 1u to account for the escape character
250  RYML_ASSERT(wpos_next <= rpos_next);
251  if(wpos_next <= wcap)
252  memcpy(src.str + wpos, s, nw);
253  rpos = rpos_next;
254  wpos = wpos_next;
255  }

References rpos, src, wcap, and wpos.

Referenced by translate_esc_extending().

◆ translate_esc_extending()

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

Definition at line 257 of file filter_processor.hpp.

258  {
259  translate_esc_bulk(s, nw, nr);
260  }
void translate_esc_bulk(const char *s, size_t nw, size_t nr) noexcept

References translate_esc_bulk().

Member Data Documentation

◆ src

substr c4::yml::FilterProcessorInplaceEndExtending::src

◆ wcap

size_t c4::yml::FilterProcessorInplaceEndExtending::wcap

write capacity - the capacity of the subject string's buffer

Definition at line 147 of file filter_processor.hpp.

Referenced by FilterProcessorInplaceEndExtending(), copy(), result(), set(), sofar(), translate_esc(), and translate_esc_bulk().

◆ rpos

size_t c4::yml::FilterProcessorInplaceEndExtending::rpos

◆ wpos

size_t c4::yml::FilterProcessorInplaceEndExtending::wpos

write position

Definition at line 149 of file filter_processor.hpp.

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


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