rapidyaml  0.7.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 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  char const* C4_RESTRICT b = &buf[offset];
62  char const* C4_RESTRICT e = b;
63  // get the current line stripped of newline chars
64  while(e < buf.end() && (*e != '\n' && *e != '\r'))
65  ++e;
66  RYML_ASSERT(e >= b);
67  const substr stripped_ = buf.sub(offset, static_cast<size_t>(e - b));
68  // advance pos to include the first line ending
69  if(e != buf.end() && *e == '\r')
70  ++e;
71  if(e != buf.end() && *e == '\n')
72  ++e;
73  RYML_ASSERT(e >= b);
74  const substr full_ = buf.sub(offset, static_cast<size_t>(e - b));
75  reset(full_, stripped_);
76  }
void reset(substr full_, substr stripped_)

References reset().

◆ reset()

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

Definition at line 78 of file parser_state.hpp.

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

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

References full, and rem.

◆ current_col() [2/2]

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

Definition at line 117 of file parser_state.hpp.

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

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: