rapidyaml  0.12.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 172 of file filter_processor.hpp.

Constructor & Destructor Documentation

◆ FilterProcessorInplaceEndExtending()

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

Definition at line 179 of file filter_processor.hpp.

180  : src(src_)
181  , wcap(wcap_)
182  , rpos(0)
183  , wpos(0)
184  {
185  _RYML_ASSERT_BASIC(wcap >= src.len);
186  }
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 188 of file filter_processor.hpp.

188 { wpos = wpos_; }

References wpos.

◆ setpos()

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

Definition at line 189 of file filter_processor.hpp.

189 { rpos = rpos_; wpos = wpos_; }

References rpos, and wpos.

◆ set_at_end()

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

Definition at line 190 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 192 of file filter_processor.hpp.

192 { 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 193 of file filter_processor.hpp.

193 { _RYML_ASSERT_BASIC(maxpos <= src.len); return rpos < maxpos; }

References rpos, and src.

◆ result()

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

Definition at line 195 of file filter_processor.hpp.

196  {
197  _c4dbgip("inplace: wpos={} wcap={} small={}", wpos, wcap, wpos > rpos);
198  FilterResult ret;
199  ret.str.str = (wpos <= wcap) ? src.str : nullptr;
200  ret.str.len = wpos;
201  return ret;
202  }

References rpos, src, c4::yml::FilterResult::str, wcap, and wpos.

◆ sofar()

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

Definition at line 203 of file filter_processor.hpp.

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

References src, wcap, and wpos.

◆ rem()

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

Definition at line 204 of file filter_processor.hpp.

204 { return src.sub(rpos); }

References rpos, and src.

◆ curr()

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

Definition at line 206 of file filter_processor.hpp.

206 { _RYML_ASSERT_BASIC(rpos < src.len); return src[rpos]; }

References rpos, and src.

◆ next()

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

Definition at line 207 of file filter_processor.hpp.

207 { 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 209 of file filter_processor.hpp.

209 { ++rpos; }

References rpos.

◆ skip() [2/2]

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

Definition at line 210 of file filter_processor.hpp.

210 { rpos += num; }

References rpos.

◆ set_at()

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

Definition at line 212 of file filter_processor.hpp.

213  {
214  _RYML_ASSERT_BASIC(pos < wpos);
215  const size_t save = wpos;
216  wpos = pos;
217  set(c);
218  wpos = save;
219  }

References set(), and wpos.

◆ set() [1/2]

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

Definition at line 220 of file filter_processor.hpp.

221  {
222  if(wpos < wcap) // respect write-capacity
223  src.str[wpos] = c;
224  ++wpos;
225  }

References src, wcap, and wpos.

◆ set() [2/2]

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

Definition at line 226 of file filter_processor.hpp.

227  {
228  _RYML_ASSERT_BASIC(num);
229  if(wpos + num <= wcap) // respect write-capacity
230  memset(src.str + wpos, c, num);
231  wpos += num;
232  }

References src, wcap, and wpos.

◆ copy() [1/2]

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

Definition at line 234 of file filter_processor.hpp.

235  {
236  _RYML_ASSERT_BASIC(wpos <= rpos);
237  _RYML_ASSERT_BASIC(rpos < src.len);
238  if(wpos < wcap) // respect write-capacity
239  src.str[wpos] = src.str[rpos];
240  ++rpos;
241  ++wpos;
242  }

References rpos, src, wcap, and wpos.

◆ copy() [2/2]

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

Definition at line 243 of file filter_processor.hpp.

244  {
245  _RYML_ASSERT_BASIC(num);
246  _RYML_ASSERT_BASIC(rpos+num <= src.len);
247  _RYML_ASSERT_BASIC(wpos <= rpos);
248  if(wpos + num <= wcap) // respect write-capacity
249  {
250  if(wpos + num <= rpos) // there is no overlap
251  memcpy(src.str + wpos, src.str + rpos, num);
252  else // there is overlap
253  memmove(src.str + wpos, src.str + rpos, num);
254  }
255  rpos += num;
256  wpos += num;
257  }

References rpos, src, wcap, and wpos.

◆ translate_esc()

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

Definition at line 259 of file filter_processor.hpp.

260  {
261  _RYML_ASSERT_BASIC(rpos + 2 <= src.len);
262  _RYML_ASSERT_BASIC(wpos <= rpos);
263  if(wpos < wcap) // respect write-capacity
264  src.str[wpos] = c;
265  rpos += 2; // add 1u to account for the escape character
266  ++wpos;
267  }

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 269 of file filter_processor.hpp.

270  {
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);
275  _RYML_ASSERT_BASIC(wpos <= rpos);
276  const size_t wpos_next = wpos + nw;
277  const size_t rpos_next = rpos + nr + 1u; // add 1u to account for the escape character
278  _RYML_ASSERT_BASIC(wpos_next <= rpos_next);
279  if(wpos_next <= wcap)
280  memcpy(src.str + wpos, s, nw);
281  rpos = rpos_next;
282  wpos = wpos_next;
283  }

References rpos, src, wcap, and wpos.

◆ translate_esc_extending()

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

Definition at line 285 of file filter_processor.hpp.

286  {
287  translate_esc_bulk(s, nw, nr);
288  }
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

the subject string

Definition at line 174 of file filter_processor.hpp.

◆ wcap

size_t c4::yml::FilterProcessorInplaceEndExtending::wcap

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

Definition at line 175 of file filter_processor.hpp.

◆ rpos

size_t c4::yml::FilterProcessorInplaceEndExtending::rpos

read position

Definition at line 176 of file filter_processor.hpp.

◆ wpos

size_t c4::yml::FilterProcessorInplaceEndExtending::wpos

write position

Definition at line 177 of file filter_processor.hpp.


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