private static string Format(ArrayList numberlist, List<FormatInfo> tokens, string lang, string letter, string groupingSep, string groupingSize) {
            StringBuilder result = new StringBuilder();
            int cFormats = 0;
            if (tokens != null) {
                cFormats = tokens.Count;
            }

            NumberingFormat numberingFormat = new NumberingFormat();
            if (groupingSize != null) {
                try {
                    numberingFormat.setGroupingSize(Convert.ToInt32(groupingSize, CultureInfo.InvariantCulture));
                }
                catch (System.FormatException) {}
                catch (System.OverflowException) {}
            }
            if (groupingSep != null) {
                if (groupingSep.Length > 1) {
                }
                numberingFormat.setGroupingSeparator(groupingSep);
            }
            if (0 < cFormats) {
                FormatInfo prefix = tokens[0];
                Debug.Assert(prefix == null || prefix.isSeparator);
                FormatInfo sufix = null;
                if (cFormats % 2 == 1) {
                    sufix = tokens[cFormats - 1];
                    cFormats --;
                }
                FormatInfo periodicSeparator = 2 < cFormats ? tokens[cFormats - 2] : DefaultSeparator;
                FormatInfo periodicFormat    = 0 < cFormats ? tokens[cFormats - 1] : DefaultFormat   ;
                if (prefix != null) {
                    result.Append(prefix.formatString);
                }
                int numberlistCount = numberlist.Count;
                for(int i = 0; i < numberlistCount; i++ ) {
                    int formatIndex   = i * 2;
                    bool haveFormat = formatIndex < cFormats;
                    if (0 < i) {
                        FormatInfo thisSeparator = haveFormat ? tokens[formatIndex + 0] : periodicSeparator;
                        Debug.Assert(thisSeparator.isSeparator);
                        result.Append(thisSeparator.formatString);
                    }

                    FormatInfo thisFormat = haveFormat ? tokens[formatIndex + 1] : periodicFormat;
                    Debug.Assert(!thisFormat.isSeparator);

                    //numberingFormat.setletter(this.letter);
                    //numberingFormat.setLang(this.lang);

                    numberingFormat.setNumberingType(thisFormat.numSequence);
                    numberingFormat.setMinLen(thisFormat.length);
                    result.Append(numberingFormat.FormatItem(numberlist[i]));
                }

                if (sufix != null) {
                    result.Append(sufix.formatString);
                }
            }
            else {
                numberingFormat.setNumberingType(NumberingSequence.Arabic);
                for (int i = 0; i < numberlist.Count; i++) {
                    if (i != 0) {
                        result.Append(".");
                    }
                    result.Append(numberingFormat.FormatItem(numberlist[i]));
                }
            }
            return result.ToString();
        }
