示例#1
0
        /// <summary>
        /// Sets a property of a selected decimal format, for use by the <c>format-number</c> function.
        /// </summary>
        /// <remarks>
        /// This method checks that the value is valid for the particular property, but it does not
        /// check that all the values for the decimal format are consistent (for example, that the
        /// decimal separator and grouping separator have different values). This consistency
        /// check is performed only when the decimal format is used.
        /// </remarks>
        /// <param name="format">The name of the decimal format whose property is to be set.
        ///  Supply null to set a property of the default (unnamed) decimal format.
        ///  This correponds to a name used in the third argument of <c>format-number</c>.</param>
        /// <param name="property">The name of the property to set: one of
        ///   "decimal-separator", "grouping-separator", "infinity", "NaN",
        ///   "minus-sign", "percent", "per-mille", "zero-digit", "digit",
        ///   or "pattern-separator".</param>
        /// <param name="value">The new value for the property.</param>

        public void SetDecimalFormatProperty(QName format, String property, String value)
        {
            net.sf.saxon.trans.DecimalFormatManager dfm = env.getDecimalFormatManager();
            if (dfm == null)
            {
                dfm = new net.sf.saxon.trans.DecimalFormatManager();
                env.setDecimalFormatManager(dfm);
            }

            net.sf.saxon.om.StructuredQName   sqname  = null;
            net.sf.saxon.trans.DecimalSymbols symbols = null;

            if (format != null)
            {
                sqname  = net.sf.saxon.om.StructuredQName.fromClarkName(format.ClarkName);
                symbols = dfm.obtainNamedDecimalFormat(sqname);
            }
            else
            {
                symbols = dfm.getDefaultDecimalFormat();
            }

            if (property.Equals("decimal-separator"))
            {
                symbols.decimalSeparator = checkSingleChar(value);
            }
            else if (property.Equals("grouping-separator"))
            {
                symbols.groupingSeparator = checkSingleChar(value);
            }
            else if (property.Equals("infinity"))
            {
                symbols.infinity = value;
            }
            else if (property.Equals("NaN"))
            {
                symbols.NaN = value;
            }
            else if (property.Equals("minus-sign"))
            {
                symbols.minusSign = checkSingleChar(value);
            }
            else if (property.Equals("percent"))
            {
                symbols.percent = checkSingleChar(value);
            }
            else if (property.Equals("per-mille"))
            {
                symbols.permill = checkSingleChar(value);
            }
            else if (property.Equals("zero-digit"))
            {
                symbols.zeroDigit = checkSingleChar(value);
                if (!symbols.isValidZeroDigit())
                {
                    throw new ArgumentException("Value supplied for zero-digit is not a Unicode digit representing zero");
                }
            }
            else if (property.Equals("digit"))
            {
                symbols.digit = checkSingleChar(value);
            }
            else if (property.Equals("pattern-separator"))
            {
                symbols.patternSeparator = checkSingleChar(value);
            }
            else
            {
                throw new ArgumentException("Unknown decimal format property " + property);
            }

            try
            {
                if (format == null)
                {
                    dfm.setDefaultDecimalFormat(symbols, 0);
                }
                else
                {
                    dfm.setNamedDecimalFormat(net.sf.saxon.om.StructuredQName.fromClarkName(format.ClarkName), symbols, 0);
                }
            }
            catch (net.sf.saxon.trans.XPathException e)
            {
                throw new DynamicError(e);
            }
        }
示例#2
0
文件: XPath.cs 项目: orbeon/saxon-he
        /// <summary>
        /// Sets a property of a selected decimal format, for use by the <c>format-number</c> function.
        /// </summary>
        /// <remarks>
        /// This method checks that the value is valid for the particular property, but it does not
        /// check that all the values for the decimal format are consistent (for example, that the
        /// decimal separator and grouping separator have different values). This consistency
        /// check is performed only when the decimal format is used.
        /// </remarks>
        /// <param name="format">The name of the decimal format whose property is to be set.
        ///  Supply null to set a property of the default (unnamed) decimal format.
        ///  This correponds to a name used in the third argument of <c>format-number</c>.</param>
        /// <param name="property">The name of the property to set: one of
        ///   "decimal-separator", "grouping-separator", "infinity", "NaN",
        ///   "minus-sign", "percent", "per-mille", "zero-digit", "digit",
        ///   or "pattern-separator".</param>
        /// <param name="value">The new value for the property.</param>

        public void SetDecimalFormatProperty(QName format, String property, String value)
        {
            net.sf.saxon.trans.DecimalFormatManager dfm = env.getDecimalFormatManager();
            if (dfm == null)
            {
                dfm = new net.sf.saxon.trans.DecimalFormatManager(net.sf.saxon.Configuration.XPATH, env.getXPathVersion());
                env.setDecimalFormatManager(dfm);
            }

            net.sf.saxon.om.StructuredQName   sqname  = null;
            net.sf.saxon.trans.DecimalSymbols symbols = null;

            if (format != null)
            {
                sqname  = net.sf.saxon.om.StructuredQName.fromClarkName(format.ClarkName);
                symbols = dfm.obtainNamedDecimalFormat(sqname);
            }
            else
            {
                symbols = dfm.getDefaultDecimalFormat();
            }

            if (property.Equals("decimal-separator"))
            {
                symbols.setDecimalSeparator(value);
            }
            else if (property.Equals("grouping-separator"))
            {
                symbols.setGroupingSeparator(value);
            }
            else if (property.Equals("infinity"))
            {
                symbols.setInfinity(value);
            }
            else if (property.Equals("NaN"))
            {
                symbols.setNaN(value);
            }
            else if (property.Equals("minus-sign"))
            {
                symbols.setMinusSign(value);
            }
            else if (property.Equals("percent"))
            {
                symbols.setPercent(value);
            }
            else if (property.Equals("per-mille"))
            {
                symbols.setPerMille(value);
            }
            else if (property.Equals("zero-digit"))
            {
                symbols.setZeroDigit(value);
                if (!net.sf.saxon.trans.DecimalSymbols.isValidZeroDigit(symbols.getZeroDigit()))
                {
                    throw new ArgumentException("Value supplied for zero-digit is not a Unicode digit representing zero");
                }
            }
            else if (property.Equals("digit"))
            {
                symbols.setDigit(value);
            }
            else if (property.Equals("pattern-separator"))
            {
                symbols.setPatternSeparator(value);
            }
            else
            {
                throw new ArgumentException("Unknown decimal format property " + property);
            }
        }
