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; }
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; }
StringRef FileInfo::GetExtension( StringRef file ) { intp index= file.IndexOf('.'); if (index>0) { return file.SubString(index); } return StringRef::Empty; }
bool SirenTextParser::ReadExpectedChar(StringRef& refProto, char val) { refProto = refProto.TrimBegin(); if (refProto.IsEmpty() || refProto[0] != val) { return false; } refProto = refProto.SubString(1); return true; }
bool SirenTextParser::ReadFunctionArguments(StringRef& refProto, List<StringRef>& outArguments) { //read arguments intp endIndex = refProto.IndexOf(')'); if (endIndex < 0) { Log::Error("Invalid function.Lost ')' "); return false; } StringRef args = refProto.SubString(1, endIndex - 1); bool isSuccess = StringParser::Split(args, ",", outArguments, false); if (!isSuccess) { Log::FormatError("Invalid function argument:{}", args); return false; } refProto = refProto.SubString(endIndex); return EndBlock(refProto); }
bool ISirenFunction::Parse(SirenAssembly& assembly, StringRef& refProto) { //read arguments intp endIndex = refProto.IndexOf(')'); if (endIndex < 0) { Log::Error("Invalid function.Lost ')' "); return false; } StringRef args = refProto.SubString(1, endIndex - 1); bool isSuccess = StringParser::Split(args, ",", mArguments, false); if (!isSuccess) { Log::FormatError("Invalid function argument:{}", args); return false; } refProto = refProto.SubString(endIndex); return SirenTextParser::EndBlock(refProto); }
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);; }
FileType FileInfo::CheckFileType( StringRef fileExt ) { if (fileExt.IsNullOrEmpty()) { return FileType::Unknown; } fileExt=fileExt.SubString(1); //remove '.' at head FileType* fileType= mFileExtDict.TryGetValue(fileExt); if (fileType!=NULL) { return *fileType; } return FileType::Unknown; }