public static string NextPart(ref string text) { StringSlice ssText = StringSlice.Prepare(text); StringSlice ssResult = SliceNextPart(ref ssText); text = ssText.ToString(); return(ssResult.ToString()); }
public static StringSlice Concat(StringSlice ssA, StringSlice ssB) { if (object.ReferenceEquals(ssA.str, ssB.str)) { if (ssA.offset + ssA.length == ssB.offset) { return(StringSlice.Prepare(ssA.str, ssA.offset, ssA.length + ssB.length)); } } return(StringSlice.Prepare(ssA.ToString() + ssB.ToString())); }
public StringSlice TrimStart(params char[] trimchars) { int end = this.offset + this.length; int trimcharsLength = trimchars.Length; for (int i = offset; i != end; i++) { for (int j = 0; ; j++) { if (j == trimcharsLength) { return(StringSlice.Prepare(this.str, i, end - i)); } if (this.str[i] == trimchars[j]) { break; } } } return(StringSlice.Prepare(this.str, this.length, this.length)); }
public static StringSlice SliceNextPart(ref StringSlice text) { StringSlice s = text.TrimStart(MyWhitespace); if (s.Length > 0) { if (s[0] == '(' || s[0] == ')' || s[0] == ',' || s[0] == ';') { StringSlice result = s.Substring(0, 1); text = s.Substring(1); return(result); } if (s[0] == '\'') { bool prevsquot = false; for (int i = 1; ; i++) { if (i >= s.Length) { if (prevsquot) { StringSlice result = s; text = StringSlice.Prepare(); return(result); } throw new Exception("Expected terminating single quote: " + s); } if (s[i] == '\'') { if (prevsquot) { prevsquot = false; } else { prevsquot = true; } } else if (prevsquot) { if (s[i] == ' ') { StringSlice result = s.Substring(0, i); text = s.Substring(i + 1); return(result); } else // Text directly after. { StringSlice result = s.Substring(0, i); text = s.Substring(i); return(result); } } } } } for (int i = 0; ; i++) { if (i >= s.Length) { StringSlice result = s; text = StringSlice.Prepare(); return(result); } if (char.IsWhiteSpace(s[i])) { StringSlice result = s.Substring(0, i); text = s.Substring(i + 1); return(result); } if (!char.IsLetterOrDigit(s[i]) && '_' != s[i] && '.' != s[i]) { if (i > 0) { StringSlice result = s.Substring(0, i); text = s.Substring(i); return(result); } { i++; // Return this symbol. StringSlice result = s.Substring(0, i); text = s.Substring(i); return(result); } } } }
public static StringSlice Concat(StringSlice ssA, string sB) { return(StringSlice.Prepare(ssA.ToString() + sB)); }
public StringSlice Substring(int startIndex, int length) { return(StringSlice.Prepare(this, startIndex, length)); }
public StringSlice Substring(int startIndex) { return(StringSlice.Prepare(this, startIndex, this.Length - startIndex)); }