Exemple #2
0
        // SDUB: perf.
        // for each call to xsl:number Format() will build new NumberingFormat object.
        // in case of no AVTs we can build this object at compile time and reuse it on execution time.
        // even partial step in this derection will be usefull (when cFormats == 0)

        private static string Format(ArrayList numberlist, ArrayList formatlist, string lang, string letter, string groupingSep, string groupingSize)
        {
            StringBuilder result   = new StringBuilder();
            int           cFormats = 0;

            if (formatlist != null)
            {
                cFormats = formatlist.Count;
            }

            NumberingFormat numberingFormat = new NumberingFormat();

            if (groupingSize != null)
            {
                try {
                    numberingFormat.setGroupingSize(Convert.ToInt32(groupingSize));
                }
                catch (System.OverflowException) {}
            }
            if (groupingSep != null)
            {
                numberingFormat.setGroupingSeparator(groupingSep);
            }
            if (0 < cFormats)
            {
                FormatInfo prefix = (FormatInfo)formatlist[0];
                Debug.Assert(prefix == null || prefix._fIsSeparator);
                FormatInfo sufix = null;
                if (cFormats % 2 == 1)
                {
                    sufix = (FormatInfo)formatlist[cFormats - 1];
                    cFormats--;
                }
                FormatInfo periodicSeparator = 2 < cFormats ? (FormatInfo)formatlist[cFormats - 2] : DefaultSeparator;
                FormatInfo periodicFormat    = 0 < cFormats ? (FormatInfo)formatlist[cFormats - 1] : DefaultFormat;
                if (prefix != null)
                {
                    result.Append(prefix._wszSeparator);
                }
                int numberlistCount = numberlist.Count;
                for (int i = 0; i < numberlistCount; i++)
                {
                    int  formatIndex = i * 2;
                    bool haveFormat  = formatIndex < cFormats;
                    if (0 < i)
                    {
                        FormatInfo thisSeparator = haveFormat ? (FormatInfo)formatlist[formatIndex + 0] : periodicSeparator;
                        Debug.Assert(thisSeparator._fIsSeparator);
                        result.Append(thisSeparator._wszSeparator);
                    }

                    FormatInfo thisFormat = haveFormat ? (FormatInfo)formatlist[formatIndex + 1] : periodicFormat;
                    Debug.Assert(!thisFormat._fIsSeparator);

                    //numberingFormat.setletter(this.letter);
                    //numberingFormat.setLang(this.lang);

                    numberingFormat.setNumberingType(thisFormat._numberingType);
                    numberingFormat.setMinLen(thisFormat._cMinLen);
                    result.Append(numberingFormat.format((double)numberlist[i]));
                }

                if (sufix != null)
                {
                    result.Append(sufix._wszSeparator);
                }
            }
            else
            {
                numberingFormat.setNumberingType(MSONFC.msonfcArabic);
                for (int i = 0; i < numberlist.Count; i++)
                {
                    if (i != 0)
                    {
                        result.Append(".");
                    }
                    result.Append(numberingFormat.format((double)numberlist[i]));
                }
            }
            return(result.ToString());
        }
