Exemplo n.º 1
0
 /// <summary>
 /// Create a new sort key and append it to the current run of sort keys.
 /// </summary>
 public void AddStringSortKey(XmlCollation collation, string value)
 {
     //BinCompat TODO
     throw new NotImplementedException();
 }
Exemplo n.º 2
0
 public XmlIntSortKey(int value, XmlCollation collation) {
     // Invert integer if sorting in descending order
     this.intVal = collation.DescendingOrder ? ~value : value;
 }
Exemplo n.º 3
0
 public XmlDateTimeSortKey(DateTime value, XmlCollation collation) : base(value.Ticks, collation) {
 }
Exemplo n.º 4
0
 public void AddEmptySortKey(XmlCollation collation)
 {
     AppendSortKey(new XmlEmptySortKey(collation));
 }
Exemplo n.º 5
0
 public XmlDecimalSortKey(decimal value, XmlCollation collation) {
     // Invert decimal if sorting in descending order
     this.decVal = collation.DescendingOrder ? -value : value;
 }
Exemplo n.º 6
0
 public void AddIntegerSortKey(XmlCollation collation, long value)
 {
     AppendSortKey(new XmlIntegerSortKey(value, collation));
 }
Exemplo n.º 7
0
 public void AddDoubleSortKey(XmlCollation collation, double value)
 {
     AppendSortKey(new XmlDoubleSortKey(value, collation));
 }
Exemplo n.º 8
0
 public XmlDateTimeSortKey(DateTime value, XmlCollation collation) : base(value.Ticks, collation)
 {
 }
Exemplo n.º 9
0
 /// <summary>
 /// Create a new sort key and append it to the current run of sort keys.
 /// </summary>
 public void AddStringSortKey(XmlCollation collation, string value)
 {
     AppendSortKey(collation.CreateSortKey(value));
 }
Exemplo n.º 10
0
 public XmlIntegerSortKey(long value, XmlCollation collation)
 {
     // Invert long if sorting in descending order
     _longVal = collation.DescendingOrder ? ~value : value;
 }
Exemplo n.º 11
0
 public XmlIntSortKey(int value, XmlCollation collation)
 {
     // Invert integer if sorting in descending order
     _intVal = collation.DescendingOrder ? ~value : value;
 }
Exemplo n.º 12
0
 public XmlDecimalSortKey(decimal value, XmlCollation collation)
 {
     // Invert decimal if sorting in descending order
     _decVal = collation.DescendingOrder ? -value : value;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Create a collation from a string.
 /// </summary>
 public XmlCollation CreateCollation(string collation)
 {
     return(XmlCollation.Create(collation));
 }
Exemplo n.º 14
0
        /// <summary>
        /// Deserialize XmlQueryStaticData object from a byte array.
        /// </summary>
        public XmlQueryStaticData(byte[] data, Type[] ebTypes)
        {
            MemoryStream       dataStream = new MemoryStream(data, /*writable:*/ false);
            XmlQueryDataReader dataReader = new XmlQueryDataReader(dataStream);
            int length;

            // Read a format version
            int formatVersion = dataReader.Read7BitEncodedInt();

            // Changes in the major part of version are not supported
            if ((formatVersion & ~0xff) > CurrentFormatVersion)
            {
                throw new NotSupportedException();
            }

            // XmlWriterSettings defaultWriterSettings;
            _defaultWriterSettings = new XmlWriterSettings(dataReader);

            // IList<WhitespaceRule> whitespaceRules;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _whitespaceRules = new WhitespaceRule[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _whitespaceRules[idx] = new WhitespaceRule(dataReader);
                }
            }

            // string[] names;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _names = new string[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _names[idx] = dataReader.ReadString();
                }
            }

            // StringPair[][] prefixMappingsList;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _prefixMappingsList = new StringPair[length][];
                for (int idx = 0; idx < length; idx++)
                {
                    int length2 = dataReader.ReadInt32();
                    _prefixMappingsList[idx] = new StringPair[length2];
                    for (int idx2 = 0; idx2 < length2; idx2++)
                    {
                        _prefixMappingsList[idx][idx2] = new StringPair(dataReader.ReadString(), dataReader.ReadString());
                    }
                }
            }

            // Int32Pair[] filters;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _filters = new Int32Pair[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _filters[idx] = new Int32Pair(dataReader.Read7BitEncodedInt(), dataReader.Read7BitEncodedInt());
                }
            }

            // XmlQueryType[] types;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _types = new XmlQueryType[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _types[idx] = XmlQueryTypeFactory.Deserialize(dataReader);
                }
            }

            // XmlCollation[] collations;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _collations = new XmlCollation[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _collations[idx] = new XmlCollation(dataReader);
                }
            }

            // string[] globalNames;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _globalNames = new string[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _globalNames[idx] = dataReader.ReadString();
                }
            }

            // EarlyBoundInfo[] earlyBound;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _earlyBound = new EarlyBoundInfo[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _earlyBound[idx] = new EarlyBoundInfo(dataReader.ReadString(), ebTypes[idx]);
                }
            }

            Debug.Assert(formatVersion != CurrentFormatVersion || dataReader.Read() == -1, "Extra data at the end of the stream");
            dataReader.Dispose();
        }
