rapidyaml  0.11.0
parse and emit YAML, and do it fast
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 More...
 
substr full
 full line, including newline characters \n and \r More...
 
size_t num_cols
 number of columns in the line, excluding newline characters (ie the initial size of rem) More...
 
size_t indentation
 number of spaces on the beginning of the line. TODO this should not be a member of this object. We only care about indentation in block mode, so this should be moved to the parser state. More...
 

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 69 of file parser_state.hpp.

70  {
71  _RYML_ASSERT_BASIC(start <= buf.len);
72  size_t end = start;
73  // get the current line stripped of newline chars
74  while((end < buf.len) && (buf.str[end] != '\n'))
75  ++end;
76  if(end < buf.len)
77  {
78  _RYML_ASSERT_BASIC(buf[end] == '\n');
79  full = buf.range(start, end + 1);
80  rem = buf.range(start, end);
81  }
82  else
83  {
84  // buffer ends without newline
85  full = rem = buf.sub(start);
86  }
87  size_t pos = rem.last_not_of('\r');
88  rem.len = (pos != npos) ? pos + 1 : 0;
89  num_cols = rem.len;
90  _RYML_ASSERT_BASIC(rem.find('\r') == npos);
91  // TODO move this to the parser state
92  indentation = rem.first_not_of(' '); // find the first column where the character is not a space
93  }
@ npos
a null string position
Definition: common.hpp:258
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. TODO this should not be a member of this object....

References full, indentation, c4::yml::npos, num_cols, and rem.

◆ current_col() [1/2]

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

Definition at line 95 of file parser_state.hpp.

96  {
97  _RYML_ASSERT_BASIC(rem.str >= full.str);
98  return static_cast<size_t>(rem.str - full.str);
99  }

References full, and rem.

◆ current_col() [2/2]

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

Definition at line 101 of file parser_state.hpp.

102  {
103  _RYML_ASSERT_BASIC(s.str >= full.str);
104  _RYML_ASSERT_BASIC(s.str <= rem.end());
105  return static_cast<size_t>(s.str - full.str);
106  }

References full, and rem.

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. TODO this should not be a member of this object. We only care about indentation in block mode, so this should be moved to the parser state.

Definition at line 62 of file parser_state.hpp.


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