Exemple #3
0
        private static string Format(ArrayList numberlist, ArrayList formatlist, string lang, string letter, string groupingSep, string groupingSize) {
            StringBuilder result = new StringBuilder();
            int cFormats = 0;
            if (formatlist != null) {
                cFormats = formatlist.Count;
            }
                        
            NumberingFormat numberingFormat = new NumberingFormat();
            if (groupingSize != null) {
                try {
                    numberingFormat.setGroupingSize(Convert.ToInt32(groupingSize));
                }
                catch (System.OverflowException) {}
            }
            if (groupingSep != null) {
                numberingFormat.setGroupingSeparator(groupingSep);
            }
            if (cFormats > 0) {
                //numberingFormat.setletter(this.letter);
                //numberingFormat.setLang(this.lang);
                
                int numberlistCount = numberlist.Count;
                FormatInfo pFormatToken = null;
                FormatInfo pFormatInfo = formatlist[0] as FormatInfo;
                int index = 0;
                for(int i = 0; i < numberlistCount; i++ ) {
                    if (pFormatInfo._fIsSeparator){
                        result.Append(pFormatInfo._wszSeparator);

                        if (cFormats > 1) {
                            pFormatToken = formatlist[++index] as FormatInfo;

                             if (cFormats > 3) {
                                // Use the next format pair (otherwise use same pair over again)
                                pFormatInfo = formatlist[++index] as FormatInfo;
                                cFormats -= 2;
                            }
                        }
                        else {
                            // Format string consists of a lone separator.  Use "1" as format token.
                            Debug.Assert(cFormats == 1);
                            pFormatToken = DefaultFormat;
                        }
                    }
                    else {
                        // Format string begins with format token, not a separator
                        if (i != 0) {
                            // Default separator token is period
                            result.Append(".");
                        }

                        pFormatToken = pFormatInfo;
                        if (cFormats > 2){
                            // Use the succeeding pair
                            pFormatInfo = formatlist[++index] as FormatInfo;
                            cFormats--;
                        }
                    }

                    numberingFormat.setNumberingType(pFormatToken._numberingType);
                    numberingFormat.setMinLen(pFormatToken._cMinLen);
                    result.Append(numberingFormat.format(Convert.ToDouble(numberlist[i])));
                } 

                if (numberlistCount == 0 && pFormatInfo._fIsSeparator){
                    // If we had no counts, then write out beginning separator, if it exists
                    result.Append(pFormatInfo._wszSeparator);
                }

                if (numberlistCount != 0 || cFormats > 1) {
                    // If we have at least one count, find last entry in format             information array
                    Debug.Assert(cFormats >= 1);
                    pFormatInfo = formatlist[formatlist.Count - 1] as FormatInfo;
                    // If last entry is a separator, always write it out
                    if (pFormatInfo._fIsSeparator){
                        result.Append(pFormatInfo._wszSeparator);
                    }
                }
            }
            else {
                numberingFormat.setNumberingType(MSONFC.msonfcArabic);
                for (int i = 0; i < numberlist.Count; i++) {
                    if (i != 0) {
                        result.Append(".");
                    }
                    result.Append(numberingFormat.format(Convert.ToDouble(numberlist[i])));
                }
            }
            return result.ToString();
        }
        // SDUB: perf.
        // for each call to xsl:number Format() will build new NumberingFormat object.
        // in case of no AVTs we can build this object at compile time and reuse it on execution time.
        // even partial step in this derection will be usefull (when cFormats == 0)

        private static string Format(ArrayList numberlist, List <FormatInfo> tokens, string lang, string letter, string groupingSep, string groupingSize)
        {
            StringBuilder result   = new StringBuilder();
            int           cFormats = 0;

            if (tokens != null)
            {
                cFormats = tokens.Count;
            }

            NumberingFormat numberingFormat = new NumberingFormat();

            if (groupingSize != null)
            {
                try
                {
                    numberingFormat.setGroupingSize(Convert.ToInt32(groupingSize, CultureInfo.InvariantCulture));
                }
                catch (System.FormatException) { }
                catch (System.OverflowException) { }
            }
            if (groupingSep != null)
            {
                if (groupingSep.Length > 1)
                {
                    // It is a breaking change to throw an exception, SQLBUDT 324367
                    //throw XsltException.Create(SR.Xslt_CharAttribute, "grouping-separator");
                }
                numberingFormat.setGroupingSeparator(groupingSep);
            }
            if (0 < cFormats)
            {
                FormatInfo prefix = tokens[0];
                Debug.Assert(prefix == null || prefix.isSeparator);
                FormatInfo sufix = null;
                if (cFormats % 2 == 1)
                {
                    sufix = tokens[cFormats - 1];
                    cFormats--;
                }
                FormatInfo periodicSeparator = 2 < cFormats ? tokens[cFormats - 2] : s_defaultSeparator;
                FormatInfo periodicFormat    = 0 < cFormats ? tokens[cFormats - 1] : s_defaultFormat;
                if (prefix != null)
                {
                    result.Append(prefix.formatString);
                }
                int numberlistCount = numberlist.Count;
                for (int i = 0; i < numberlistCount; i++)
                {
                    int  formatIndex = i * 2;
                    bool haveFormat  = formatIndex < cFormats;
                    if (0 < i)
                    {
                        FormatInfo thisSeparator = haveFormat ? tokens[formatIndex + 0] : periodicSeparator;
                        Debug.Assert(thisSeparator.isSeparator);
                        result.Append(thisSeparator.formatString);
                    }

                    FormatInfo thisFormat = haveFormat ? tokens[formatIndex + 1] : periodicFormat;
                    Debug.Assert(!thisFormat.isSeparator);

                    //numberingFormat.setletter(this.letter);
                    //numberingFormat.setLang(this.lang);

                    numberingFormat.setNumberingType(thisFormat.numSequence);
                    numberingFormat.setMinLen(thisFormat.length);
                    result.Append(numberingFormat.FormatItem(numberlist[i]));
                }

                if (sufix != null)
                {
                    result.Append(sufix.formatString);
                }
            }
            else
            {
                numberingFormat.setNumberingType(NumberingSequence.Arabic);
                for (int i = 0; i < numberlist.Count; i++)
                {
                    if (i != 0)
                    {
                        result.Append('.');
                    }
                    result.Append(numberingFormat.FormatItem(numberlist[i]));
                }
            }
            return(result.ToString());
        }