Exemplo n.º 15
0
 /// <summary>
 /// Create a new sort key and append it to the current run of sort keys.
 /// </summary>
 public void AddStringSortKey(XmlCollation collation, string value)
 {
     //BinCompat TODO
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public void AddDecimalSortKey(XmlCollation collation, decimal value)
 {
     AppendSortKey(new XmlDecimalSortKey(value, collation));
 }
Exemplo n.º 17
0
 public void AddDecimalSortKey(XmlCollation collation, decimal value)
 {
     AppendSortKey(new XmlDecimalSortKey(value, collation));
 }
Exemplo n.º 18
0
 public void AddIntegerSortKey(XmlCollation collation, long value)
 {
     AppendSortKey(new XmlIntegerSortKey(value, collation));
 }
Exemplo n.º 19
0
 public void AddIntSortKey(XmlCollation collation, int value)
 {
     AppendSortKey(new XmlIntSortKey(value, collation));
 }
Exemplo n.º 20
0
 public void AddIntSortKey(XmlCollation collation, int value)
 {
     AppendSortKey(new XmlIntSortKey(value, collation));
 }
Exemplo n.º 21
0
 public void AddDateTimeSortKey(XmlCollation collation, DateTime value)
 {
     AppendSortKey(new XmlDateTimeSortKey(value, collation));
 }
Exemplo n.º 22
0
 public void AddDoubleSortKey(XmlCollation collation, double value)
 {
     AppendSortKey(new XmlDoubleSortKey(value, collation));
 }
Exemplo n.º 23
0
        /// <summary>
        /// Deserialize XmlQueryStaticData object from a byte array.
        /// </summary>
        public XmlQueryStaticData(byte[] data, Type[] ebTypes)
        {
            MemoryStream dataStream = new MemoryStream(data, /*writable:*/false);
            XmlQueryDataReader dataReader = new XmlQueryDataReader(dataStream);
            int length;

            // Read a format version
            int formatVersion = dataReader.ReadInt32Encoded();

            // Changes in the major part of version are not supported
            if ((formatVersion & ~0xff) > CurrentFormatVersion)
                throw new NotSupportedException();

            // XmlWriterSettings defaultWriterSettings;
            _defaultWriterSettings = new XmlWriterSettings(dataReader);

            // IList<WhitespaceRule> whitespaceRules;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _whitespaceRules = new WhitespaceRule[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _whitespaceRules[idx] = new WhitespaceRule(dataReader);
                }
            }

            // string[] names;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _names = new string[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _names[idx] = dataReader.ReadString();
                }
            }

            // StringPair[][] prefixMappingsList;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _prefixMappingsList = new StringPair[length][];
                for (int idx = 0; idx < length; idx++)
                {
                    int length2 = dataReader.ReadInt32();
                    _prefixMappingsList[idx] = new StringPair[length2];
                    for (int idx2 = 0; idx2 < length2; idx2++)
                    {
                        _prefixMappingsList[idx][idx2] = new StringPair(dataReader.ReadString(), dataReader.ReadString());
                    }
                }
            }

            // Int32Pair[] filters;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _filters = new Int32Pair[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _filters[idx] = new Int32Pair(dataReader.ReadInt32Encoded(), dataReader.ReadInt32Encoded());
                }
            }

            // XmlQueryType[] types;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _types = new XmlQueryType[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _types[idx] = XmlQueryTypeFactory.Deserialize(dataReader);
                }
            }

            // XmlCollation[] collations;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _collations = new XmlCollation[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _collations[idx] = new XmlCollation(dataReader);
                }
            }

            // string[] globalNames;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _globalNames = new string[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _globalNames[idx] = dataReader.ReadString();
                }
            }

            // EarlyBoundInfo[] earlyBound;
            length = dataReader.ReadInt32();
            if (length != 0)
            {
                _earlyBound = new EarlyBoundInfo[length];
                for (int idx = 0; idx < length; idx++)
                {
                    _earlyBound[idx] = new EarlyBoundInfo(dataReader.ReadString(), ebTypes[idx]);
                }
            }

            Debug.Assert(formatVersion != CurrentFormatVersion || dataReader.Read() == -1, "Extra data at the end of the stream");
            dataReader.Dispose();
        }
