rapidyaml  0.16.0
parseandemitYAML,anddoitfast
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 166 of file filter_processor.hpp.

Constructor & Destructor Documentation

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

Definition at line 173 of file filter_processor.hpp.

174  : src(src_)
175  , wcap(wcap_)
176  , rpos(0)
177  , wpos(0)
178  {
179  RYML_ASSERT_BASIC_(wcap >= src.len);
180  }
size_t wcap
write capacity - the capacity of the subject string's buffer
size_t len
the length of the substring
Definition: substr.hpp:218

Member Function Documentation

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

Definition at line 182 of file filter_processor.hpp.

182 { wpos = wpos_; }
void c4::yml::FilterProcessorInplaceEndExtending::setpos ( size_t  rpos_,
size_t  wpos_ 
)
inlinenoexcept

Definition at line 183 of file filter_processor.hpp.

183 { rpos = rpos_; wpos = wpos_; }
void c4::yml::FilterProcessorInplaceEndExtending::set_at_end ( )
inlinenoexcept

Definition at line 184 of file filter_processor.hpp.

184 { skip(src.len - rpos); }
size_t len
the length of the substring
Definition: substr.hpp:218
bool c4::yml::FilterProcessorInplaceEndExtending::has_more_chars ( ) const
inlinenoexcept

Definition at line 186 of file filter_processor.hpp.

186 { return rpos < src.len; }
size_t len
the length of the substring
Definition: substr.hpp:218
bool c4::yml::FilterProcessorInplaceEndExtending::has_more_chars ( size_t  maxpos) const
inlinenoexcept

Definition at line 187 of file filter_processor.hpp.

187 { RYML_ASSERT_BASIC_(maxpos <= src.len); return rpos < maxpos; }
size_t len
the length of the substring
Definition: substr.hpp:218
FilterResult c4::yml::FilterProcessorInplaceEndExtending::result ( ) const
inlinenoexcept

Definition at line 189 of file filter_processor.hpp.

190  {
191  _c4dbgip("inplace: wpos={} wcap={} small={}", wpos, wcap, wpos > rpos);
192  FilterResult ret;
193  ret.str.str = (wpos <= wcap) ? src.str : nullptr;
194  ret.str.len = wpos;
195  return ret;
196  }
size_t wcap
write capacity - the capacity of the subject string's buffer
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
csubstr c4::yml::FilterProcessorInplaceEndExtending::sofar ( ) const
inlinenoexcept

Definition at line 197 of file filter_processor.hpp.

197 { return csubstr(src.str, wpos <= wcap ? wpos : wcap); }
size_t wcap
write capacity - the capacity of the subject string's buffer
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356
csubstr c4::yml::FilterProcessorInplaceEndExtending::rem ( ) const
inlinenoexcept

Definition at line 198 of file filter_processor.hpp.

