/// <summary> /// an Infrastructure element is braced by <? .... ?> /// </summary> /// <param name="InBx"></param> /// <returns></returns> private XmlUnit CrackUnits_ScanInfrastructureUnit(int InBx) { XmlUnit unit = null; Scanner.ScanCharResults res; BoundedString boundedStream = new BoundedString(mStream); // scan for the end of the unit. ( there should be a > before an < ) res = Scanner.ScanEqualAny_BypassQuoted( boundedStream, InBx + 1, new char[] { '>', '<' }, QuoteEncapsulation.Double); if ((res.ResultPos == -1) || (res.ResultChar == '<')) { ThrowIncorrectlyFormedXmlException(InBx); } // "?" within the angle brackets. else if ((boundedStream[InBx + 1] != '?') || (boundedStream[res.ResultPos - 1] != '?')) { ThrowIncorrectlyFormedXmlException(InBx); } // setup the XmlUnit. else { unit = new XmlUnit(); unit.UnitCode = XmlUnitCode.InfraStructure; unit.Bx = InBx; unit.Ex = res.ResultPos; unit.UnitValue = boundedStream.Substring(unit.Bx, unit.Lx); } return(unit); }
public ScanPattern FindPatternAtSubstring( BoundedString InString, int InStringIx) { ScanPattern foundPat = null; if (InString.IsOutsideBounds(InStringIx) == false) { foundPat = FindPatternAtSubstring( InString.String, InStringIx, InString.Ex); } return(foundPat); }
public Tuple <ScanPattern, int> FindPatternAtSubstring( BoundedString InString, int InStringIx) { ScanPattern foundPat = null; int foundMatchLx = 0; if (InString.IsOutsideBounds(InStringIx) == false) { var rv = MatchPatternsAtStringLocation(InString.String, InStringIx, InString.Ex); foundPat = rv.Item1; foundMatchLx = rv.Item2; } return(new Tuple <ScanPattern, int>(foundPat, foundMatchLx)); }
/// <summary> /// The WordCursor locates the named part of a named=value pair. /// Advance to and return the WordCursor of the value part. /// </summary> /// <param name="InBoundedString"></param> /// <param name="InCsr"></param> /// <returns></returns> private static WordCursor ScanOpenUnit_Attribute_GetValue( BoundedString InBoundedString, WordCursor InCsr) { if (InCsr.Word == null) { return(null); } else if (InCsr.DelimValue != "=") { return(null); } // scan to the value part of the attribute. WordCursor nxCsr = Scanner.ScanNextWord(InBoundedString, InCsr); // no value to scan to. the caller should handle this as a // mal formed xml error. if (nxCsr.IsEndOfString == true) { return(null); } else if (nxCsr.Word == null) { return(null); } // got a word. is an attribute value as long as the delimeter // is legit. else if (nxCsr.DelimClass == DelimClassification.Whitespace) { return(nxCsr); } else if (nxCsr.DelimClass == DelimClassification.EndOfString) { return(nxCsr); } else if (nxCsr.DelimValue == "/") { return(nxCsr); } // likely the wrong type of delimiter. return null so the caller // can signal malformed xml error. else { return(null); } }
public bool Match(BoundedString Text, int Ix) { bool rv = false; if (Text.IsOutsideBounds(Ix, this.PatternValue.Length) == true) { rv = false; } else if (mLeadChar != Text[Ix]) { rv = false; } else if (this.PatternValue == Text.Substring(Ix, this.PatternValue.Length)) { rv = true; } else { rv = false; } return(rv); }
XmlUnit CrackUnits_ScanOpenUnit(int InBx) { Scanner.ScanCharResults res; XmlUnit unit = new XmlUnit(); unit.UnitCode = XmlUnitCode.Open; WordCursor nxWord = null; BoundedString boundedStream = new BoundedString(mStream); // unit starts with "<" if (boundedStream[InBx] != '<') { ThrowIncorrectlyFormedXmlException(InBx); } unit.Bx = InBx; // scan for the end of the unit. ( there should be a > before an < ) res = Scanner.ScanEqualAny_BypassQuoted( boundedStream, InBx + 1, new char[] { '>', '<' }, QuoteEncapsulation.Double); if ((res.ResultPos == -1) || (res.ResultChar == '<')) { ThrowIncorrectlyFormedXmlException(InBx); } else { unit.Ex = res.ResultPos; } // setup to step from word to word in the unit. boundedStream = new BoundedString(mStream, InBx + 1, res.ResultPos - 1); TextTraits traits = new TextTraits(); traits.OpenNamedBracedPatterns.Clear( ); traits.DividerPatterns.Add("/", "=", DelimClassification.DividerSymbol); traits.WhitespacePatterns.AddDistinct( Environment.NewLine, DelimClassification.Whitespace); // isolate the words of the open unit. WordCursor csr = Scanner.ScanFirstWord(boundedStream, traits); while (true) { if (csr.IsEndOfString == true) { break; } // the unit name if (ScanOpenUnit_CursorAtUnitName(csr) == true) { if (unit.NameWord != null) { ThrowIncorrectlyFormedXmlException(InBx); // already have a unit name } else { unit.NameWord = csr; } } // no word. just the ending "/". ( handle a little later. ) else if ((csr.Word == null) && (csr.DelimValue == "/")) { } else if (csr.Word == null) { ThrowIncorrectlyFormedXmlException(InBx); } // handle as an element attribute ( a named value pair ) else { nxWord = ScanOpenUnit_Attribute_GetValue(boundedStream, csr); if (nxWord != null) { // note: attributes values are stored in their xml encoded // state. unit.AddAttribute(csr, nxWord); csr = nxWord; } else { ThrowIncorrectlyFormedXmlException(InBx); } } // process the "/" delimeter. ( must be the end of the OpenUnit ) if (csr.DelimValue == "/") { WordCursor nx = Scanner.ScanNextWord(boundedStream, csr); if (nx.IsEndOfString == true) { unit.UnitCode = XmlUnitCode.Single; break; } else { ThrowIncorrectlyFormedXmlException(InBx); } } csr = Scanner.ScanNextWord(boundedStream, csr); } return(unit); }
private XmlUnit CrackUnits_ScanCloseUnit(int InBx) { Scanner.ScanCharResults res; XmlUnit unit = new XmlUnit(); unit.UnitCode = XmlUnitCode.Close; WordCursor csr = null; BoundedString boundedStream = new BoundedString(mStream); // unit starts with "<" if (boundedStream[InBx] != '<') { ThrowIncorrectlyFormedXmlException(InBx); } unit.Bx = InBx; // scan for the end of the unit. ( there should be a > before an < ) res = Scanner.ScanEqualAny_BypassQuoted( boundedStream, InBx + 1, new char[] { '>', '<' }, QuoteEncapsulation.Double); if ((res.ResultPos == -1) || (res.ResultChar == '<')) { ThrowIncorrectlyFormedXmlException(InBx); } else { unit.Ex = res.ResultPos; } // setup to step from word to word in the close unit. boundedStream = new BoundedString(mStream, InBx + 1, res.ResultPos - 1); TextTraits traits = new TextTraits(); traits.OpenNamedBracedPatterns.Clear(); traits.DividerPatterns.Add("/", "=", DelimClassification.DividerSymbol); // first word must be an empty word w/ "/" delim. csr = Scanner.ScanFirstWord(boundedStream, traits); if ((csr.IsDelimOnly) && (csr.DelimValue == "/")) { } else { ThrowIncorrectlyFormedXmlException(InBx); } // next is a name with end of string delim. csr = Scanner.ScanNextWord(boundedStream, csr); if ((csr.IsEndOfString) || (csr.DelimClass == DelimClassification.EndOfString)) { } else { ThrowIncorrectlyFormedXmlException(InBx); } // if there is an element name, store it. if (csr.Word != null) { unit.NameWord = csr; } return(unit); }