Exemplo n.º 24
0
 public void AddDateTimeSortKey(XmlCollation collation, DateTime value)
 {
     AppendSortKey(new XmlDateTimeSortKey(value, collation));
 }
Exemplo n.º 25
0
 public XmlIntegerSortKey(long value, XmlCollation collation) {
     // Invert long if sorting in descending order
     this.longVal = collation.DescendingOrder ? ~value : value;
 }
Exemplo n.º 26
0
 public void AddEmptySortKey(XmlCollation collation)
 {
     AppendSortKey(new XmlEmptySortKey(collation));
 }
Exemplo n.º 27
0
        public XmlDoubleSortKey(double value, XmlCollation collation) {
            if (Double.IsNaN(value)) {
                // Treat NaN as if it were the empty sequence
                this.isNaN = true;

                // Greatest, Ascending: isEmptyGreatest = true
                // Greatest, Descending: isEmptyGreatest = false
                // Least, Ascending: isEmptyGreatest = false
                // Least, Descending: isEmptyGreatest = true
                this.dblVal = (collation.EmptyGreatest != collation.DescendingOrder) ? Double.PositiveInfinity : Double.NegativeInfinity;
            }
            else {
                this.dblVal = collation.DescendingOrder ? -value : value;
            }
        }
 /// <summary>
 /// Create a new sort key and append it to the current run of sort keys.
 /// </summary>
 public void AddStringSortKey(XmlCollation collation, string value) {
     AppendSortKey(collation.CreateSortKey(value));
 }
Exemplo n.º 29
0
 public XmlEmptySortKey(XmlCollation collation) {
     // Greatest, Ascending: isEmptyGreatest = true
     // Greatest, Descending: isEmptyGreatest = false
     // Least, Ascending: isEmptyGreatest = false
     // Least, Descending: isEmptyGreatest = true
     this.isEmptyGreatest = collation.EmptyGreatest != collation.DescendingOrder;
 }
