rapidyaml  0.10.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 ()=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 51 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 60 of file parser_state.hpp.

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

References reset().

◆ reset()

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

Definition at line 81 of file parser_state.hpp.

82  {
83  rem = stripped_;
84  indentation = stripped_.first_not_of(' '); // find the first column where the character is not a space
85  full = full_;
86  stripped = stripped_;
87  }
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 89 of file parser_state.hpp.

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

References full, and rem.

◆ current_col() [2/2]

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

Definition at line 119 of file parser_state.hpp.

120  {
121  RYML_ASSERT(s.str >= full.str);
122  RYML_ASSERT(full.is_super(s));
123  size_t col = static_cast<size_t>(s.str - full.str);
124  return col;
125  }

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 53 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 55 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 56 of file parser_state.hpp.

Referenced by reset().


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