/// <summary> /// calc if the char at location in string is a word char or not ( is not a /// NonWordChar ) /// </summary> /// <param name="InBoundedString"></param> /// <param name="InIx"></param> /// <returns></returns> public bool IsWordChar( BoundedString InBoundedString, int InIx) { bool isWordChar = false; if (InBoundedString.IsOutsideBounds(InIx)) { isWordChar = false; } else { var rv = NonWordPatterns.FindPatternAtSubstring( InBoundedString, InIx); var pat = rv.Item1; var matchLx = rv.Item2; if (pat == null) { isWordChar = true; } else { isWordChar = false; } } return(isWordChar); }
/// <summary> /// return the NonWord info of path sep char which is classified as being a /// path part delimiter ( it could be a division expression symbol ) /// </summary> /// <param name="InBoundedString"></param> /// <param name="InIx"></param> /// <returns></returns> public ScanPattern GetPathPartDelim(BoundedString InBoundedString, int InIx) { ScanPattern pat = null; int matchLx = 0; if (InBoundedString.IsOutsideBounds(InIx)) { } else if (IsPathSepChar(InBoundedString[InIx]) == true) { var rv = NonWordPatterns.MatchPatternsAtStringLocation( InBoundedString.String, InIx, InBoundedString.Ex); pat = rv.Item1; matchLx = rv.Item2; // the nonword is a path sep char. but is it a pathPart delim? // It is if there is a word char before or after the path sep char. // ex: /abc/efg vs. a = b / c ; if ((IsWordChar(InBoundedString, InIx - 1) == false) && (IsWordChar(InBoundedString, InIx + 1) == false)) { pat = null; } } return(pat); }
/// <summary> /// calc if the char at location in string is a word char or not ( is not a /// NonWordChar ) /// </summary> /// <param name="InBoundedString"></param> /// <param name="InIx"></param> /// <returns></returns> public bool IsWordChar( BoundedString InBoundedString, int InIx) { bool isWordChar = false; if (InBoundedString.IsOutsideBounds(InIx)) { isWordChar = false; } else { ScanPattern pat = NonWordPatterns.FindPatternAtSubstring( InBoundedString, InIx); if (pat == null) { isWordChar = true; } else { isWordChar = false; } } return(isWordChar); }
/// <summary> /// calc if the /// </summary> /// <param name="InBoundedString"></param> /// <param name="InBx"></param> /// <returns></returns> public bool IsPathPartDelim(BoundedString InBoundedString, int InIx) { if (InBoundedString.IsOutsideBounds(InIx)) { return(false); } else if (IsPathSepChar(InBoundedString[InIx]) == false) { return(false); } else if (IsWordChar(InBoundedString, InIx - 1) == true) { return(true); } else if (IsWordChar(InBoundedString, InIx + 1) == true) { return(true); } else { return(false); } }
/// <summary> /// return the NonWord info of path sep char which is classified as being a /// path part delimiter ( it could be a division expression symbol ) /// </summary> /// <param name="InBoundedString"></param> /// <param name="InIx"></param> /// <returns></returns> public ScanPattern GetPathPartDelim(BoundedString InBoundedString, int InIx) { ScanPattern pat = null; if (InBoundedString.IsOutsideBounds(InIx)) { } else if (IsPathSepChar(InBoundedString[InIx]) == true) { pat = NonWordPatterns.FindPatternAtSubstring( InBoundedString.String, InIx, InBoundedString.Ex); // the nonword is a path sep char. but is it a pathPart delim? // It is if there is a word char before or after the path sep char. // ex: /abc/efg vs. a = b / c ; if ((IsWordChar(InBoundedString, InIx - 1) == false) && (IsWordChar(InBoundedString, InIx + 1) == false)) { pat = null; } } return(pat); }
// -------------------- ScanWord_IsolateWord --------------------------- // We have a word starting at InBx. Scan to the end of the word. // Returns the word in the InOutResults parm. // Returns the word delim in the return argument. private static ScanPatternResults ScanWord_IsolateWord( BoundedString InBoundedString, int InBx, ref WordCursor InOutResults, TextTraits Traits) { int Bx, Ix, Lx; string wordText; ScanPatternResults spr = null; Bx = InBx; char ch1 = InBoundedString.String[Bx]; // is start of a verbatim string literal if ((Traits.VerbatimLiteralPattern != null) && (Traits.VerbatimLiteralPattern.Match(InBoundedString, Bx))) { } // is quoted. the word runs to the closing quote. else if (IsOpenQuoteChar(ch1) == true) { Ix = ScanCloseQuote(InBoundedString.String, Bx, Traits.QuoteEncapsulation); if ((Ix == -1) || (Ix > InBoundedString.Ex)) { throw (new ApplicationException( "Closing quote not found starting at position " + Bx.ToString() + " in " + InBoundedString.String)); } Lx = Ix - Bx + 1; wordText = InBoundedString.String.Substring(Bx, Lx); InOutResults.SetWord(wordText, WordClassification.Quoted, Bx); // setup the non word which follows the closing quote. Bx = Ix + 1; if (InBoundedString.IsOutsideBounds(Bx)) { spr = new ScanPatternResults(-1); } else { // the char that follows the closing quote must be a delim spr = ScanEqualAny(InBoundedString, Bx, Traits.NonWordPatterns); if (spr.FoundPos != Bx) { throw new ApplicationException( "invalid char follows close quote at pos " + Ix.ToString() + " in " + Stringer.Head(InBoundedString.String, 80)); } } } else { // Scan the string for any of the non word patterns spcfd in Traits. DelimClassification sprdc = DelimClassification.None; spr = ScanEqualAny(InBoundedString, Bx, Traits.NonWordPatterns); if (spr.IsNotFound == false) { sprdc = spr.FoundPat.DelimClassification; } // a quote character within the name. this is an error. if (sprdc == DelimClassification.Quote) { throw new ApplicationException( "quote character immed follows name character at position " + spr.FoundPos.ToString() + " in " + InBoundedString.String); } // no delim found. all word to the end of the string. else if (spr.IsNotFound) { wordText = InBoundedString.Substring(Bx); InOutResults.SetWord(wordText, WordClassification.Identifier, InBx); } // found an open named brace char else if (sprdc == DelimClassification.OpenNamedBraced) { ScanWord_IsolateWord_Braced( InBoundedString, Bx, spr, ref InOutResults, Traits); } // delim is same position as the word. so there is no word, only a delim. else if (spr.FoundPos == InBx) { if (Scanner.IsOpenBraced(sprdc)) { InOutResults.SetWord( spr.FoundPat.PatternValue, WordClassification.OpenContentBraced, Bx, spr.FoundPat.LeadChar); } // start of CommentToEnd comment. This is a word, not a delim. Find the // end of the comment and set the delim to that end position. else if (sprdc == DelimClassification.CommentToEnd) { spr = ScanWord_IsolateWord_CommentToEnd( InBoundedString, spr.FoundPos, ref InOutResults, Traits); } else { InOutResults.SetNullWord(); } } // we have a word that ends with a delim. else { Lx = spr.FoundPos - InBx; wordText = InBoundedString.Substring(InBx, Lx); InOutResults.SetWord(wordText, WordClassification.Identifier, InBx); } } // return ScanPatternResults of the delim that ends the word. return(spr); }