Esempio n. 1
0
        public IActionResult Index()
        {
            StringMod msg = new StringMod()
            {
                Message = "A message is here"
            };

            return(View(msg));
        }
Esempio n. 2
0
        /** {@inheritDoc} */

        public override void FormatValue(StringBuilder toAppendTo, object valueObject)
        {
            double value = ((double)valueObject);

            value *= scale;

            // For negative numbers:
            // - If the cell format has a negative number format, this method
            // is called with a positive value and the number format has
            // the negative formatting required, e.g. minus sign or brackets.
            // - If the cell format does not have a negative number format,
            // this method is called with a negative value and the number is
            // formatted with a minus sign at the start.
            bool negative = value < 0;

            if (negative)
            {
                value = -value;
            }

            // Split out the fractional part if we need to print a fraction
            double fractional = 0;

            if (slash != null)
            {
                if (improperFraction)
                {
                    fractional = value;
                    value      = 0;
                }
                else
                {
                    fractional = value % 1.0;
                    //noinspection SillyAssignment
                    value = (long)value;
                }
            }

            SortedList <StringMod, object> mods = new SortedList <StringMod, object>();
            StringBuilder output = new StringBuilder(desc);

            if (exponent != null)
            {
                WriteScientific(value, output, mods);
            }
            else if (improperFraction)
            {
                WriteFraction(value, null, fractional, output, mods);
            }
            else
            {
                StringBuilder result = new StringBuilder();
                //Formatter f = new Formatter(result);
                //f.Format(LOCALE, printfFmt, value);
                result.Append(value.ToString(printfFmt));
                if (numerator == null)
                {
                    WriteFractional(result, output);
                    Writeint(result, output, integerSpecials, mods,
                             integerCommas);
                }
                else
                {
                    WriteFraction(value, result, fractional, output, mods);
                }
            }

            // Now strip out any remaining '#'s and add any pending text ...
            IEnumerator <Special> it         = specials.GetEnumerator();//.ListIterator();
            IEnumerator           Changes    = mods.Keys.GetEnumerator();
            StringMod             nextChange = (Changes.MoveNext() ? (StringMod)Changes.Current : null);
            int      adjust       = 0;
            BitArray deletedChars = new BitArray(1024); // records chars already deleted

            while (it.MoveNext())
            {
                Special s           = it.Current;
                int     adjustedPos = s.pos + adjust;
                if (!deletedChars[(s.pos)] && output[adjustedPos] == '#')
                {
                    output.Remove(adjustedPos, 1);
                    adjust--;
                    deletedChars.Set(s.pos, true);
                }
                while (nextChange != null && s == nextChange.special)
                {
                    int lenBefore = output.Length;
                    int modPos    = s.pos + adjust;
                    int posTweak  = 0;
                    switch (nextChange.op)
                    {
                    case StringMod.AFTER:
                        // ignore Adding a comma After a deleted char (which was a '#')
                        if (nextChange.toAdd.Equals(",") && deletedChars.Get(s.pos))
                        {
                            break;
                        }
                        posTweak = 1;
                        output.Insert(modPos + posTweak, nextChange.toAdd);
                        break;

                    //noinspection fallthrough
                    case StringMod.BEFORE:
                        output.Insert(modPos + posTweak, nextChange.toAdd);
                        break;

                    case StringMod.REPLACE:
                        int delPos =
                            s.pos;         // delete starting pos in original coordinates
                        if (!nextChange.startInclusive)
                        {
                            delPos++;
                            modPos++;
                        }

                        // Skip over anything already deleted
                        while (deletedChars.Get(delPos))
                        {
                            delPos++;
                            modPos++;
                        }

                        int delEndPos =
                            nextChange.end.pos;         // delete end point in original
                        if (nextChange.endInclusive)
                        {
                            delEndPos++;
                        }

                        int modEndPos =
                            delEndPos + adjust;         // delete end point in current

                        if (modPos < modEndPos)
                        {
                            if (nextChange.toAdd == "")
                            {
                                output.Remove(modPos, modEndPos - modPos);
                            }
                            else
                            {
                                char FillCh = nextChange.toAdd[0];
                                for (int i = modPos; i < modEndPos; i++)
                                {
                                    output[i] = FillCh;
                                }
                            }
                            for (int k = delPos; k < delEndPos; k++)
                            {
                                deletedChars.Set(k, true);
                            }
                            //deletedChars.Set(delPos, delEndPos);
                        }
                        break;

                    default:
                        throw new InvalidOperationException(
                                  "Unknown op: " + nextChange.op);
                    }
                    adjust += output.Length - lenBefore;

                    if (Changes.MoveNext())
                    {
                        nextChange = (StringMod)Changes.Current;
                    }
                    else
                    {
                        nextChange = null;
                    }
                }
            }

            // Finally, add it to the string
            if (negative)
            {
                toAppendTo.Append('-');
            }
            //toAppendTo.Append(value.ToString(format));
            toAppendTo.Append(output);
        }