Ejemplo n.º 1
0
 public CellNumberStringMod(CellNumberFormatter.Special start, bool startInclusive, CellNumberFormatter.Special end, bool endInclusive)
 {
     special             = start;
     this.startInclusive = startInclusive;
     this.end            = end;
     this.endInclusive   = endInclusive;
     op    = REPLACE;
     toAdd = "";
 }
Ejemplo n.º 2
0
 private CellNumberFormatter.Special PreviousNumber()
 {
     for (int i = specials.Count - 1; i >= 0; i--)
     {
         CellNumberFormatter.Special s = specials[i];
         if (IsDigitFmt(s))
         {
             //Special numStart = s;
             CellNumberFormatter.Special last = s;
             while (i >= 0)
             {
                 s = specials[i];
                 if (last.pos - s.pos > 1 || !IsDigitFmt(s)) // it has to be continuous digits
                 {
                     break;
                 }
                 last = s;
                 i--;
             }
             return(last);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
 public CellNumberStringMod(CellNumberFormatter.Special start, bool startInclusive, CellNumberFormatter.Special end, bool endInclusive, char toAdd)
     : this(start, startInclusive, end, endInclusive)
 {
     ;
     this.toAdd = toAdd + "";
 }
Ejemplo n.º 4
0
 public CellNumberStringMod(CellNumberFormatter.Special special, string toAdd, int op)
 {
     this.special = special;
     this.toAdd   = toAdd;
     this.op      = op;
 }
Ejemplo n.º 5
0
        public String HandlePart(Match m, String part, CellFormatType type, StringBuilder descBuf)
        {
            int  pos     = descBuf.Length;
            char firstCh = part[0];

            switch (firstCh)
            {
            case 'e':
            case 'E':
                // See comment in WriteScientific -- exponent handling is complex.
                // (1) When parsing the format, remove the sign from After the 'e' and
                // Put it before the first digit of the exponent.
                if (exponent == null && specials.Count > 0)
                {
                    exponent = new CellNumberFormatter.Special('.', pos);
                    specials.Add(exponent);
                    insertSignForExponent = part[1];
                    return(part.Substring(0, 1));
                }
                break;

            case '0':
            case '?':
            case '#':
                if (insertSignForExponent != '\0')
                {
                    specials.Add(new CellNumberFormatter.Special(insertSignForExponent, pos));
                    descBuf.Append(insertSignForExponent);
                    insertSignForExponent = '\0';
                    pos++;
                }
                for (int i = 0; i < part.Length; i++)
                {
                    char ch = part[i];
                    specials.Add(new CellNumberFormatter.Special(ch, pos + i));
                }
                break;

            case '.':
                if (decimalPoint == null && specials.Count > 0)
                {
                    decimalPoint = new CellNumberFormatter.Special('.', pos);
                    specials.Add(decimalPoint);
                }
                break;

            case '/':
                //!! This assumes there is a numerator and a denominator, but these are actually optional
                if (slash == null && specials.Count > 0)
                {
                    numerator = PreviousNumber();
                    // If the first number in the whole format is the numerator, the
                    // entire number should be printed as an improper fraction
                    improperFraction |= (numerator == FirstDigit(specials));
                    slash             = new CellNumberFormatter.Special('.', pos);
                    specials.Add(slash);
                }
                break;

            case '%':
                // don't need to remember because we don't need to do anything with these
                scale *= 100;
                break;

            default:
                return(null);
            }
            return(part);
        }
Ejemplo n.º 6
0
 private static bool IsDigitFmt(CellNumberFormatter.Special s)
 {
     return(s.ch == '0' || s.ch == '?' || s.ch == '#');
 }