/// <summary> /// Position the navigator on the attribute with the specified name and return true. If no matching /// attribute can be found, return false. Don't assume the name parts are atomized with respect /// to this document. /// </summary> public override bool MoveToAttribute(string localName, string namespaceURI) { XPathNode[] page = _pageCurrent; int idx = _idxCurrent; if ((object)localName != (object)_atomizedLocalName) _atomizedLocalName = (localName != null) ? NameTable.Get(localName) : null; if (XPathNodeHelper.GetAttribute(ref _pageCurrent, ref _idxCurrent, _atomizedLocalName, namespaceURI)) { // Save element parent in order to make node-order comparison simpler _pageParent = page; _idxParent = idx; return true; } return false; }
/// <summary> /// This method compiles an XPath string, if not already saved. /// Otherwise it returns the available XPath compilation. /// </summary> /// <param name="xPath">The XPath string</param> /// <returns>A compiled XPath expression</returns> public override XPathExpression?Compile(string xPath) { XPathExpression?expr; // Compare pointers instead of literal values if (ReferenceEquals(xPath, NameTable.Get(xPath))) { return(CompiledExpressions[xPath]); } NameTable.Add(xPath); expr = XPathQueryManager.Compile(xPath); if (expr != null) { CompiledExpressions.Add(xPath, expr); } return(expr); }
public static void RespectManuallyAddedReference() { // Test depends that the string used here is also automatically added to XmlDocument XmlNameTable string targetStr = "#DoCument".ToLowerInvariant(); // Avoid interning var d = new XmlDocument(); string defaultXmlDocumentTargetStr = d.NameTable.Get(targetStr); Assert.NotSame(targetStr, defaultXmlDocumentTargetStr); Assert.Equal(targetStr, defaultXmlDocumentTargetStr); // Create a NameTable to be shared and ensure that it is using the same reference as the test var nt = new NameTable(); nt.Add(targetStr); Assert.Same(targetStr, nt.Get(targetStr)); // The one added earlier should be the actual reference d = new XmlDocument(nt); Assert.Same(targetStr, d.Name); }
/// <summary> /// Position the navigator on the attribute with the specified name and return true. If no matching /// attribute can be found, return false. Don't assume the name parts are atomized with respect /// to this document. /// </summary> public override bool MoveToAttribute(string localName, string namespaceURI) { XPathNode[] page = this.pageCurrent; int idx = this.idxCurrent; if ((object)localName != (object)this.atomizedLocalName) { this.atomizedLocalName = (localName != null) ? NameTable.Get(localName) : null; } if (XPathNodeHelper.GetAttribute(ref this.pageCurrent, ref this.idxCurrent, this.atomizedLocalName, namespaceURI)) { // Save element parent in order to make node-order comparison simpler this.pageParent = page; this.idxParent = idx; return(true); } return(false); }
public override string Get(string array) { return(_nametable.Get(array)); }
public override string Get(string array) { return(_nt.Get(array)); }
virtual bool MoveToFollowing(string localName, string namespaceURI, XPathNavigator end) { if (localName == null) { throw new ArgumentNullException("localName"); } if (namespaceURI == null) { throw new ArgumentNullException("namespaceURI"); } localName = NameTable.Get(localName); if (localName == null) { return(false); } namespaceURI = NameTable.Get(namespaceURI); if (namespaceURI == null) { return(false); } XPathNavigator nav = Clone(); switch (nav.NodeType) { case XPathNodeType.Attribute: case XPathNodeType.Namespace: nav.MoveToParent(); break; } do { if (!nav.MoveToFirstChild()) { do { if (!nav.MoveToNext()) { if (!nav.MoveToParent()) { return(false); } } else { break; } } while (true); } if (end != null && end.IsSamePosition(nav)) { return(false); } if (object.ReferenceEquals(localName, nav.LocalName) && object.ReferenceEquals(namespaceURI, nav.NamespaceURI)) { MoveTo(nav); return(true); } } while (true); }
public void Get1() { string get1 = "get1"; string testGet = table.Add(get1); Assert.AreEqual("get1", testGet, "#1"); Assert.AreEqual(testGet, table.Get(get1), "#2"); Assert.AreSame(get1, testGet, "#3"); testGet = table.Get(""); Assert.AreEqual(string.Empty, testGet, "#1"); Assert.AreSame(string.Empty, testGet, "#2"); }
private string nt(string val) { return(_nameTable.Get(val)); }
/// <summary> /// Same as <see cref="XmlNamespaceManager"/>. /// </summary> public override string LookupPrefix(string uri) { var key = NameTable.Get(uri); return(key == null ? null : base.LookupPrefix(key)); }
/// <summary> /// Same as <see cref="XmlNamespaceManager"/>. /// </summary> public override string LookupNamespace(string prefix) { var key = NameTable.Get(prefix); return(key == null ? null : base.LookupNamespace(key)); }
// Test adding strings and checking that object equality // works as string equality on the results. public void TestNameTableAdd() { NameTable table = new NameTable(); String value, value2, result; // Add an initial string, which should be added directly. value = "Hello"; result = table.Add(value); if(!ReferenceEquals(value, result)) { Fail("initial add"); } // Create a string that has the same contents as "value", // but which will not have the same object reference. value2 = String.Concat("Hel", "lo"); if(ReferenceEquals(value, value2)) { Fail("concat construction failed - runtime engine error"); } // Look up the initial string and validate it. if(!ReferenceEquals(value, table.Get(value))) { Fail("lookup initial did not give the initial string"); } if(!ReferenceEquals(value, table.Get(value2))) { Fail("lookup initial on same contents gave wrong result"); } // Add another string and validate against the first. value2 = table.Add("Goodbye"); if(ReferenceEquals(value2, value)) { Fail("Hello == Goodbye!"); } if(!ReferenceEquals(value, table.Get(value))) { Fail("initial string changed after adding another string"); } if(!ReferenceEquals(value2, table.Get("Goodbye"))) { Fail("second string could not be found on lookup"); } // Check that the empty string is added as "String.Empty". if(!ReferenceEquals(String.Empty, table.Add(""))) { Fail("empty string not added as String.Empty"); } // Add and get strings using an array. char[] array = new char [10]; array[3] = 'H'; array[4] = 'i'; value2 = table.Add(array, 3, 2); if(!ReferenceEquals(value2, table.Get("Hi"))) { Fail("array add on Hi failed"); } if(!ReferenceEquals(value2, table.Get(array, 3, 2))) { Fail("array get on Hi failed"); } array[3] = 'H'; array[4] = 'e'; array[5] = 'l'; array[6] = 'l'; array[7] = 'o'; value2 = table.Add(array, 3, 5); if(!ReferenceEquals(value, value2)) { Fail("array add on Hello gave incorrect value"); } if(!ReferenceEquals(value, table.Get(array, 3, 5))) { Fail("array add on Hello gave incorrect value"); } if(!ReferenceEquals(String.Empty, table.Add(array, 10, 0))) { Fail("array add on \"\" gave incorrect value"); } }
// Test the exceptions that may be thrown by various methods. public void TestNameTableExceptions() { NameTable table = new NameTable(); char[] array = new char [10]; try { table.Add(null); Fail("Add(null) should throw an exception"); } catch(ArgumentNullException) { // Success } try { table.Get(null); Fail("Get(null) should throw an exception"); } catch(ArgumentNullException) { // Success } try { table.Add(null, 0, 0); Fail("Add(null, 0, 0) should throw an exception"); } catch(ArgumentNullException) { // Success } try { table.Get(null, 0, 0); Fail("Get(null, 0, 0) should throw an exception"); } catch(ArgumentNullException) { // Success } try { table.Add(array, 0, -1); Fail("Add(array, 0, -1) should throw an exception"); } catch(ArgumentOutOfRangeException) { // Success } try { table.Get(array, 0, -1); Fail("Get(array, 0, -1) should throw an exception"); } catch(ArgumentOutOfRangeException) { // Success } try { table.Add(array, -1, 3); Fail("Add(array, -1, 3) should throw an exception"); } catch(IndexOutOfRangeException) { // Success } try { table.Get(array, -1, 3); Fail("Get(array, -1, 3) should throw an exception"); } catch(IndexOutOfRangeException) { // Success } try { table.Add(array, 0, 11); Fail("Add(array, 0, 11) should throw an exception"); } catch(IndexOutOfRangeException) { // Success } try { table.Get(array, 0, 11); Fail("Get(array, 0, 11) should throw an exception"); } catch(IndexOutOfRangeException) { // Success } }
public override string Get(char[] array, int offset, int length) => _nameTable.Get(array, offset, length);
// Test adding strings and checking that object equality // works as string equality on the results. public void TestNameTableAdd() { NameTable table = new NameTable(); String value, value2, result; // Add an initial string, which should be added directly. value = "Hello"; result = table.Add(value); if (!ReferenceEquals(value, result)) { Fail("initial add"); } // Create a string that has the same contents as "value", // but which will not have the same object reference. value2 = String.Concat("Hel", "lo"); if (ReferenceEquals(value, value2)) { Fail("concat construction failed - runtime engine error"); } // Look up the initial string and validate it. if (!ReferenceEquals(value, table.Get(value))) { Fail("lookup initial did not give the initial string"); } if (!ReferenceEquals(value, table.Get(value2))) { Fail("lookup initial on same contents gave wrong result"); } // Add another string and validate against the first. value2 = table.Add("Goodbye"); if (ReferenceEquals(value2, value)) { Fail("Hello == Goodbye!"); } if (!ReferenceEquals(value, table.Get(value))) { Fail("initial string changed after adding another string"); } if (!ReferenceEquals(value2, table.Get("Goodbye"))) { Fail("second string could not be found on lookup"); } // Check that the empty string is added as "String.Empty". if (!ReferenceEquals(String.Empty, table.Add(""))) { Fail("empty string not added as String.Empty"); } // Add and get strings using an array. char[] array = new char [10]; array[3] = 'H'; array[4] = 'i'; value2 = table.Add(array, 3, 2); if (!ReferenceEquals(value2, table.Get("Hi"))) { Fail("array add on Hi failed"); } if (!ReferenceEquals(value2, table.Get(array, 3, 2))) { Fail("array get on Hi failed"); } array[3] = 'H'; array[4] = 'e'; array[5] = 'l'; array[6] = 'l'; array[7] = 'o'; value2 = table.Add(array, 3, 5); if (!ReferenceEquals(value, value2)) { Fail("array add on Hello gave incorrect value"); } if (!ReferenceEquals(value, table.Get(array, 3, 5))) { Fail("array add on Hello gave incorrect value"); } if (!ReferenceEquals(String.Empty, table.Add(array, 10, 0))) { Fail("array add on \"\" gave incorrect value"); } }
// Test the exceptions that may be thrown by various methods. public void TestNameTableExceptions() { NameTable table = new NameTable(); char[] array = new char [10]; try { table.Add(null); Fail("Add(null) should throw an exception"); } catch (ArgumentNullException) { // Success } try { table.Get(null); Fail("Get(null) should throw an exception"); } catch (ArgumentNullException) { // Success } try { table.Add(null, 0, 0); Fail("Add(null, 0, 0) should throw an exception"); } catch (ArgumentNullException) { // Success } try { table.Get(null, 0, 0); Fail("Get(null, 0, 0) should throw an exception"); } catch (ArgumentNullException) { // Success } try { table.Add(array, 0, -1); Fail("Add(array, 0, -1) should throw an exception"); } catch (ArgumentOutOfRangeException) { // Success } try { table.Get(array, 0, -1); Fail("Get(array, 0, -1) should throw an exception"); } catch (ArgumentOutOfRangeException) { // Success } try { table.Add(array, -1, 3); Fail("Add(array, -1, 3) should throw an exception"); } catch (IndexOutOfRangeException) { // Success } try { table.Get(array, -1, 3); Fail("Get(array, -1, 3) should throw an exception"); } catch (IndexOutOfRangeException) { // Success } try { table.Add(array, 0, 11); Fail("Add(array, 0, 11) should throw an exception"); } catch (IndexOutOfRangeException) { // Success } try { table.Get(array, 0, 11); Fail("Get(array, 0, 11) should throw an exception"); } catch (IndexOutOfRangeException) { // Success } }