public static StringBuilder ExtractString(this StringBuilder @this, int startIndex, out int endIndex) { if (@this.Length > startIndex + 1) { var ch1 = @this[startIndex]; var ch2 = @this[startIndex + 1]; if (ch1 == '@' && ch2 == '"') { // @"my string" return(@this.ExtractStringArobasDoubleQuote(startIndex, out endIndex)); } if (ch1 == '@' && ch2 == '\'') { // WARNING: This is not a valid string, however single quote is often used to make it more readable in text templating // @'my string' return(@this.ExtractStringArobasSingleQuote(startIndex, out endIndex)); } if (ch1 == '"') { // "my string" return(@this.ExtractStringDoubleQuote(startIndex, out endIndex)); } if (ch1 == '\'') { // WARNING: This is not a valid string, however single quote is often used to make it more readable in text templating // 'my string' return(@this.ExtractStringSingleQuote(startIndex, out endIndex)); } } endIndex = -1; return(null); }
public static StringBuilder ExtractToken(this StringBuilder @this, int startIndex, out int endIndex) { /* A token can be: * - Keyword / Literal * - Operator * - String * - Integer * - Real */ // CHECK first which type is the token var ch1 = @this[startIndex]; var pos = startIndex + 1; switch (ch1) { case '@': if (pos < @this.Length && @this[pos] == '"') { return(@this.ExtractStringArobasDoubleQuote(startIndex, out endIndex)); } if (pos < @this.Length && @this[pos] == '\'') { return(@this.ExtractStringArobasSingleQuote(startIndex, out endIndex)); } break; case '"': return(@this.ExtractStringDoubleQuote(startIndex, out endIndex)); case '\'': return(@this.ExtractStringSingleQuote(startIndex, out endIndex)); case '`': case '~': case '!': case '#': case '$': case '%': case '^': case '&': case '*': case '(': case ')': case '-': case '_': case '=': case '+': case '[': case ']': case '{': case '}': case '|': case ':': case ';': case ',': case '.': case '<': case '>': case '?': case '/': return(@this.ExtractOperator(startIndex, out endIndex)); case '0': if (pos < @this.Length && (@this[pos] == 'x' || @this[pos] == 'X')) { return(@this.ExtractHexadecimal(startIndex, out endIndex)); } return(@this.ExtractNumber(startIndex, out endIndex)); case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return(@this.ExtractNumber(startIndex, out endIndex)); default: if ((ch1 >= 'a' && ch1 <= 'z') || (ch1 >= 'A' && ch1 <= 'Z')) { return(@this.ExtractKeyword(startIndex, out endIndex)); } endIndex = -1; return(null); } throw new Exception("Invalid token"); }
public static StringBuilder ExtractStringDoubleQuote(this StringBuilder @this) { return(@this.ExtractStringDoubleQuote(0)); }
public static StringBuilder ExtractStringDoubleQuote(this StringBuilder @this, int startIndex) { int endIndex; return(@this.ExtractStringDoubleQuote(startIndex, out endIndex)); }
public static StringBuilder ExtractStringDoubleQuote(this StringBuilder @this, out int endIndex) { return(@this.ExtractStringDoubleQuote(0, out endIndex)); }