private String DecodeDecimalFormat(StringBuilder buffer, Format format)
 {
     buffer.Append(",number"); //$NON-NLS-1$
     if (format.Equals(NumberFormat.GetNumberInstance(locale)))
     {
         // Empty block
     }
     else if (format.Equals(NumberFormat.GetIntegerInstance(locale)))
     {
         buffer.Append(",integer"); //$NON-NLS-1$
     }
     else if (format.Equals(NumberFormat.GetCurrencyInstance(locale)))
     {
         buffer.Append(",currency"); //$NON-NLS-1$
     }
     else if (format.Equals(NumberFormat.GetPercentInstance(locale)))
     {
         buffer.Append(",percent"); //$NON-NLS-1$
     }
     else
     {
         buffer.Append(',');
         return(((DecimalFormat)format).ToPattern());
     }
     return(null);
 }
        private Format ParseVariable(String str0, ParsePosition position)
        {
            int  length = str0.Length, offset = position.GetIndex();
            char ch;

            if (offset >= length ||
                ((ch = str0[offset++]) != '}' && ch != ','))
            {
                // text.15=Missing element format
                throw new ArgumentException("text.15"); //$NON-NLS-1$
            }
            position.SetIndex(offset);
            if (ch == '}')
            {
                return(null);
            }
            int type = Match(str0, position, false, new String[] { "time",                        //$NON-NLS-1$
                                                                   "date", "number", "choice" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

            if (type == -1)
            {
                // text.16=Unknown element format
                throw new ArgumentException("text.16"); //$NON-NLS-1$
            }
            StringBuilder buffer = new StringBuilder();

            ch = str0[position.GetIndex() - 1];
            switch (type)
            {
            case 0:     // time
            case 1:     // date
                if (ch == '}')
                {
                    return((type == 1) ? DateFormat.GetDateInstance(
                               DateFormat.DEFAULT, locale) : DateFormat
                           .GetTimeInstance(DateFormat.DEFAULT, locale));
                }
                int dateStyle = Match(str0, position, true, new String[] {
                    "full", "long", "medium", "short"
                });                                                                   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                if (dateStyle == -1)
                {
                    ILOG.J2CsMapping.Formatting.Format.UpToWithQuotes(str0, position, buffer, '}', '{');
                    return(new SimpleDateFormat(buffer.ToString(), locale));
                }
                switch (dateStyle)
                {
                case 0:
                    dateStyle = DateFormat.FULL;
                    break;

                case 1:
                    dateStyle = DateFormat.LONG;
                    break;

                case 2:
                    dateStyle = DateFormat.MEDIUM;
                    break;

                case 3:
                    dateStyle = DateFormat.SHORT;
                    break;
                }
                return((type == 1) ? DateFormat.GetDateInstance(dateStyle, locale)
                            : DateFormat.GetTimeInstance(dateStyle, locale));

            case 2:     // number
                if (ch == '}')
                {
                    return(NumberFormat.GetInstance());
                }
                int numberStyle = Match(str0, position, true, new String[] {
                    "currency", "percent", "integer"
                });                                                                  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                if (numberStyle == -1)
                {
                    ILOG.J2CsMapping.Formatting.Format.UpToWithQuotes(str0, position, buffer, '}', '{');
                    return(new DecimalFormat(buffer.ToString(),
                                             new DecimalFormatSymbols(locale)));
                }
                switch (numberStyle)
                {
                case 0:         // currency
                    return(NumberFormat.GetCurrencyInstance(locale));

                case 1:         // percent
                    return(NumberFormat.GetPercentInstance(locale));
                }
                return(NumberFormat.GetIntegerInstance(locale));
            }
            // choice
            try
            {
                ILOG.J2CsMapping.Formatting.Format.UpToWithQuotes(str0, position, buffer, '}', '{');
            }
            catch (ArgumentException e)
            {
                // ignored
            }
            return(new ChoiceFormat(buffer.ToString()));
        }