StringRef SirenTextParser::ReadToken(StringRef& refProto) { refProto = refProto.TrimBegin(); if (refProto.IsEmpty()) { return StringRef::Empty; } if (StdString::IsDigit(refProto[0])) { Log::FormatError("Token cannot begin with number:{}", refProto[0]); return StringRef::Empty; } size_t tokenLength = 0; size_t length = refProto.Length(); for (size_t i = 0; i < length - 1; ++i) { int c = refProto[i]; if (StdString::IsToken(c)) { ++tokenLength; } else { break; } } StringRef token = refProto.SubString(0, tokenLength); refProto = refProto.SubString(tokenLength); return token; }
bool SirenTextParser::ReadExpectedChar(StringRef& refProto, char val) { refProto = refProto.TrimBegin(); if (refProto.IsEmpty() || refProto[0] != val) { return false; } refProto = refProto.SubString(1); return true; }
char SirenTextParser::ReadNextPrintChar(StringRef& refProto) { refProto = refProto.TrimBegin(); if (refProto.IsEmpty()) { return '\0'; } char c = refProto[0]; refProto = refProto.SubString(1); return c; }
bool SirenTextParser::EndType(StringRef& refProto) { refProto = refProto.TrimBegin(); intp index = refProto.IndexOf('}'); if (index < 0) { Log::Error("Cannot find }"); return false; } refProto = refProto.SubString(index + 1); return EndBlock(refProto);; }
StringRef SirenTextParser::ReadAttribute(StringRef& refProto) { refProto = refProto.TrimBegin(); intp index = refProto.IndexOf(']'); if (index < 0) { Log::Error("Cannot find ] on attribute"); return false; } StringRef result = refProto.SubString(0, index); refProto = refProto.SubString(index + 1); return result; }