public override IEnumerable<TokenResult> Parse(string input, string UserId) { int bias = 0; var results = new List<TokenResult>(); string test = input; while (test.IndexOf('"') > -1) { int index = test.IndexOf('"'); int endIndex = test.IndexOf('"', index + 1); if (endIndex == (-1)) { break; } var result = new TokenResult { Length = (endIndex - 1) - (index + 1), Start = index + bias, TokenType = this.GetType().ToString(), Value = test.Substring(index + 1, endIndex - (index + 1)), Token = new TokenQuotedPhrase { Value = test.Substring(index + 1, endIndex - (index + 1)) } }; results.Add(result); int origLength = test.Length; test = test.Substring(endIndex + 1); bias += (origLength - test.Length); } return results; }
public virtual IEnumerable<TokenResult> Parse(string input, string userId) { var results = new List<TokenResult>(); var quotePoints = GetQuotePoints(input); foreach (var word in this.Words) { string test = input; int index, pos; index = test.IndexOf(word); // While matched while (index >= 0) { pos = index + word.Length; if (pos <= test.Length) { bool add = true; if (pos < test.Length) { if (test[pos] != ' ') { add = false; } } if (add) { var result = new TokenResult { Length = word.Length, Start = index, TokenType = this.GetType().ToString(), Value = word, Token = ((Token)Activator.CreateInstance(this.GetType())) }; results.Add(result); result.Token.Value = word; index += word.Length; } } // Find next match index = test.IndexOf(" " + word, pos); // If index is >= 0 if (index >= 0) { // Skip the space index++; } } } return results; }
public override IEnumerable<TokenResult> Parse(string input, string UserId) { var results = new List<TokenResult>(); string testString = input; bool isInQuote = false; string[] words = input.Split(' '); foreach (var word in words) { if (word.IndexOf("\"") > -1) { isInQuote = !isInQuote; } if (isInQuote) { continue; } double dblTest; if (double.TryParse(word.Replace(",", "").Replace("%", ""), out dblTest)) { int intTest; if (int.TryParse(word.Replace(",", "").Replace("%", ""), out intTest)) { var result = new TokenResult { Length = word.Length, Start = testString.IndexOf(word), TokenType = typeof (TokenInt).ToString(), Value = intTest, Token = new TokenInt { Value = intTest } }; results.Add(result); } } } return results; }
public override IEnumerable<TokenResult> Parse(string input, string UserId) { var results = new List<TokenResult>(); string testString = input; string[] words = input.Split(' '); foreach (var word in words) { double dblTest; if (double.TryParse(word.Replace(",", "").Replace("%", ""), out dblTest)) { long longTest; if (long.TryParse(word.Replace(",", "").Replace("%", ""), out longTest)) { var result = new TokenResult { Length = word.Length, Start = testString.IndexOf(word), TokenType = typeof(TokenLong).ToString(), Value = longTest, Token = new TokenLong { Value = longTest } }; results.Add(result); } } } return results; }