public string ReadWord() { var b = new ByteBuilder(); while (CanRead) { byte c = Data[Position]; if (c == '\r' || c == '\n' || c == ':' || c == ',' || c == ']') { break; } b.Append(c); Position++; } return(b.ToString()); }
public string ReadValue() { var b = new ByteBuilder(); ValueLength = 0; if (Data[Position] == '\"') { Position++; while (CanRead && Data[Position] != '\r' && Data[Position] != '\n') { if (Data[Position] == '\"' && Data[Position - 1] != '\\') { Position++; break; } b.Append(Data[Position]); Position++; } ValueLength = 1; return(b.ToString()); } else if (Data[Position] == '|' || Data[Position] == '>') { int indent = CurrentLineIndent; SkipLine(); MoveToIndentEnd(); if (CurrentLineIndent < indent) // Technically valid { return(""); } // Remove all comment blocks, makes it easier to handle afterwards indent = CurrentLineIndent; int readLines = 0; bool trim = true; bool blockComment = false; int read = 0; while (CanRead) { char c = (char)Data[Position]; if (c == '\n' || (c == '\r' && Position + 1 < Length && Data[Position + 1] == '\n')) { if (c == '\n') { Position++; } else { Position += 2; } NextLine(); MoveToIndentEnd(indent); if (read > 0) { b.Append((byte)' '); } readLines++; trim = true; read = 0; continue; } if (CurrentLineIndent < indent) // Needs to be checked after to make an exception for empty lines { break; } if (Position + 1 < Length) { if (blockComment) { if (c == '*' && Data[Position + 1] == '/') { blockComment = false; Position++; } Position++; continue; } if (c == '/' && Data[Position + 1] == '/') { SkipLine(); MoveToIndentEnd(indent); readLines++; trim = true; read = 0; continue; } else if (c == '/' && Data[Position + 1] == '*') { blockComment = true; Position++; continue; } } if (trim) { if (c == ' ' || c == '\t') { Position++; continue; } } trim = false; b.Append((byte)c); read++; Position++; } ValueLength = readLines + 1; return(b.ToString().TrimEnd(' ')); } else { while (CanRead && Data[Position] != '\r' && Data[Position] != '\n' && Data[Position] != '#') { b.Append(Data[Position]); Position++; } ValueLength = 1; return(b.ToString().TrimEnd(' ', '\t')); } }