internal static bool IsProcessingInstructionName(string name)
        {
            if (name == null)
            {
                return(false);
            }

            int         nameLength  = name.Length;
            int         position    = 0;
            XmlCharType xmlCharType = XmlCharType.Instance;

            while (position < nameLength && xmlCharType.IsWhiteSpace(name[position]))
            {
                position++;
            }

            if (position >= nameLength)
            {
                return(false);
            }

            if (position < nameLength && !xmlCharType.IsStartNCNameChar(name[position]))
            {
                return(false);
            }

            while (position < nameLength && xmlCharType.IsNCNameChar(name[position]))
            {
                position++;
            }

            while (position < nameLength && xmlCharType.IsWhiteSpace(name[position]))
            {
                position++;
            }

            if (position < nameLength)
            {
                return(false);
            }

            if (nameLength == 3 &&
                (name[0] == CharX || name[0] == Charx) &&
                (name[1] == CharM || name[1] == Charm) &&
                (name[2] == CharL || name[2] == Charl)
                )
            {
                return(false);
            }

            return(true);
        }
        internal static bool IsProcessingInstructionName(string name)
        {
            if (name == null)
            {
                return(false);
            }

            int         nameLength  = name.Length;
            int         position    = 0;
            XmlCharType xmlCharType = XmlCharType.Instance;

            while (position < nameLength && xmlCharType.IsWhiteSpace(name[position]))
            {
                position++;
            }

            if (position >= nameLength)
            {
                return(false);
            }

            int len = ValidateNames.ParseNCName(name, position);

            if (len == 0)
            {
                return(false);
            }
            position += len;

            while (position < nameLength && xmlCharType.IsWhiteSpace(name[position]))
            {
                position++;
            }

            if (position < nameLength)
            {
                return(false);
            }

            if (nameLength == 3 &&
                (name[0] == CharX || name[0] == Charx) &&
                (name[1] == CharM || name[1] == Charm) &&
                (name[2] == CharL || name[2] == Charl)
                )
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
 private void SkipSpace()
 {
     while (xmlCharType.IsWhiteSpace(curChar))
     {
         NextChar();
     }
 }
        private string Normalize(XPathNodeIterator nodeIterator)
        {
            string str1;

            if (argList.Count > 0)
            {
                str1 = argList[0].Evaluate(nodeIterator).ToString();
            }
            else
            {
                str1 = nodeIterator.Current.Value;
            }
            str1 = XmlConvertEx.TrimString(str1);
            int           count       = 0;
            StringBuilder str2        = new StringBuilder();
            bool          FirstSpace  = true;
            XmlCharType   xmlCharType = XmlCharType.Instance;

            while (count < str1.Length)
            {
                if (!xmlCharType.IsWhiteSpace(str1[count]))
                {
                    FirstSpace = true;
                    str2.Append(str1[count]);
                }
                else if (FirstSpace)
                {
                    FirstSpace = false;
                    str2.Append(' ');
                }
                count++;
            }
            return(str2.ToString());
        }
Exemple #5
0
 private void SkipSpace()
 {
     while (_xmlCharType.IsWhiteSpace(this.CurrentChar) && NextChar())
     {
         ;
     }
 }
 void SkipSpace()
 {
     while (xmlCharType.IsWhiteSpace(this.CurerntChar) && NextChar())
     {
         ;
     }
 }
Exemple #7
0
 private void SkipSpace()
 {
     if (XmlCharType.IsWhiteSpace(CurrentChar))
     {
         SkipKnownSpace();
     }
 }
Exemple #8
0
        private string Normalize(XPathNodeIterator nodeIterator)
        {
            string str;

            if (this.argList.Count > 0)
            {
                str = this.argList[0].Evaluate(nodeIterator).ToString();
            }
            else
            {
                str = nodeIterator.Current.Value;
            }
            str = XmlConvert.TrimString(str);
            int           num      = 0;
            StringBuilder builder  = new StringBuilder();
            bool          flag     = true;
            XmlCharType   instance = XmlCharType.Instance;

            while (num < str.Length)
            {
                if (!instance.IsWhiteSpace(str[num]))
                {
                    flag = true;
                    builder.Append(str[num]);
                }
                else if (flag)
                {
                    flag = false;
                    builder.Append(' ');
                }
                num++;
            }
            return(builder.ToString());
        }
Exemple #9
0
 private void SkipKnownSpace()
 {
     Debug.Assert(XmlCharType.IsWhiteSpace(CurrentChar));
     while (NextChar() && XmlCharType.IsWhiteSpace(CurrentChar))
     {
         ;
     }
 }
Exemple #10
0
        private static unsafe void Decode(char *pChars, char *pCharsEndPos,
                                          byte *pBytes, byte *pBytesEndPos,
                                          ref bool hasHalfByteCached, ref byte cachedHalfByte,
                                          out int charsDecoded, out int bytesDecoded)
        {
#if DEBUG
            Debug.Assert(pCharsEndPos - pChars >= 0);
            Debug.Assert(pBytesEndPos - pBytes >= 0);
#endif

            char *      pChar       = pChars;
            byte *      pByte       = pBytes;
            XmlCharType xmlCharType = XmlCharType.Instance;
            while (pChar < pCharsEndPos && pByte < pBytesEndPos)
            {
                byte halfByte;
                char ch = *pChar++;

                if (ch >= 'a' && ch <= 'f')
                {
                    halfByte = (byte)(ch - 'a' + 10);
                }
                else if (ch >= 'A' && ch <= 'F')
                {
                    halfByte = (byte)(ch - 'A' + 10);
                }
                else if (ch >= '0' && ch <= '9')
                {
                    halfByte = (byte)(ch - '0');
                }
                else if (xmlCharType.IsWhiteSpace(ch))
                {
                    continue;
                }
                else
                {
                    throw new XmlException(SR.Xml_InvalidBinHexValue, new string(pChars, 0, (int)(pCharsEndPos - pChars)));
                }

                if (hasHalfByteCached)
                {
                    *pByte++ = (byte)((cachedHalfByte << 4) + halfByte);
                    hasHalfByteCached = false;
                }
                else
                {
                    cachedHalfByte    = halfByte;
                    hasHalfByteCached = true;
                }
            }

            bytesDecoded = (int)(pByte - pBytes);
            charsDecoded = (int)(pChar - pChars);
        }
 private static string AppendLineInfoMessage(string message, ISourceLineInfo?lineInfo)
 {
     if (lineInfo != null)
     {
         string fileName        = SourceLineInfo.GetFileName(lineInfo.Uri !);
         string lineInfoMessage = CreateMessage(SR.Xml_ErrorFilePosition, fileName, lineInfo.Start.Line.ToString(CultureInfo.InvariantCulture), lineInfo.Start.Pos.ToString(CultureInfo.InvariantCulture));
         if (lineInfoMessage != null && lineInfoMessage.Length > 0)
         {
             if (message.Length > 0 && !XmlCharType.IsWhiteSpace(message[message.Length - 1]))
             {
                 message += " ";
             }
             message += lineInfoMessage;
         }
     }
     return(message);
 }
        internal static bool IsProcessingInstructionName(string?name)
        {
            if (name == null)
            {
                return(false);
            }

            int nameLength = name.Length;
            int position   = 0;

            while (position < nameLength && XmlCharType.IsWhiteSpace(name[position]))
            {
                position++;
            }

            if (position >= nameLength)
            {
                return(false);
            }

            int len = ValidateNames.ParseNCName(name, position);

            if (len == 0)
            {
                return(false);
            }
            position += len;

            while (position < nameLength && XmlCharType.IsWhiteSpace(name[position]))
            {
                position++;
            }

            if (position < nameLength)
            {
                return(false);
            }

            if (nameLength == 3 && name.StartsWith("xml", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
Exemple #13
0
        private string Normalize(XPathNodeIterator nodeIterator)
        {
            string value;

            if (_argList.Count > 0)
            {
                value = _argList[0].Evaluate(nodeIterator).ToString() !;
            }
            else
            {
                Debug.Assert(nodeIterator.Current != null);
                value = nodeIterator.Current.Value;
            }
            int modifyPos = -1;

            char[]      chars       = value.ToCharArray();
            bool        firstSpace  = false; // Start false to trim the beginning
            XmlCharType xmlCharType = XmlCharType.Instance;

            for (int comparePos = 0; comparePos < chars.Length; comparePos++)
            {
                if (!xmlCharType.IsWhiteSpace(chars[comparePos]))
                {
                    firstSpace = true;
                    modifyPos++;
                    chars[modifyPos] = chars[comparePos];
                }
                else if (firstSpace)
                {
                    firstSpace = false;
                    modifyPos++;
                    chars[modifyPos] = ' ';
                }
            }

            // Trim end
            if (modifyPos > -1 && chars[modifyPos] == ' ')
            {
                modifyPos--;
            }

            return(new string(chars, 0, modifyPos + 1));
        }
        // Replaces \r\n, \n, \r and \t with single space (0x20) and then removes spaces
        // at the beggining and and the end of the string and replaces sequences of spaces
        // with a single space.
        public static string NonCDataNormalize(string value)
        {
            int len = value.Length;

            if (len <= 0)
            {
                return(string.Empty);
            }

            int           startPos    = 0;
            StringBuilder norValue    = null;
            XmlCharType   xmlCharType = XmlCharType.Instance;

            while (xmlCharType.IsWhiteSpace(value[startPos]))
            {
                startPos++;
                if (startPos == len)
                {
                    return(" ");
                }
            }

            int i = startPos;

            while (i < len)
            {
                if (!xmlCharType.IsWhiteSpace(value[i]))
                {
                    i++;
                    continue;
                }

                int j = i + 1;
                while (j < len && xmlCharType.IsWhiteSpace(value[j]))
                {
                    j++;
                }
                if (j == len)
                {
                    if (norValue == null)
                    {
                        return(value.Substring(startPos, i - startPos));
                    }
                    else
                    {
                        norValue.Append(value, startPos, i - startPos);
                        return(norValue.ToString());
                    }
                }
                if (j > i + 1 || value[i] != 0x20)
                {
                    if (norValue == null)
                    {
                        norValue = new StringBuilder(len);
                    }
                    norValue.Append(value, startPos, i - startPos);
                    norValue.Append((char)0x20);
                    startPos = j;
                    i        = j;
                }
                else
                {
                    i++;
                }
            }

            if (norValue != null)
            {
                if (startPos < i)
                {
                    norValue.Append(value, startPos, i - startPos);
                }
                return(norValue.ToString());
            }
            else
            {
                if (startPos > 0)
                {
                    return(value.Substring(startPos, len - startPos));
                }
                else
                {
                    return(value);
                }
            }
        }
Exemple #15
0
            // This method trims whitespaces from the beginnig and the end of the string and cached writer events
            internal void Trim()
            {
                // if only one string value -> trim the write spaces directly
                if (_singleStringValue != null)
                {
                    _singleStringValue = XmlConvert.TrimString(_singleStringValue);
                    return;
                }

                // trim the string in StringBuilder
                string valBefore = _stringValue.ToString();
                string valAfter  = XmlConvert.TrimString(valBefore);

                if (valBefore != valAfter)
                {
                    _stringValue = new StringBuilder(valAfter);
                }

                // trim the beginning of the recorded writer events
                XmlCharType xmlCharType = XmlCharType.Instance;

                int i = _firstItem;

                while (i == _firstItem && i <= _lastItem)
                {
                    Item item = _items[i];
                    switch (item.type)
                    {
                    case ItemType.Whitespace:
                        _firstItem++;
                        break;

                    case ItemType.String:
                    case ItemType.Raw:
                    case ItemType.ValueString:
                        item.data = XmlConvert.TrimStringStart((string)item.data);
                        if (((string)item.data).Length == 0)
                        {
                            // no characters left -> move the firstItem index to exclude it from the Replay
                            _firstItem++;
                        }
                        break;

                    case ItemType.StringChars:
                    case ItemType.RawChars:
                        BufferChunk bufChunk = (BufferChunk)item.data;
                        int         endIndex = bufChunk.index + bufChunk.count;
                        while (bufChunk.index < endIndex && xmlCharType.IsWhiteSpace(bufChunk.buffer[bufChunk.index]))
                        {
                            bufChunk.index++;
                            bufChunk.count--;
                        }
                        if (bufChunk.index == endIndex)
                        {
                            // no characters left -> move the firstItem index to exclude it from the Replay
                            _firstItem++;
                        }
                        break;
                    }
                    i++;
                }

                // trim the end of the recorded writer events
                i = _lastItem;
                while (i == _lastItem && i >= _firstItem)
                {
                    Item item = _items[i];
                    switch (item.type)
                    {
                    case ItemType.Whitespace:
                        _lastItem--;
                        break;

                    case ItemType.String:
                    case ItemType.Raw:
                    case ItemType.ValueString:
                        item.data = XmlConvert.TrimStringEnd((string)item.data);
                        if (((string)item.data).Length == 0)
                        {
                            // no characters left -> move the lastItem index to exclude it from the Replay
                            _lastItem--;
                        }
                        break;

                    case ItemType.StringChars:
                    case ItemType.RawChars:
                        BufferChunk bufChunk = (BufferChunk)item.data;
                        while (bufChunk.count > 0 && xmlCharType.IsWhiteSpace(bufChunk.buffer[bufChunk.index + bufChunk.count - 1]))
                        {
                            bufChunk.count--;
                        }
                        if (bufChunk.count == 0)
                        {
                            // no characters left -> move the lastItem index to exclude it from the Replay
                            _lastItem--;
                        }
                        break;
                    }
                    i--;
                }
            }
Exemple #16
0
        private unsafe void Decode(char *pChars, char *pCharsEndPos,
                                   byte *pBytes, byte *pBytesEndPos,
                                   out int charsDecoded, out int bytesDecoded)
        {
#if DEBUG
            Debug.Assert(pCharsEndPos - pChars >= 0);
            Debug.Assert(pBytesEndPos - pBytes >= 0);
#endif

            // walk hex digits pairing them up and shoving the value of each pair into a byte
            byte *      pByte       = pBytes;
            char *      pChar       = pChars;
            int         b           = _bits;
            int         bFilled     = _bitsFilled;
            XmlCharType xmlCharType = XmlCharType.Instance;
            while (pChar < pCharsEndPos && pByte < pBytesEndPos)
            {
                char ch = *pChar;
                // end?
                if (ch == '=')
                {
                    break;
                }
                pChar++;

                // ignore white space
                if (xmlCharType.IsWhiteSpace(ch))
                {
                    continue;
                }

                int digit;
                if (ch > 122 || (digit = s_mapBase64[ch]) == Invalid)
                {
                    throw new XmlException(SR.Xml_InvalidBase64Value, new string(pChars, 0, (int)(pCharsEndPos - pChars)));
                }

                b        = (b << 6) | digit;
                bFilled += 6;

                if (bFilled >= 8)
                {
                    // get top eight valid bits
                    *pByte++ = (byte)((b >> (bFilled - 8)) & 0xFF);
                    bFilled -= 8;

                    if (pByte == pBytesEndPos)
                    {
                        goto Return;
                    }
                }
            }

            if (pChar < pCharsEndPos && *pChar == '=')
            {
                bFilled = 0;
                // ignore padding chars
                do
                {
                    pChar++;
                } while (pChar < pCharsEndPos && *pChar == '=');

                // ignore whitespace after the padding chars
                if (pChar < pCharsEndPos)
                {
                    do
                    {
                        if (!xmlCharType.IsWhiteSpace(*pChar++))
                        {
                            throw new XmlException(SR.Xml_InvalidBase64Value, new string(pChars, 0, (int)(pCharsEndPos - pChars)));
                        }
                    } while (pChar < pCharsEndPos);
                }
            }

Return:
            _bits       = b;
            _bitsFilled = bFilled;

            bytesDecoded = (int)(pByte - pBytes);
            charsDecoded = (int)(pChar - pChars);
        }
 void SkipSpace()
 {
     while (xmlCharType.IsWhiteSpace(curChar) && NextChar())
     {
     }
 }
Exemple #18
0
        public static string NormalizeSpace(string value)
        {
            XmlCharType   xmlCharType = XmlCharType.Instance;
            StringBuilder sb = null;
            int           idx, idxStart = 0, idxSpace = 0;

            for (idx = 0; idx < value.Length; idx++)
            {
                if (xmlCharType.IsWhiteSpace(value[idx]))
                {
                    if (idx == idxStart)
                    {
                        // Previous character was a whitespace character, so discard this character
                        idxStart++;
                    }
                    else if (value[idx] != ' ' || idxSpace == idx)
                    {
                        // Space was previous character or this is a non-space character
                        if (sb == null)
                        {
                            sb = new StringBuilder(value.Length);
                        }
                        else
                        {
                            sb.Append(' ');
                        }

                        // Copy non-space characters into string builder
                        if (idxSpace == idx)
                        {
                            sb.Append(value, idxStart, idx - idxStart - 1);
                        }
                        else
                        {
                            sb.Append(value, idxStart, idx - idxStart);
                        }

                        idxStart = idx + 1;
                    }
                    else
                    {
                        // Single whitespace character doesn't cause normalization, but mark its position
                        idxSpace = idx + 1;
                    }
                }
            }

            if (sb == null)
            {
                // Check for string that is entirely composed of whitespace
                if (idxStart == idx)
                {
                    return(string.Empty);
                }

                // If string does not end with a space, then it must already be normalized
                if (idxStart == 0 && idxSpace != idx)
                {
                    return(value);
                }

                sb = new StringBuilder(value.Length);
            }
            else if (idx != idxStart)
            {
                sb.Append(' ');
            }

            // Copy non-space characters into string builder
            if (idxSpace == idx)
            {
                sb.Append(value, idxStart, idx - idxStart - 1);
            }
            else
            {
                sb.Append(value, idxStart, idx - idxStart);
            }

            return(sb.ToString());
        }
Exemple #19
0
        public void Write(char[] array, int offset, int count)
        {
            if (null == array)
            {
                throw new ArgumentNullException(nameof(array));
            }

            if (0 > offset)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            if (0 > count)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            if (count > array.Length - offset)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            if (_cacheAttrValue)
            {
                _attrValue.Append(array, offset, count);
            }

            int  endPos = offset + count;
            int  i      = offset;
            char ch     = (char)0;

            for (;;)
            {
                int startPos = i;
                //unsafe
                //{
                while (i < endPos && _xmlCharType.IsAttributeValueChar(ch = array[i]))
                {
                    i++;
                }
                //}

                if (startPos < i)
                {
                    _textWriter.Write(array, startPos, i - startPos);
                }
                if (i == endPos)
                {
                    break;
                }

                switch (ch)
                {
                case (char)0x9:
                    _textWriter.Write(ch);
                    break;

                case (char)0xA:
                case (char)0xD:
                    if (_inAttribute)
                    {
                        WriteCharEntityImpl(ch);
                    }
                    else
                    {
                        _textWriter.Write(ch);
                    }
                    break;

                case '<':
                    WriteEntityRefImpl("lt");
                    break;

                case '>':
                    WriteEntityRefImpl("gt");
                    break;

                case '&':
                    WriteEntityRefImpl("amp");
                    break;

                case '\'':
                    if (_inAttribute && _quoteChar == ch)
                    {
                        WriteEntityRefImpl("apos");
                    }
                    else
                    {
                        _textWriter.Write('\'');
                    }
                    break;

                case '"':
                    if (_inAttribute && _quoteChar == ch)
                    {
                        WriteEntityRefImpl("quot");
                    }
                    else
                    {
                        _textWriter.Write('"');
                    }
                    break;

                default:
                    if (XmlCharType.IsHighSurrogate(ch))
                    {
                        if (i + 1 < endPos)
                        {
                            WriteSurrogateChar(array[++i], ch);
                        }
                        else
                        {
                            throw new Exception("throw new ArgumentException(SR.Xml_SurrogatePairSplit);");
                        }
                    }
                    else if (XmlCharType.IsLowSurrogate(ch))
                    {
                        throw new Exception("throw XmlConvert.CreateInvalidHighSurrogateCharException(ch)");
                    }
                    else
                    {
                        Debug.Assert((ch < 0x20 && !_xmlCharType.IsWhiteSpace(ch)) || (ch > 0xFFFD));
                        WriteCharEntityImpl(ch);
                    }
                    break;
                }
                i++;
            }
        }