// ------------------ ScanWord_IsolatedWord_CommentToEnd ------------------- private static ScanPatternResults ScanWord_IsolateWord_CommentToEnd( BoundedString InBoundedString, int InWordBx, ref WordCursor InOutResults, TextTraits InTraits) { string wordText; ScanPatternResults spr = null; // look for end of comment. ( either end of line or end of string ) int fx = Scanner.ScanEqual(InBoundedString, InWordBx, Environment.NewLine).ResultPos; if (fx >= 0) { int Lx = fx - InWordBx; wordText = InBoundedString.Substring(InWordBx, Lx); ScanPattern pat = InTraits.NonWordPatterns.FindPatternAtSubstring(InBoundedString, fx); spr = new ScanPatternResults(fx, pat); } else { wordText = InBoundedString.Substring(InWordBx); spr = new ScanPatternResults(-1); } // store info on the word found in the return WordCursor argument. InOutResults.SetWord(wordText, WordClassification.CommentToEnd, InWordBx); // return value of method contains info on the word delim. return(spr); }
public static bool ShouldQuoteValue(string InValue) { int Fx = Scanner.ScanEqual(InValue, new char[] { ' ', '\t', '\"', ',', '(' }).a; if (Fx >= 0) { return(true); } else { return(false); } }
/// <summary> /// Scan in string for any of the pattern characters. /// </summary> /// <param name="InValue"></param> /// <param name="InBx"></param> /// <param name="InPatternChars"></param> /// <returns></returns> public static int IndexOf(string InValue, int InBx, char[] InPatternChars) { return(Scanner.ScanEqual(InValue, InBx, InPatternChars).a); }
/// <summary> /// Examine the string for its WordClassification content. /// </summary> /// <param name="InWord"></param> /// <param name="InTraits"></param> /// <returns></returns> public static CharObjectPair CalcWordClassification( string InWord, TextTraits InTraits) { int Fx = 0, Ix = 0; WordClassification wc = WordClassification.None; char braceChar = ' '; char ch1 = AcCommon.PullChar(InWord, 0); int Ex = InWord.Length - 1; // is quoted. the word runs to the closing quote. if (Scanner.IsOpenQuoteChar(ch1) == true) { Ix = Scanner.ScanCloseQuote(InWord, 0, InTraits.QuoteEncapsulation); if (Ix == Ex) { wc = WordClassification.Quoted; } else { wc = WordClassification.MixedText; } } // check if the string is a Braced or NameBraced word. if (wc == WordClassification.None) { char[] combo = AcCommon.Concat(InTraits.DelimChars, InTraits.BraceChars); Scanner.ScanCharResults results = Scanner.ScanEqual(InWord, 0, combo); Fx = results.ResultPos; ch1 = results.ResultChar; // found a brace char if ((InTraits.IsOpenBraceChar(ch1) == true) && (InTraits.IsDelimChar(ch1) == false)) { Ix = Scanner.ScanCloseBrace(InWord, Fx); if (Ix == Ex) { braceChar = ch1; if (Fx == 0) { wc = WordClassification.Braced; } else { wc = WordClassification.NameBraced; } } } } // word is all delimeter. if (wc == WordClassification.None) { Fx = Scanner.ScanNotEqual(InWord, 0, InTraits.DelimChars).a; if (Fx >= 0) { wc = WordClassification.Delimeter; } } // check if a numeric string. if (wc == WordClassification.None) { char[] digitChars = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '+', '-' }; Fx = Scanner.ScanNotEqual(InWord, 0, digitChars).a; if (Fx == -1) { wc = WordClassification.Numeric; try { double vx = double.Parse(InWord); } catch (Exception) { wc = WordClassification.None; } } } // any delim chars in the string. if not, the string is a name. otherwise, it is // mixed. if (wc == WordClassification.None) { Fx = Scanner.ScanEqual(InWord, 0, InTraits.DelimChars).a; if (Fx == -1) { wc = WordClassification.Name; } else { wc = WordClassification.MixedText; } } return(new CharObjectPair(braceChar, wc)); }