Exemple #5
0
        private static string Format(ArrayList numberlist, ArrayList formatlist, string lang, string letter, string groupingSep, string groupingSize)
        {
            StringBuilder result   = new StringBuilder();
            int           cFormats = 0;

            if (formatlist != null)
            {
                cFormats = formatlist.Count;
            }

            NumberingFormat numberingFormat = new NumberingFormat();

            if (groupingSize != null)
            {
                try {
                    numberingFormat.setGroupingSize(Convert.ToInt32(groupingSize));
                }
                catch (System.OverflowException) {}
            }
            if (groupingSep != null)
            {
                numberingFormat.setGroupingSeparator(groupingSep);
            }
            if (cFormats > 0)
            {
                //numberingFormat.setletter(this.letter);
                //numberingFormat.setLang(this.lang);

                int        numberlistCount = numberlist.Count;
                FormatInfo pFormatToken    = null;
                FormatInfo pFormatInfo     = formatlist[0] as FormatInfo;
                int        index           = 0;
                for (int i = 0; i < numberlistCount; i++)
                {
                    if (pFormatInfo._fIsSeparator)
                    {
                        result.Append(pFormatInfo._wszSeparator);

                        if (cFormats > 1)
                        {
                            pFormatToken = formatlist[++index] as FormatInfo;

                            if (cFormats > 3)
                            {
                                // Use the next format pair (otherwise use same pair over again)
                                pFormatInfo = formatlist[++index] as FormatInfo;
                                cFormats   -= 2;
                            }
                        }
                        else
                        {
                            // Format string consists of a lone separator.  Use "1" as format token.
                            Debug.Assert(cFormats == 1);
                            pFormatToken = DefaultFormat;
                        }
                    }
                    else
                    {
                        // Format string begins with format token, not a separator
                        if (i != 0)
                        {
                            // Default separator token is period
                            result.Append(".");
                        }

                        pFormatToken = pFormatInfo;
                        if (cFormats > 2)
                        {
                            // Use the succeeding pair
                            pFormatInfo = formatlist[++index] as FormatInfo;
                            cFormats--;
                        }
                    }

                    numberingFormat.setNumberingType(pFormatToken._numberingType);
                    numberingFormat.setMinLen(pFormatToken._cMinLen);
                    result.Append(numberingFormat.format(Convert.ToDouble(numberlist[i])));
                }

                if (numberlistCount == 0 && pFormatInfo._fIsSeparator)
                {
                    // If we had no counts, then write out beginning separator, if it exists
                    result.Append(pFormatInfo._wszSeparator);
                }

                if (numberlistCount != 0 || cFormats > 1)
                {
                    // If we have at least one count, find last entry in format             information array
                    Debug.Assert(cFormats >= 1);
                    pFormatInfo = formatlist[formatlist.Count - 1] as FormatInfo;
                    // If last entry is a separator, always write it out
                    if (pFormatInfo._fIsSeparator)
                    {
                        result.Append(pFormatInfo._wszSeparator);
                    }
                }
            }
            else
            {
                numberingFormat.setNumberingType(MSONFC.msonfcArabic);
                for (int i = 0; i < numberlist.Count; i++)
                {
                    if (i != 0)
                    {
                        result.Append(".");
                    }
                    result.Append(numberingFormat.format(Convert.ToDouble(numberlist[i])));
                }
            }
            return(result.ToString());
        }