public override long getIntegerValue() { if (Value != null) { return(Value.getIntegerValue()); } return(base.getIntegerValue()); }
/// <summary> /// Formating string: /// 20s - string with padding to 20 chars, left align /// -20s - string with padding to 20 chars, right align /// 2d - integer number padded to 2 chars with spaces, right align /// 02d - integer number padded to 2 chars with zero, right align /// 1.7f - floating point value with at least 1 digit before point and 7 digits after point /// </summary> /// <param name="ph">Input placeholder (without markup substrings, /// this can contain also some formatting after : character</param> /// <returns></returns> public string ReplaceVariablePlaceholder(string ph) { string fmt = ""; int phi = ph.IndexOf(':'); if (phi >= 0) { fmt = ph.Substring(phi + 1); ph = ph.Substring(0, phi); } GSCore cs = EvaluateProperty(ph); if (fmt.EndsWith("s")) { string value = cs.getStringValue(); int places; if (int.TryParse(fmt.Substring(0, fmt.Length - 1), out places)) { if (places > 0) { value = value.PadRight(places); } else { value = value.PadLeft(-places); } } return(value); } else if (fmt.EndsWith("m")) { string value = cs.getStringValue(); int places; if (int.TryParse(fmt.Substring(0, fmt.Length - 1), out places)) { if (value.Length > places) { value = value.Substring(0, places - 3) + "..."; } else { if (places > 0) { value = value.PadRight(places); } else { value = value.PadLeft(-places); } } } return(value); } else if (fmt.EndsWith("d")) { bool padWithZero = false; int places; string result = ""; long ival = cs.getIntegerValue(); if (int.TryParse(fmt.Substring(0, fmt.Length - 1), out places)) { if (fmt.StartsWith("0")) { padWithZero = true; } if (padWithZero) { result = string.Format("{0:0".PadRight(places - 1, '0') + "}", ival); result = result.PadLeft(places, '0'); } else { result = string.Format("{0:#".PadRight(places - 1, '#') + "}", ival); result = result.PadLeft(places, ' '); } } else { result = ival.ToString(); } return(result); } else if (fmt.EndsWith("f")) { string a, b; fmt = fmt.Substring(0, fmt.Length - 1); int i = fmt.IndexOf('.'); if (i >= 0) { a = fmt.Substring(0, i); b = fmt.Substring(i + 1); } else { a = fmt; b = "0"; } int ia, ib; double d = cs.getDoubleValue(); string result; if (int.TryParse(a, out ia) && int.TryParse(b, out ib)) { result = string.Format("{0:" + string.Format("F{0}", ib) + "}", d); result = result.PadLeft(ia + ib + 1); } else { result = d.ToString(); } return(result); } else { return(cs.getStringValue()); } }