198 { return src.sub(rpos); }
basic_substring sub(size_t first) const noexcept
return [first,len[
Definition: substr.hpp:502
char c4::yml::FilterProcessorInplaceEndExtending::curr ( ) const
inlinenoexcept

Definition at line 200 of file filter_processor.hpp.

200 { RYML_ASSERT_BASIC_(rpos < src.len); return src[rpos]; }
size_t len
the length of the substring
Definition: substr.hpp:218
char c4::yml::FilterProcessorInplaceEndExtending::next ( ) const
inlinenoexcept

Definition at line 201 of file filter_processor.hpp.

201 { return rpos+1 < src.len ? src[rpos+1] : '\0'; }
size_t len
the length of the substring
Definition: substr.hpp:218
void c4::yml::FilterProcessorInplaceEndExtending::skip ( )
inlinenoexcept

Definition at line 203 of file filter_processor.hpp.

Referenced by set_at_end().

203 { ++rpos; }
void c4::yml::FilterProcessorInplaceEndExtending::skip ( size_t  num)
inlinenoexcept

Definition at line 204 of file filter_processor.hpp.

204 { rpos += num; }
void c4::yml::FilterProcessorInplaceEndExtending::set_at ( size_t  pos,
char  c 
)
inlinenoexcept

Definition at line 206 of file filter_processor.hpp.

207  {
208  RYML_ASSERT_BASIC_(pos < wpos);
209  const size_t save = wpos;
210  wpos = pos;
211  set(c);
212  wpos = save;
213  }
void c4::yml::FilterProcessorInplaceEndExtending::set ( char  c)
inlinenoexcept

Definition at line 214 of file filter_processor.hpp.

Referenced by set_at().

215  {
216  if(wpos < wcap) // respect write-capacity
217  src.str[wpos] = c;
218  ++wpos;
219  }
size_t wcap
write capacity - the capacity of the subject string's buffer
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
void c4::yml::FilterProcessorInplaceEndExtending::set ( char  c,
size_t  num 
)
inlinenoexcept

Definition at line 220 of file filter_processor.hpp.

221  {
222  RYML_ASSERT_BASIC_(num);
223  if(wpos + num <= wcap) // respect write-capacity
224  memset(src.str + wpos, c, num);
225  wpos += num;
226  }
size_t wcap
write capacity - the capacity of the subject string's buffer
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
void c4::yml::FilterProcessorInplaceEndExtending::copy ( )
inlinenoexcept

Definition at line 228 of file filter_processor.hpp.

229  {
230  RYML_ASSERT_BASIC_(wpos <= rpos);
231  RYML_ASSERT_BASIC_(rpos < src.len);
232  if(wpos < wcap) // respect write-capacity
233  src.str[wpos] = src.str[rpos];
234  ++rpos;
235  ++wpos;
236  }
size_t wcap
write capacity - the capacity of the subject string's buffer
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
size_t len
the length of the substring
Definition: substr.hpp:218
void c4::yml::FilterProcessorInplaceEndExtending::copy ( size_t  num)
inlinenoexcept

Definition at line 237 of file filter_processor.hpp.

238  {
239  RYML_ASSERT_BASIC_(num);
240  RYML_ASSERT_BASIC_(rpos+num <= src.len);
241  RYML_ASSERT_BASIC_(wpos <= rpos);
242  if(wpos + num <= wcap) // respect write-capacity
243  {
244  if(wpos + num <= rpos) // there is no overlap
245  memcpy(src.str + wpos, src.str + rpos, num);
246  else // there is overlap
247  memmove(src.str + wpos, src.str + rpos, num);
248  }
249  rpos += num;
250  wpos += num;
251  }
size_t wcap
write capacity - the capacity of the subject string's buffer
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
size_t len
the length of the substring
Definition: substr.hpp:218
void c4::yml::FilterProcessorInplaceEndExtending::translate_esc ( char  c)
inlinenoexcept

Definition at line 253 of file filter_processor.hpp.

254  {
255  RYML_ASSERT_BASIC_(rpos + 2 <= src.len);
256  RYML_ASSERT_BASIC_(wpos <= rpos);
257  if(wpos < wcap) // respect write-capacity
258  src.str[wpos] = c;
259  rpos += 2; // add 1u to account for the escape character
260  ++wpos;
261  }
size_t wcap
write capacity - the capacity of the subject string's buffer
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
size_t len
the length of the substring
Definition: substr.hpp:218
void c4::yml::FilterProcessorInplaceEndExtending::translate_esc_bulk ( const char *  s,
size_t  nw,
size_t  nr 
)
inlinenoexcept

Definition at line 263 of file filter_processor.hpp.

Referenced by translate_esc_extending().

264  {
265  RYML_ASSERT_BASIC_(nw > 0);
266  RYML_ASSERT_BASIC_(nr > 0);
267  RYML_ASSERT_BASIC_(nw <= nr + 1u);
268  RYML_ASSERT_BASIC_(rpos+nr <= src.len);
269  RYML_ASSERT_BASIC_(wpos <= rpos);
270  const size_t wpos_next = wpos + nw;
271  const size_t rpos_next = rpos + nr + 1u; // add 1u to account for the escape character
272  RYML_ASSERT_BASIC_(wpos_next <= rpos_next);
273  if(wpos_next <= wcap)
274  memcpy(src.str + wpos, s, nw);
275  rpos = rpos_next;
276  wpos = wpos_next;
277  }
size_t wcap
write capacity - the capacity of the subject string's buffer
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
size_t len
the length of the substring
Definition: substr.hpp:218
void c4::yml::FilterProcessorInplaceEndExtending::translate_esc_extending ( const char *  s,
size_t  nw,
size_t  nr 
)
inlinenoexcept

Definition at line 279 of file filter_processor.hpp.

280  {
281  translate_esc_bulk(s, nw, nr);
282  }
void translate_esc_bulk(const char *s, size_t nw, size_t nr) noexcept

Member Data Documentation

substr c4::yml::FilterProcessorInplaceEndExtending::src

the subject string

Definition at line 168 of file filter_processor.hpp.

size_t c4::yml::FilterProcessorInplaceEndExtending::wcap

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

Definition at line 169 of file filter_processor.hpp.

Referenced by result().

size_t c4::yml::FilterProcessorInplaceEndExtending::rpos

read position

Definition at line 170 of file filter_processor.hpp.

Referenced by copy(), curr(), and skip().

size_t c4::yml::FilterProcessorInplaceEndExtending::wpos

write position

Definition at line 171 of file filter_processor.hpp.

Referenced by copy(), set(), set_at(), and translate_esc().


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