/** * Creates a elapsed time formatter. * * @param pattern The pattern to Parse. */ public CellElapsedFormatter(String pattern) : base(pattern) { specs = new List <TimeSpec>(); StringBuilder desc = CellFormatPart.ParseFormat(pattern, CellFormatType.ELAPSED, new ElapsedPartHandler(this)); //ListIterator<TimeSpec> it = specs.ListIterator(specs.Count); //while (it.HasPrevious()) for (int i = specs.Count - 1; i >= 0; i--) { //TimeSpec spec = it.Previous(); TimeSpec spec = specs[i]; //desc.Replace(spec.pos, spec.pos + spec.len, "%0" + spec.len + "d"); desc.Remove(spec.pos, spec.len); desc.Insert(spec.pos, "D" + spec.len); if (spec.type != topmost.type) { spec.modBy = modFor(spec.type, spec.len); } } printfFmt = desc.ToString(); }
/** * Creates a new object. * * @param format The format. */ private CellFormat(String format) { this.format = format; MatchCollection mc = ONE_PART.Matches(format); List <CellFormatPart> parts = new List <CellFormatPart>(); //while (m.Success) foreach (Match m in mc) { try { String valueDesc = m.Groups[0].Value; // Strip out the semicolon if it's there if (valueDesc.EndsWith(";")) { valueDesc = valueDesc.Substring(0, valueDesc.Length - 1); } parts.Add(new CellFormatPart(valueDesc)); } catch (Exception) { //CellFormatter.logger.Log(Level.WARNING, // "Invalid format: " + CellFormatter.Quote(m.Group()), e); parts.Add(null); } } switch (parts.Count) { case 1: posNumFmt = zeroNumFmt = negNumFmt = parts[(0)]; textFmt = DEFAULT_TEXT_FORMAT; break; case 2: posNumFmt = zeroNumFmt = parts[0]; negNumFmt = parts[1]; textFmt = DEFAULT_TEXT_FORMAT; break; case 3: posNumFmt = parts[0]; zeroNumFmt = parts[1]; negNumFmt = parts[2]; textFmt = DEFAULT_TEXT_FORMAT; break; case 4: default: posNumFmt = parts[0]; zeroNumFmt = parts[1]; negNumFmt = parts[2]; textFmt = parts[3]; break; } }
public String HandlePart(Match m, String part, CellFormatType type, StringBuilder desc) { int pos = desc.Length; char firstCh = part[0]; switch (firstCh) { case '[': if (part.Length < 3) { break; } if (_formatter.topmost != null) { throw new ArgumentException( "Duplicate '[' times in format"); } part = part.ToLower(); int specLen = part.Length - 2; _formatter.topmost = _formatter.AssignSpec(part[1], pos, specLen); return(part.Substring(1, specLen)); case 'h': case 'm': case 's': case '0': part = part.ToLower(); _formatter.AssignSpec(part[0], pos, part.Length); return(part); case '\n': return("%n"); case '\"': part = part.Substring(1, part.Length - 2); break; case '\\': part = part.Substring(1); break; case '*': if (part.Length > 1) { part = CellFormatPart.ExpandChar(part); } break; // An escape we can let it handle because it can't have a '%' case '_': return(null); } // Replace ever "%" with a "%%" so we can use printf //return PERCENTS.Matcher(part).ReplaceAll("%%"); //return PERCENTS.Replace(part, "%%"); return(part); }
/** * Creates a new date formatter with the given specification. * * @param format The format. */ public CellDateFormatter(String format) : base(format) { ; DatePartHandler partHandler = new DatePartHandler(this); StringBuilder descBuf = CellFormatPart.ParseFormat(format, CellFormatType.DATE, partHandler); partHandler.Finish(descBuf); dateFmt = new SimpleDateFormat(descBuf.ToString()); }
public CellTextFormatter(String format) : base(format) { ; int[] numPlaces = new int[1]; PartHandler handler = new PartHandler(numPlaces[0]); desc = CellFormatPart.ParseFormat(format, CellFormatType.TEXT, handler).ToString(); // Remember the "@" positions in last-to-first order (to make insertion easier) textPos = new int[handler.NumPlace]; int pos = desc.Length - 1; for (int i = 0; i < textPos.Length; i++) { textPos[i] = desc.LastIndexOf("\u0000", pos); pos = textPos[i] - 1; } }