rapidyaml  0.7.1
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 ()=default
 
void reset_with_next_line (substr buf, size_t offset)
 
void reset (substr full_, substr stripped_)
 
size_t current_col () const RYML_NOEXCEPT
 
size_t current_col (csubstr s) const RYML_NOEXCEPT
 

Public Attributes

substr rem
 the stripped line remainder; initially starts at the first non-space character More...
 
size_t indentation
 the number of spaces on the beginning of the line More...
 
substr full
 the full line, including newlines on the right More...
 
substr stripped
 the stripped line, excluding newlines on the right More...
 

Detailed Description

Helper to control the line contents while parsing a buffer.

Definition at line 49 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  offset 
)
inline

Definition at line 58 of file parser_state.hpp.

59  {
60  RYML_ASSERT(offset <= buf.len);
61  size_t e = offset;
62  // get the current line stripped of newline chars
63  while(e < buf.len && (buf.str[e] != '\n' && buf.str[e] != '\r'))
64  ++e;
65  RYML_ASSERT(e >= offset);
66  const substr stripped_ = buf.range(offset, e);
67  // advance pos to include the first line ending
68  if(e < buf.len && buf.str[e] == '\r')
69  ++e;
70  if(e < buf.len && buf.str[e] == '\n')
71  ++e;
72  const substr full_ = buf.range(offset, e);
73  reset(full_, stripped_);
74  }
void reset(substr full_, substr stripped_)

References reset().

◆ reset()

void c4::yml::LineContents::reset ( substr  full_,
substr  stripped_ 
)
inline

Definition at line 76 of file parser_state.hpp.

77  {
78  rem = stripped_;
79  indentation = stripped_.first_not_of(' '); // find the first column where the character is not a space
80  full = full_;
81  stripped = stripped_;
82  }
substr rem
the stripped line remainder; initially starts at the first non-space character
substr full
the full line, including newlines on the right
substr stripped
the stripped line, excluding newlines on the right
size_t indentation
the number of spaces on the beginning of the line

References full, indentation, rem, and stripped.

Referenced by reset_with_next_line().

◆ current_col() [1/2]

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

Definition at line 84 of file parser_state.hpp.

85  {
86  // WARNING: gcc x86 release builds were wrong (eg returning 0
87  // when the result should be 4 ) when this function was like
88  // this:
89  //
90  //return current_col(rem);
91  //
92  // (see below for the full definition of the called overload
93  // of current_col())
94  //
95  // ... so we explicitly inline the code in here:
96  RYML_ASSERT(rem.str >= full.str);
97  size_t col = static_cast<size_t>(rem.str - full.str);
98  return col;
99  //
100  // this was happening only on builds specifically with (gcc
101  // AND x86 AND release); no other builds were having the
102  // problem: not in debug, not in x64, not in other
103  // architectures, not in clang, not in visual studio. WTF!?
104  //
105  // Enabling debug prints with RYML_DBG made the problem go
106  // away, so these could not be used to debug the
107  // problem. Adding prints inside the called current_col() also
108  // made the problem go away! WTF!???
109  //
110  // a prize will be offered to anybody able to explain why this
111  // was happening.
112  }

References full, and rem.

◆ current_col() [2/2]

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

Definition at line 114 of file parser_state.hpp.

115  {
116  RYML_ASSERT(s.str >= full.str);
117  RYML_ASSERT(full.is_super(s));
118  size_t col = static_cast<size_t>(s.str - full.str);
119  return col;
120  }

References full.

Member Data Documentation

◆ rem

substr c4::yml::LineContents::rem

the stripped line remainder; initially starts at the first non-space character

Definition at line 51 of file parser_state.hpp.

Referenced by c4::yml::ParserState::at_line_beginning(), current_col(), and reset().

◆ indentation

size_t c4::yml::LineContents::indentation

◆ full

substr c4::yml::LineContents::full

the full line, including newlines on the right

Definition at line 53 of file parser_state.hpp.

Referenced by c4::yml::ParserState::at_line_beginning(), current_col(), and reset().

◆ stripped

substr c4::yml::LineContents::stripped

the stripped line, excluding newlines on the right

Definition at line 54 of file parser_state.hpp.

Referenced by reset().


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