System.Xml.TernaryTreeReadOnly.FindCaseInsensitiveString C# (CSharp) Method

FindCaseInsensitiveString() public method

public FindCaseInsensitiveString ( String stringToFind ) : byte
stringToFind String
return byte
        public byte FindCaseInsensitiveString(String stringToFind) {

            //Debug.Assert(wszFind != null && wszFind.Length != 0);

            int stringPos = 0, nodePos = 0;
            int charToFind, charInTheTree;
            byte [] node = nodeBuffer;

            charToFind = stringToFind[stringPos];

            if (charToFind > 'z') return 0;                    // Ternary tree only stores ASCII strings
            if (charToFind >= 'a') charToFind -= ('a' - 'A');     // Normalize to upper case

            while (true) {
                int pos = nodePos * 4;

                charInTheTree = node[pos + (int)TernaryTreeByte.characterByte];
                //Console.WriteLine("charToFind: {0},charInTheTree: {1}, nodePos: {2}", charToFind, charInTheTree, nodePos);

                if (charToFind < charInTheTree) {

                    // If input character is less than the tree character, take the left branch
                    if (node[pos + (int)TernaryTreeByte.leftTree] == 0x0) {
                        break;
                    }
                    nodePos = nodePos + node[pos + (int)TernaryTreeByte.leftTree];

                } else if (charToFind > charInTheTree) {
                    // If input character is greater than the tree character, take the right branch
                    if (node[pos + (int)TernaryTreeByte.rightTree] == 0x0)
                        break;
                    nodePos = nodePos + node[pos + (int)TernaryTreeByte.rightTree];

                } else {
                    // If input character is equal to the tree character, take the equal branch
                    if (charToFind == 0)
                        return node[pos + (int)TernaryTreeByte.data];

                    // The offset for the equal branch is always one
                    ++nodePos;

                    // Move to the next input character
                    ++stringPos;
                    if (stringPos == stringToFind.Length) {
                        charToFind = 0;
                    }
                    else {
                        charToFind = stringToFind[stringPos];
                        if (charToFind > 'z') return 0;                     // Ternary tree only stores ASCII strings
                        if (charToFind >= 'a') charToFind -= ('a' - 'A');   // Normalize to upper case
                    }
                }
            }

            // Return default
            return 0;
        }
    }

Usage Example

示例#1
0
        // For the HTML element, it should call this method with ns and prefix as String.Empty
        public override void WriteStartElement(string prefix, string localName, string ns)
        {
            Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);

            elementScope.Push((byte)currentElementProperties);

            if (ns.Length == 0)
            {
                Debug.Assert(prefix.Length == 0);


                currentElementProperties = (ElementProperties)elementPropertySearch.FindCaseInsensitiveString(localName);
                base.bufBytes[bufPos++]  = (byte)'<';
                base.RawText(localName);
                base.attrEndPos = bufPos;
            }
            else
            {
                // Since the HAS_NS has no impact to the ElementTextBlock behavior,
                // we don't need to push it into the stack.
                currentElementProperties = ElementProperties.HAS_NS;
                base.WriteStartElement(prefix, localName, ns);
            }
        }