Exemplo n.º 30
0
        /// <summary>
        /// This function is used in both parser and f&o library, so just strictly map valid literals to XmlCollation.
        /// Set compare options one by one:
        ///     0, false: no effect; 1, true: yes
        /// Disregard unrecognized options.
        /// </summary>
        internal static XmlCollation Create(string collationLiteral) {
            Debug.Assert(collationLiteral != null, "collation literal should not be null");

            if (collationLiteral == XmlReservedNs.NsCollCodePoint) {
                return CodePointCollation;
            }

            XmlCollation coll = new XmlCollation();
            Uri collationUri = new Uri(collationLiteral);

            string authority = collationUri.GetLeftPart(UriPartial.Authority);
            if (authority == XmlReservedNs.NsCollationBase) {
                // Language
                // at least a '/' will be returned for Uri.LocalPath
                string lang = collationUri.LocalPath.Substring(1);
                if (lang.Length == 0) {
                    // Use default culture of current thread (cultinfo = null)
                } else {
                    // Create culture from RFC 1766 string
                    try {
                        coll.cultinfo = new CultureInfo(lang);
                    }
                    catch (ArgumentException) {
                        throw new XslTransformException(Res.Coll_UnsupportedLanguage, lang);
                    }
                }
            } else if (collationUri.IsBaseOf(new Uri(XmlReservedNs.NsCollCodePoint))) {
                // language with codepoint collation is not allowed
                coll.compops = CompareOptions.Ordinal;
            } else {
                // Unrecognized collation
                throw new XslTransformException(Res.Coll_Unsupported, collationLiteral);
            }

            // Sort & Compare option
            // at least a '?' will be returned for Uri.Query if not empty
            string query = collationUri.Query;
            string sort = null;

            if (query.Length != 0) {
                foreach (string option in query.Substring(1).Split('&')) {
                    string[] pair = option.Split('=');

                    if (pair.Length != 2)
                        throw new XslTransformException(Res.Coll_BadOptFormat, option);

                    string optionName = pair[0].ToUpper(CultureInfo.InvariantCulture);
                    string optionValue = pair[1].ToUpper(CultureInfo.InvariantCulture);

                    if (optionName == sortStr) {
                        sort = optionValue;
                    }
                    else if (optionValue == "1" || optionValue == "TRUE") {
                        switch (optionName) {
                        case ignoreCaseStr:        coll.compops |= CompareOptions.IgnoreCase; break;
                        case ignoreKanatypeStr:    coll.compops |= CompareOptions.IgnoreKanaType; break;
                        case ignoreNonspaceStr:    coll.compops |= CompareOptions.IgnoreNonSpace; break;
                        case ignoreSymbolsStr:     coll.compops |= CompareOptions.IgnoreSymbols; break;
                        case ignoreWidthStr:       coll.compops |= CompareOptions.IgnoreWidth; break;
                        case upperFirstStr:        coll.upperFirst = true; break;
                        case emptyGreatestStr:     coll.emptyGreatest = true; break;
                        case descendingOrderStr:   coll.descendingOrder = true; break;
                        default:
                            throw new XslTransformException(Res.Coll_UnsupportedOpt, pair[0]);
                        }
                    }
                    else if (optionValue == "0" || optionValue == "FALSE") {
                        switch (optionName) {
                        case ignoreCaseStr:        coll.compops &= ~CompareOptions.IgnoreCase; break;
                        case ignoreKanatypeStr:    coll.compops &= ~CompareOptions.IgnoreKanaType; break;
                        case ignoreNonspaceStr:    coll.compops &= ~CompareOptions.IgnoreNonSpace; break;
                        case ignoreSymbolsStr:     coll.compops &= ~CompareOptions.IgnoreSymbols; break;
                        case ignoreWidthStr:       coll.compops &= ~CompareOptions.IgnoreWidth; break;
                        case upperFirstStr:        coll.upperFirst = false; break;
                        case emptyGreatestStr:     coll.emptyGreatest = false; break;
                        case descendingOrderStr:   coll.descendingOrder = false; break;
                        default:
                            throw new XslTransformException(Res.Coll_UnsupportedOpt, pair[0]);
                        }
                    }
                    else {
                        throw new XslTransformException(Res.Coll_UnsupportedOptVal, pair[0], pair[1]);
                    }
                }
            }

            // upperfirst option is only meaningful when not ignore case
            if (coll.upperFirst && (coll.compops & CompareOptions.IgnoreCase) != 0)
                coll.upperFirst = false;

            // other CompareOptions are only meaningful if Ordinal comparison is not being used
            if ((coll.compops & CompareOptions.Ordinal) != 0) {
                coll.compops = CompareOptions.Ordinal;
                coll.upperFirst = false;
            }

            // new cultureinfo based on alternate sorting option
            if (sort != null && coll.cultinfo != null) {
                int lgid = GetLangID(coll.cultinfo.LCID);
                switch (sort) {
                case "bopo":
                    if (lgid == zhTW) {
                        coll.cultinfo = new CultureInfo(zhTWbopo);
                    }
                    break;
                case "strk":
                    if (lgid == zhCN || lgid == zhHK || lgid == zhSG || lgid == zhMO) {
                        coll.cultinfo = new CultureInfo(MakeLCID(coll.cultinfo.LCID, strksort));
                    }
                    break;
                case "uni":
                    if (lgid == jaJP || lgid == koKR) {
                        coll.cultinfo = new CultureInfo(MakeLCID(coll.cultinfo.LCID, unicsort));
                    }
                    break;
                case "phn":
                    if (lgid == deDE) {
                        coll.cultinfo = new CultureInfo(deDEphon);
                    }
                    break;
                case "tech":
                    if (lgid == huHU) {
                        coll.cultinfo = new CultureInfo(huHUtech);
                    }
                    break;
                case "mod":
                    // ka-GE(Georgian - Georgia) Modern Sort: 0x00010437
                    if (lgid == kaGE) {
                        coll.cultinfo = new CultureInfo(kaGEmode);
                    }
                    break;
                case "pron": case "dict": case "trad":
                    // es-ES(Spanish - Spain) Traditional: 0x0000040A
                    // They are removing 0x040a (Spanish Traditional sort) in NLS+.
                    // So if you create 0x040a, it's just like 0x0c0a (Spanish International sort).
                    // Thus I don't handle it differently.
                    break;
                default:
                    throw new XslTransformException(Res.Coll_UnsupportedSortOpt, sort);
                }
            }
            return coll;
        }