示例#3
0
文件: XPath.cs 项目: nuxleus/saxonica
        /// <summary>
        /// Sets a property of a selected decimal format, for use by the <c>format-number</c> function.
        /// </summary>
        /// <remarks>
        /// This method checks that the value is valid for the particular property, but it does not
        /// check that all the values for the decimal format are consistent (for example, that the
        /// decimal separator and grouping separator have different values). This consistency
        /// check is performed only when the decimal format is used.
        /// </remarks>
        /// <param name="format">The name of the decimal format whose property is to be set.
        ///  Supply null to set a property of the default (unnamed) decimal format.
        ///  This correponds to a name used in the third argument of <c>format-number</c>.</param>
        /// <param name="property">The name of the property to set: one of
        ///   "decimal-separator", "grouping-separator", "infinity", "NaN",
        ///   "minus-sign", "percent", "per-mille", "zero-digit", "digit",
        ///   or "pattern-separator".</param>
        /// <param name="value">The new value for the property.</param>

        public void SetDecimalFormatProperty(QName format, String property, String value){
            net.sf.saxon.trans.DecimalFormatManager dfm = env.getDecimalFormatManager();
            if (dfm == null)
            {
                dfm = new net.sf.saxon.trans.DecimalFormatManager();
                env.setDecimalFormatManager(dfm);
            }
            
            net.sf.saxon.om.StructuredQName sqname = null;
            net.sf.saxon.trans.DecimalSymbols symbols = null;
            
            if (format != null) {
                sqname = net.sf.saxon.om.StructuredQName.fromClarkName(format.ClarkName);
                symbols = dfm.obtainNamedDecimalFormat(sqname);
            } else {
                symbols = dfm.getDefaultDecimalFormat();
            }

            if (property.Equals("decimal-separator"))
            {
                symbols.decimalSeparator = checkSingleChar(value);
            }
            else if (property.Equals("grouping-separator"))
            {
                symbols.groupingSeparator = checkSingleChar(value);
            }
            else if (property.Equals("infinity"))
            {
                symbols.infinity = value;
            }
            else if (property.Equals("NaN"))
            {
                symbols.NaN = value;
            }
            else if (property.Equals("minus-sign"))
            {
                symbols.minusSign = checkSingleChar(value);
            }
            else if (property.Equals("percent"))
            {
                symbols.percent = checkSingleChar(value);
            }
            else if (property.Equals("per-mille"))
            {
                symbols.permill = checkSingleChar(value);
            }
            else if (property.Equals("zero-digit"))
            {
                symbols.zeroDigit = checkSingleChar(value);
                if (!symbols.isValidZeroDigit()) {
                    throw new ArgumentException("Value supplied for zero-digit is not a Unicode digit representing zero");
                } 
            }
            else if (property.Equals("digit"))
            {
                symbols.digit = checkSingleChar(value);
            }
            else if (property.Equals("pattern-separator"))
            {
                symbols.patternSeparator = checkSingleChar(value);
            }
            else
            {
                throw new ArgumentException("Unknown decimal format property " + property);
            }

            try
            {
                if (format == null)
                {
                    dfm.setDefaultDecimalFormat(symbols, 0);
                }
                else
                {
                    dfm.setNamedDecimalFormat(net.sf.saxon.om.StructuredQName.fromClarkName(format.ClarkName), symbols, 0);
                }
            }
            catch (net.sf.saxon.trans.XPathException e)
            {
                throw new DynamicError(e);
            }
        }