rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
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
size_t wcap
 write capacity - the capacity of the subject string's buffer
size_t rpos
 read position
size_t wpos
 write position

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

◆ FilterProcessorInplaceEndExtending()

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

Member Function Documentation

◆ setwpos()

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

Definition at line 182 of file filter_processor.hpp.

182{ wpos = wpos_; }

◆ setpos()

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_; }

◆ set_at_end()

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

Definition at line 184 of file filter_processor.hpp.

◆ has_more_chars() [1/2]

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

Definition at line 186 of file filter_processor.hpp.

186{ return rpos < src.len; }

◆ has_more_chars() [2/2]

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; }

◆ result()

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 }

◆ sofar()

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); }
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2356

◆ rem()

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

Definition at line 198 of file filter_processor.hpp.

198{ return src.sub(rpos); }

◆ curr()

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]; }

◆ next()

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'; }

◆ skip() [1/2]

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

Definition at line 203 of file filter_processor.hpp.

203{ ++rpos; }

Referenced by set_at_end().

◆ skip() [2/2]

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

Definition at line 204 of file filter_processor.hpp.

204{ rpos += num; }

◆ set_at()

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 }

◆ set() [1/2]

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

Definition at line 214 of file filter_processor.hpp.

215 {
216 if(wpos < wcap) // respect write-capacity
217 src.str[wpos] = c;
218 ++wpos;
219 }

Referenced by set_at().

◆ set() [2/2]

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 }

◆ copy() [1/2]

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 }

◆ copy() [2/2]

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 }

◆ translate_esc()

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 }

◆ translate_esc_bulk()

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.

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 }

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 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

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

Referenced by FilterProcessorInplaceEndExtending(), copy(), copy(), result(), set(), 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 171 of file filter_processor.hpp.

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


The documentation for this struct was generated from the following file:
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/latest/src/c4/yml/filter_processor.hpp