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

Helper to control the line contents while parsing a buffer. More...

#include <parser_state.hpp>

Public Member Functions

 LineContents () RYML_NOEXCEPT=default
void reset_with_next_line (substr buf, size_t start) RYML_NOEXCEPT
size_t current_col () const RYML_NOEXCEPT
size_t current_col (csubstr s) const RYML_NOEXCEPT

Public Attributes

substr rem
 current line remainder, without newline characters
substr full
 full line, including newline characters \n and \r
size_t num_cols
 number of columns in the line, excluding newline characters (ie the initial size of rem)
size_t indentation
 number of spaces on the beginning of the line.

Detailed Description

Helper to control the line contents while parsing a buffer.

Definition at line 56 of file parser_state.hpp.

Constructor & Destructor Documentation

◆ LineContents()

c4::yml::LineContents::LineContents ( )
default

Member Function Documentation

◆ reset_with_next_line()

void c4::yml::LineContents::reset_with_next_line ( substr buf,
size_t start )
inline

Definition at line 66 of file parser_state.hpp.

67 {
68 _RYML_ASSERT_BASIC(start <= buf.len);
69 size_t end = start;
70 // get the current line stripped of newline chars
71 while((end < buf.len) && (buf.str[end] != '\n'))
72 ++end;
73 if(end < buf.len)
74 {
75 _RYML_ASSERT_BASIC(buf[end] == '\n');
76 full = buf.range(start, end + 1);
77 rem = buf.range(start, end);
78 }
79 else
80 {
81 // buffer ends without newline
82 full = rem = buf.sub(start);
83 }
84 size_t pos = rem.last_not_of('\r');
85 rem.len = (pos != npos) ? pos + 1 : 0;
86 num_cols = rem.len;
87 _RYML_ASSERT_BASIC(rem.find('\r') == npos);
88 // TODO move this to the parser state
89 indentation = rem.first_not_of(' '); // find the first column where the character is not a space
90 }
@ npos
a null string position
Definition common.hpp:263
substr rem
current line remainder, without newline characters
substr full
full line, including newline characters \n and \r
size_t num_cols
number of columns in the line, excluding newline characters (ie the initial size of rem)
size_t indentation
number of spaces on the beginning of the line.

◆ current_col() [1/2]

size_t c4::yml::LineContents::current_col ( ) const
inline

Definition at line 92 of file parser_state.hpp.

93 {
94 _RYML_ASSERT_BASIC(rem.str >= full.str);
95 return static_cast<size_t>(rem.str - full.str);
96 }

◆ current_col() [2/2]

size_t c4::yml::LineContents::current_col ( csubstr s) const
inline

Definition at line 98 of file parser_state.hpp.

99 {
100 _RYML_ASSERT_BASIC(s.str >= full.str);
101 _RYML_ASSERT_BASIC(s.str <= rem.end());
102 return static_cast<size_t>(s.str - full.str);
103 }

Member Data Documentation

◆ rem

substr c4::yml::LineContents::rem

current line remainder, without newline characters

Definition at line 58 of file parser_state.hpp.

◆ full

substr c4::yml::LineContents::full

full line, including newline characters \n and \r

Definition at line 59 of file parser_state.hpp.

◆ num_cols

size_t c4::yml::LineContents::num_cols

number of columns in the line, excluding newline characters (ie the initial size of rem)

Definition at line 60 of file parser_state.hpp.

◆ indentation

size_t c4::yml::LineContents::indentation

number of spaces on the beginning of the line.

Definition at line 62 of file parser_state.hpp.


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