/// <summary>
        /// Parse the message arguments from the specified String using the rules of
        /// this MessageFormat.
        /// </summary>
        ///
        /// <param name="string">the String to parse</param>
        /// <returns>the array of Object arguments resulting from the parse</returns>
        /// <exception cref="ParseException">when an error occurs during parsing</exception>
        public Object[] Parse(String str0)
        {
            ParsePosition position = new ParsePosition(0);

            Object[] result = Parse(str0, position);
            if (position.GetErrorIndex() != -1 || position.GetIndex() == 0)
            {
                throw new ILOG.J2CsMapping.Util.ParseException(null, position.GetErrorIndex());
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Parse a Number from the specified String using the rules of this
        /// NumberFormat.
        /// </summary>
        ///
        /// <param name="string">the String to parse</param>
        /// <returns>the Number resulting from the parse</returns>
        /// <exception cref="ParseException">when an error occurs during parsing</exception>
        public object Parse(String str0)
        {
            ParsePosition pos    = new ParsePosition(0);
            object        number = Parse(str0, pos);

            if (pos.GetErrorIndex() != -1 || pos.GetIndex() == 0)
            {
                throw new ILOG.J2CsMapping.Util.ParseException(null, pos.GetErrorIndex());
            }
            return(number);
        }
Beispiel #3
0
        /// <summary>
        /// Parse a Date from the specified String using the rules of this
        /// DateFormat.
        /// </summary>
        ///
        /// <param name="string">the String to parse</param>
        /// <returns>the Date resulting from the parse</returns>
        /// <exception cref="ParseException">when an error occurs during parsing</exception>
        public DateTime Parse(String str0)
        {
            ParsePosition position = new ParsePosition(0);
            DateTime      date     = Parse(str0, position);

            if (position.GetErrorIndex() != -1 || position.GetIndex() == 0)
            {
                // text.19=Unparseable date: {0}
                throw new ILOG.J2CsMapping.Util.ParseException("text.19" + str0 + position.GetErrorIndex()); //$NON-NLS-1$
            }
            return(date);
        }
        /// <summary>
        /// Parse the message argument from the specified String starting at the
        /// index specified by the ParsePosition. If the string is successfully
        /// parsed, the index of the ParsePosition is updated to the index following
        /// the parsed text.
        /// </summary>
        ///
        /// <param name="string">the String to parse</param>
        /// <param name="position">the ParsePosition, updated on return with the index followingthe parsed text, or on error the index is unchanged and theerror index is set to the index where the error occurred</param>
        /// <returns>the array of Object arguments resulting from the parse, or null
        /// if there is an error</returns>
        public Object[] Parse(String str0, ParsePosition position)
        {
            if (str0 == null)
            {
                return(new Object[0]);
            }
            ParsePosition internalPos = new ParsePosition(0);
            int           offset      = position.GetIndex();

            Object[] result = new Object[maxArgumentIndex + 1];
            for (int i = 0; i <= maxOffset; i++)
            {
                String sub = strings[i];
                if (!ILOG.J2CsMapping.Util.StringUtil.StartsWith(str0, sub, offset))
                {
                    position.SetErrorIndex(offset);
                    return(null);
                }
                offset += sub.Length;
                Object parse;
                Format format = formats[i];
                if (format == null)
                {
                    if (i + 1 < strings.Length)
                    {
                        int next = ILOG.J2CsMapping.Util.StringUtil.IndexOf(str0, strings[i + 1], offset);
                        if (next == -1)
                        {
                            position.SetErrorIndex(offset);
                            return(null);
                        }
                        parse  = str0.Substring(offset, (next) - (offset));
                        offset = next;
                    }
                    else
                    {
                        parse  = str0.Substring(offset);
                        offset = str0.Length;
                    }
                }
                else
                {
                    internalPos.SetIndex(offset);
                    parse = format.ParseObject(str0, internalPos);
                    if (internalPos.GetErrorIndex() != -1)
                    {
                        position.SetErrorIndex(offset);
                        return(null);
                    }
                    offset = internalPos.GetIndex();
                }
                result[argumentNumbers[i]] = parse;
            }
            if (maxOffset + 1 < strings.Length)
            {
                String sub_0 = strings[maxOffset + 1];
                if (!ILOG.J2CsMapping.Util.StringUtil.StartsWith(str0, sub_0, offset))
                {
                    position.SetErrorIndex(offset);
                    return(null);
                }
                offset += sub_0.Length;
            }
            position.SetIndex(offset);
            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Parses the pattern to determine new strings and ranges for this
        /// ChoiceFormat.
        /// </summary>
        ///
        /// <param name="template">the pattern of strings and ranges</param>
        /// <exception cref="IllegalArgumentException">then an error occurs parsing the pattern</exception>
        public void ApplyPattern(String template)
        {
            double[]       limits = new double[5];
            IList <String> formats = new List <String>();
            int            length = template.Length, limitCount = 0, index = 0;
            StringBuilder  buffer = new StringBuilder();

            IBM.ICU.Text.NumberFormat format   = IBM.ICU.Text.NumberFormat.GetInstance(ILOG.J2CsMapping.Util.Locale.US);
            ParsePosition             position = new ParsePosition(0);

            while (true)
            {
                index = SkipWhitespace(template, index);
                if (index >= length)
                {
                    if (limitCount == limits.Length)
                    {
                        choiceLimits = limits;
                    }
                    else
                    {
                        choiceLimits = new double[limitCount];
                        System.Array.Copy((Array)(limits), 0, (Array)(choiceLimits), 0, limitCount);
                    }
                    choiceFormats = new String[formats.Count];
                    for (int i = 0; i < formats.Count; i++)
                    {
                        choiceFormats[i] = formats[i];
                    }
                    return;
                }

                position.SetIndex(index);
                object value_ren = format.Parse(template, position);
                index = SkipWhitespace(template, position.GetIndex());
                if (position.GetErrorIndex() != -1 || index >= length)
                {
                    // Fix Harmony 540
                    choiceLimits  = new double[0];
                    choiceFormats = new String[0];
                    return;
                }
                char ch = template[index++];
                if (limitCount == limits.Length)
                {
                    double[] newLimits = new double[limitCount * 2];
                    System.Array.Copy((Array)(limits), 0, (Array)(newLimits), 0, limitCount);
                    limits = newLimits;
                }
                double next;
                switch ((int)ch)
                {
                case '#':
                case '\u2264':
                    next = Convert.ToDouble(value_ren);
                    break;

                case '<':
                    next = NextDouble(Convert.ToDouble(value_ren));
                    break;

                default:
                    throw new ArgumentException();
                }
                if (limitCount > 0 && next <= limits[limitCount - 1])
                {
                    throw new ArgumentException();
                }
                buffer.Length = 0;
                position.SetIndex(index);
                ILOG.J2CsMapping.Formatting.Format.UpTo(template, position, buffer, '|');
                index = position.GetIndex();
                limits[limitCount++] = next;
                ILOG.J2CsMapping.Collections.Generics.Collections.Add(formats, buffer.ToString());
            }
        }