rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
c4::yml::detail Namespace Reference

a CRTP base providing read-only methods for ConstNodeRef and NodeRef More...

Classes

struct  RoNodeMethods

Functions

csubstr _get_text_region (csubstr text, size_t pos, size_t num_lines_before, size_t num_lines_after)

Detailed Description

a CRTP base providing read-only methods for ConstNodeRef and NodeRef

Function Documentation

◆ _get_text_region()

csubstr c4::yml::detail::_get_text_region ( csubstr text,
size_t pos,
size_t num_lines_before,
size_t num_lines_after )

Definition at line 283 of file common.cpp.

284{
285 if(pos > text.len)
286 return text.last(0);
287 size_t before = text.first(pos).last_of('\n');
288 size_t before_count = 0;
289 while((before != npos) && (++before_count <= num_lines_before))
290 {
291 if(before == 0)
292 break;
293 before = text.first(--before).last_of('\n');
294 }
295 if(before < text.len || before == npos)
296 ++before;
297 size_t after = text.first_of('\n', pos);
298 size_t after_count = 0;
299 while((after != npos) && (++after_count <= num_lines_after))
300 {
301 ++after;
302 if(after >= text.len)
303 break;
304 after = text.first_of('\n', after);
305 }
306 return before <= after ? text.range(before, after) : text.first(0);
307}
@ npos
a null string position
Definition common.hpp:263
basic_substring range(size_t first, size_t last=npos) const noexcept
return [first,last[.
Definition substr.hpp:520
size_t last_of(const C c, size_t start=npos) const
Definition substr.hpp:947
size_t len
the length of the substring
Definition substr.hpp:218
basic_substring last(size_t num) const noexcept
return the last num elements: [len-num,len[
Definition substr.hpp:537
size_t first_of(const C c, size_t start=0) const
Definition substr.hpp:935
basic_substring first(size_t num) const noexcept
return the first num elements: [0,num[
Definition substr.hpp:530