public void OutputState(ValueFormat format) { Console.ForegroundColor = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ConsoleColor.Black : ConsoleColor.White; if (Bus.Driver == this) { Console.ForegroundColor = ConsoleColor.Red; } if (busInputLine != null && busInputLine.State) { Console.ForegroundColor = ConsoleColor.Blue; } Console.SetCursorPosition(ConsoleXY.X, ConsoleXY.Y); Console.Write("|-----------------------|"); Console.SetCursorPosition(ConsoleXY.X, ConsoleXY.Y + 1); Console.Write("| |"); Console.SetCursorPosition(ConsoleXY.X, ConsoleXY.Y + 1); switch (format) { case ValueFormat.Hex: Console.Write(String.Format("|RAM: 0x{0:X2}", Value)); break; case ValueFormat.Decimal: Console.Write(String.Format("|RAM: {0}", Value)); break; case ValueFormat.Binary: Console.Write(String.Format("|RAM: {0}", BinaryValue)); break; } Console.SetCursorPosition(ConsoleXY.X, ConsoleXY.Y + 2); Console.Write("|-----------------------|"); }
public EvaluateRequestArguments(string expression, long?frameId = null, ContextType?context = null, ValueFormat format = null) { this.Expression = expression; this.FrameId = frameId; this.Context = context; this.Format = format; }
internal static EventParameter Read(BinaryReader reader) { string name = reader.ReadString(); ValueFormat format = (ValueFormat)reader.ReadInt32(); switch (format) { case ValueFormat.SystemXml: return(ReadSystemXmlParameter(reader, name)); case ValueFormat.LinkMeXml: return(ReadLinkMeXmlParameter(reader, name)); case ValueFormat.SystemBinary: return(ReadSystemBinaryParameter(reader, name)); case ValueFormat.LinkMeBinary: return(ReadLinkMeBinaryParameter(reader, name)); case ValueFormat.String: return(ReadStringParameter(reader, name)); default: return(ReadRawParameter(reader, name)); } }
private EventParameter(string name, string className, object value, ValueFormat valueFormat) { m_name = name; m_class = className; m_value = value; m_valueFormat = valueFormat; }
private EventParameter(string name, ClassInfo info, object value, ValueFormat valueFormat) { m_name = name; m_class = info.ToString(); m_value = value; m_valueFormat = valueFormat; }
public static string GetFormatString(ValueFormat format) { switch (format) { case ValueFormat.Value: return("VALUE"); case ValueFormat.Score: return("SCORE"); case ValueFormat.TimeSecs: return("SECS"); case ValueFormat.TimeMillisecs: return("MILLISECS"); case ValueFormat.TimeFrames: return("FRAMES"); case ValueFormat.TimeMinutes: return("MINUTES"); case ValueFormat.TimeSecsAsMins: return("SECS_AS_MINS"); case ValueFormat.Other: return("OTHER"); default: return("UNKNOWN"); } }
private void WriteValueInfo(XmlWriteAdaptor adaptor, string className, ValueFormat valueFormat) { adaptor.WriteAttribute(Constants.Xml.ClassAttribute, className); string format; switch (valueFormat) { case ValueFormat.LinkMeXml: format = Constants.Xml.LinkMeFormat; break; case ValueFormat.SystemXml: format = Constants.Xml.SystemFormat; break; case ValueFormat.String: format = Constants.Xml.StringFormat; break; default: format = string.Empty; break; } adaptor.WriteAttribute(Constants.Xml.FormatAttribute, format); }
/// <summary> /// Learns formatting data from source /// </summary> /// <param name="source">The source.</param> public void Learn(MetaTableProperty source) { if (ValueTypeName.isNullOrEmpty()) { ValueTypeName = source.ValueTypeName; } if (ValueFormat.isNullOrEmpty()) { ValueFormat = source.ValueFormat; } if (decimalDelimiter.isNullOrEmpty()) { decimalDelimiter = source.decimalDelimiter; } if (thousantDelimiter.isNullOrEmpty()) { thousantDelimiter = source.thousantDelimiter; } if (ContentType == CellContentType.unknown) { ContentType = source.ContentType; } if (AllContentTypes == CellContentType.unknown) { AllContentTypes = source.AllContentTypes; } factor = source.factor; }
public IProtoSerializerWithWireType TryGetSimpleCoreSerializer(BinaryDataFormat dataFormat, Type type, out WireType defaultWireType) { object dummy = null; ValueFormat format = ValueFormat.Compact; return(TryGetCoreSerializer(dataFormat, type, out defaultWireType, ref format, false, false, false, false, ref dummy)); }
public void ValueFormatEquals() { var target = new ValueFormat(); var target2 = new ValueFormat(); Assert.IsTrue(target2.Equals(target)); }
public void ValueFormatCopyToEquals() { var target = new ValueFormat(); m_ValueFormatGerman.CopyTo(target); Assert.IsTrue(m_ValueFormatGerman.Equals(target)); }
public JSONParser() { this.isObject = new List <bool>(); this.backslashed = false; this.valueFormat = ValueFormat.none; this.afterColon = false; }
public override int GetHashCode() { var builder = new StringBuilder(); builder.AppendLine(TypeDescriptor.Encode(Type)); foreach (var argument in Arguments) { builder.Append(String.Format("{0}=", argument.Name)); if (ValueFormat.GetFormat(argument.Value) == ValueFormats.Array) { var array = argument.Value as Array; if (array == null) { throw new ArgumentException(); } for (var i = 0; i < array.Length; i++) { if (i > 0) { builder.Append(","); } builder.Append(array.GetValue(i)); } } else { builder.Append(argument.Value); } builder.AppendLine(); } return(builder.ToString().GetHashCode()); }
public void ConvertDoubleWithoutFormat() { var format = new ValueFormat(typeof(double)); object value = format.Convert("2.5"); Assert.IsFalse(value is double); }
public virtual RemoteValue Create(RemoteValue remoteProxy, RemoteValue addressOf, SbType typeInfo, string expressionPath, bool hasExpressionPath, uint numChildren, string summary, string typeName, string value, ValueType valueType, bool isPointerType, ValueFormat valueFormat, ulong byteSize) => new CachedValue(remoteProxy, addressOf, typeInfo, expressionPath, hasExpressionPath, numChildren, summary, typeName, value, valueType, isPointerType, valueFormat, byteSize);
public void ConvertDouble() { var format = new ValueFormat(typeof(double), "00.00"); double value = (double)format.Convert("2.5"); Assert.AreEqual(2.5, value); }
public void Init() { var m_ValueFormatGerman = new ValueFormat(); m_ValueFormatGerman.DataType = DataType.DateTime; m_ValueFormatGerman.DateFormat = @"dd/MM/yyyy"; m_ValueFormatGerman.DateSeparator = "."; m_ValueFormatGerman.DecimalSeparator = ","; m_ValueFormatGerman.False = @"Falsch"; m_ValueFormatGerman.GroupSeparator = "."; m_ValueFormatGerman.NumberFormat = "0.##"; m_ValueFormatGerman.TimeSeparator = ":"; m_ValueFormatGerman.True = @"Wahr"; var ff = new CsvFile(); m_Column.Name = "StartDate"; m_Column.Ignore = true; m_Column.ValueFormat = m_ValueFormatGerman; ff.ColumnAdd(m_Column); Assert.AreEqual("StartDate", m_Column.Name, "Name"); Assert.AreEqual(DataType.DateTime, m_Column.DataType, "DataType"); Assert.IsTrue(m_Column.Convert, "Convert"); Assert.IsTrue(m_Column.Ignore, "Ignore"); }
/// <summary> /// Converts a single value to a given format. For typed formats /// this method tries to convert various types of values to a nullable DateTime. /// It also handles parsing strings that are input without a colon for speed entry (e.g. 1500). /// </summary> /// <param name="value">A single value to convert to the given format.</param> /// <param name="format">The value format to convert the value to.</param> /// <returns>The value converted to the given format.</returns> protected override object ConvertValue(object value, ValueFormat format) { if (format.IsTyped() && value is string) { string str = (string)value; int i; if (int.TryParse(str, out i) && i >= 0) { if (i > 23 && i < 60 || i < 24 && MinutesCentric) { return(new DateTime?(DateTime.Parse("0:" + i))); } else if (i < 24) { return(new DateTime?(DateTime.Parse(i + ":0"))); } else if (str.Length == 4) { DateTime dt; if (DateTime.TryParse(str.Substring(0, 2) + ":" + str.Substring(2), out dt)) { return(new DateTime?(dt)); } } } } return(base.ConvertValue(value, format)); }
public Value() { _decValue = 0; _num = 0; _denom = 1; _format = ValueFormat.Default; }
public Value(decimal decValue, ValueFormat format) { _decValue = decValue; _format = format; _num = decValue; _denom = 1; }
/// <summary> /// Returns an unquoted, unescaped version of the result from FormatValue() if that value /// looks like a quoted and escaped string literal. For instance, L"\"foo\\nbar\"" becomes /// "foo\nbar". Returns "" otherwise. /// </summary> public virtual string FormatStringView( RemoteValue remoteValue, ValueFormat fallbackValueFormat) { string value = FormatValue(remoteValue, fallbackValueFormat); return(CStringEscapeHelper.Unescape(value)); }
public SetExpressionRequestArguments(string expression, string value, long?frameId = null, ValueFormat format = null) { this.Expression = expression; this.Value = value; this.FrameId = frameId; this.Format = format; }
public void ConvertString() { var format = new ValueFormat(); object value = format.Convert( "hiho" ); Assert.AreEqual( "hiho", value ); }
public void ConvertString() { var format = new ValueFormat(typeof(string)); object value = format.Convert("hiho"); Assert.AreEqual("hiho", value); }
public void ConvertRegExString() { var format = new ValueFormat( typeof( int ), "000000", new Regex( @"WKN: ([\d]+)" ) ); object value = format.Convert( "WKN: 850206" ); Assert.AreEqual( 850206, (int)value ); }
public void ConvertdoubleWithoutFormat() { var format = new ValueFormat( typeof( double ) ); object value = format.Convert( "2.5" ); Assert.IsFalse( value is double ); }
public void ConvertDouble() { var format = new ValueFormat( typeof( double ), "00.00" ); double value = (double)format.Convert( "2.5" ); Assert.AreEqual( 2.5, value ); }
/// <summary> /// Converts a single value to a given format. For typed formats /// this method tries to convert various types of values to a nullable integer. /// </summary> /// <param name="value">A single value to convert to the given format.</param> /// <param name="format">The value format to convert the value to.</param> /// <returns>The value converted to the given format.</returns> protected override object ConvertValue(object value, ValueFormat format) { if (format.IsTyped()) { if (value is int?) { return(value); } if (value is int) { return((int?)value); } if (value is double) { return((int?)((double)value)); } if (IsValueNull(value, format)) { return(null); } int i; if (int.TryParse(Convert.ToString(value), NumberStyles.Number, null, out i)) { return(i); } } return(base.ConvertValue(value, format)); }
/// <inheritdoc /> public bool Equals([AllowNull] Number other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( ValueFormat == other.ValueFormat || ValueFormat != null && ValueFormat.Equals(other.ValueFormat) ) && ( Font == other.Font || Font != null && Font.Equals(other.Font) ) && ( Prefix == other.Prefix || Prefix != null && Prefix.Equals(other.Prefix) ) && ( Suffix == other.Suffix || Suffix != null && Suffix.Equals(other.Suffix) )); }
public string ToString(ValueFormat format) { if (format == ValueFormat.Scientific) { if (Power >= 3) { return($"{Gain}*10^{Power}"); } else { return($"{Gain}"); } } if (format == ValueFormat.Literal) { var powerName = PowerNamer.GetName(Power); if (string.IsNullOrEmpty(powerName)) { return($"{Gain}"); } else { return($"{Gain} {powerName}"); } } else { //Impossible to reach, convert to switch ?? return(""); } }
/// <summary> /// Adds a new value node to a given folder node. /// </summary> /// <param name="key">the key of the new value node.</param> /// <param name="value">the value.</param> /// <param name="format">the format.</param> /// <param name="root">the folder node.</param> /// <returns>the new value node.</returns> public static IEntry AddValueNode(string key, object value, ValueFormat format, IEntry root) { if (root == null) { throw new RegistryException("root is null"); } if (!root.IsFolder) { throw new RegistryException("root is a value node!"); } var keyExists = root.Contains(key); if (keyExists) { throw new RegistryException("the key already exists."); } var node = root.AddValue(key); node.SetValue(value, format); return(node); }
/// <summary> /// Converts a single value to a given format. For typed formats /// this method tries to convert various types of values to a nullable decimal. /// For string formats it displays the internal decimal formatted according /// to the specified <see cref="DisplayFormat"/> if set. /// </summary> /// <param name="value">A single value to convert to the given format.</param> /// <param name="format">The value format to convert the value to.</param> /// <returns>The value converted to the given format.</returns> protected override object ConvertValue(object value, ValueFormat format) { if (format.IsTyped()) { if (value is decimal?) { return(value); } if (value is decimal) { return((decimal?)value); } if (value is int) { return((decimal?)((int)value)); } if (IsValueNull(value, format)) { return(null); } decimal d; if (decimal.TryParse(Convert.ToString(value), ParseStyles, null, out d)) { return(d); } } if (format == ValueFormat.DisplayString && value is decimal? && !IsValueNull(value, format)) { return(((decimal?)value).Value.ToString(DisplayFormat)); } return(base.ConvertValue(value, format)); }
public SetVariableRequestArguments(long variablesReference, string name, string value, ValueFormat format = null) { this.VariablesReference = variablesReference; this.Name = name; this.Value = value; this.Format = format; }
/// <summary> /// Converts a single value to a given format. For typed formats /// this method tries to convert various types of values to a nullable Guid. /// </summary> /// <param name="value">A single value to convert to the given format.</param> /// <param name="format">The value format to convert the value to.</param> /// <returns>The value converted to the given format.</returns> protected override object ConvertValue(object value, ValueFormat format) { if (format.IsTyped()) { if (value is Guid?) { return(value); } if (value is Guid) { return((Guid?)value); } if (IsValueNull(value, format)) { return(null); } if (Guid.TryParse(Convert.ToString(value), out Guid id)) { return(new Guid?(id)); } if (format == ValueFormat.Transport) { return(null); } } return(base.ConvertValue(value, format)); }
public void ConvertRegExString() { var format = new ValueFormat(typeof(int), "000000", new Regex(@"WKN: ([\d]+)")); object value = format.Convert("WKN: 850206"); Assert.AreEqual(850206, (int)value); }
public void SetLegacyFormat(ref MemberLevelSettingsValue level, MemberInfo member, RuntimeTypeModel model) { Type type = Helpers.GetMemberType(member); ValueFormat legacyFormat = ValueSerializerBuilder.GetDefaultLegacyFormat(type, model); switch (Helpers.GetTypeCode(type)) { // these can't be registered and don't have AsReferenceDefault // explicitely set their asReference = false case ProtoTypeCode.String: case ProtoTypeCode.ByteArray: case ProtoTypeCode.Type: case ProtoTypeCode.Uri: level.Format = legacyFormat; break; default: if (!RuntimeTypeModel.CheckTypeCanBeAdded(model, type)) { // for primitive types - explicitly level.Format = legacyFormat; } break; } }
public static string FormatValue(int value, ValueFormat format) { var output = string.Empty; switch (format) { case ValueFormat.None: output = value.ToString(); break; case ValueFormat.WithSpace: output = value.ToString("# ### ### ##0").Trim(); break; case ValueFormat.WithComma: output = value.ToString("#,### ### ##0").Trim(','); break; case ValueFormat.Time: { var t = TimeSpan.FromSeconds(value); output = string.Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds); } break; case ValueFormat.TimeMinutes: { var t = TimeSpan.FromSeconds(value); output = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds); } break; case ValueFormat.TimeMiliseconds: { var t = TimeSpan.FromMilliseconds(value); output = string.Format("{0:D2}:{1:D2}:{2:D2}`{3:D2}", t.Hours, t.Minutes, t.Seconds, t.Milliseconds); } break; case ValueFormat.TimeMinutesMiliseconds: { var t = TimeSpan.FromMilliseconds(value); output = string.Format("{0:D2}:{1:D2}`{2:D2}", t.Minutes, t.Seconds, t.Milliseconds); } break; } return output; }
public void Copy() { var format = new ValueFormat( typeof( int ), "000.000" ); var copy = new ValueFormat( format ); Assert.AreEqual( typeof( int ), copy.Type ); Assert.AreEqual( "000.000", copy.Format ); }
public void ConvertDateTime() { var format = new ValueFormat( typeof( DateTime ), "dd.MM.yyyy" ); DateTime value = (DateTime)format.Convert( "12.12.2000" ); Assert.AreEqual( 2000, value.Year ); Assert.AreEqual( 12, value.Month ); Assert.AreEqual( 12, value.Day ); }
public void ConvertCurrency() { var format = new ValueFormat( typeof( double ), "000000.00", new Regex( @"([\d.]+)\s*€" ) ); double value = (double)format.Convert( "2.5€" ); Assert.AreEqual( 2.5, value, 0.000001d ); value = (double)format.Convert( "0.25 €" ); Assert.AreEqual( 0.25, value, 0.000001d ); }
/// <summary> /// Converts a single value to a given format. /// For the transport format it uses the header ID converted as an integer. /// </summary> /// <param name="value">A single value to convert to the given format.</param> /// <param name="format">The value format to convert the value to.</param> /// <returns>The value converted to the given format.</returns> protected override object ConvertValue(object value, ValueFormat format) { Header h = value as Header; if (format == ValueFormat.Transport && h != null) { int id; if (Int32.TryParse(h.Id, out id)) return id; } return base.ConvertValue(value, format); }
/// <summary> /// Converts a single value to a given format. /// For the transport format it uses the header ID converted to a boolean. /// </summary> /// <param name="value">A single value to convert to the given format.</param> /// <param name="format">The value format to convert the value to.</param> /// <returns>The value converted to the given format.</returns> protected override object ConvertValue(object value, ValueFormat format) { Header h = value as Header; if (format == ValueFormat.Transport && h != null) { if (BooleanProperty.TrueStrings.Contains(h.Id)) return true; if (BooleanProperty.FalseStrings.Contains(h.Id)) return false; } return base.ConvertValue(value, format); }
public Value(decimal decValue, decimal num, decimal denom, ValueFormat format) { if (denom == 0) throw new Exception("Denominator cannot be zero."); _decValue = decValue; _num = num; _denom = denom; _format = format; SimplifyFraction(); }
/// <summary> /// Converts a single value to a given format. /// For the transport format it uses the header ID converted as a Guid. /// </summary> /// <param name="value">A single value to convert to the given format.</param> /// <param name="format">The value format to convert the value to.</param> /// <returns>The value converted to the given format.</returns> protected override object ConvertValue(object value, ValueFormat format) { Header h = value as Header; if (format == ValueFormat.Transport && h != null) { try { return new Guid(h.Id); } catch (Exception) { } } return base.ConvertValue(value, format); }
public static bool FormatIdentifier(Identifier iden, out string result, ValueFormat nameformat, ValueFormat varformat) { if (!String.IsNullOrEmpty(iden.Name)) { StringBuilder builder=new StringBuilder(128); builder.Append(iden.GetNameFormatted(nameformat)); foreach (ValueVariable val in iden.Children) { builder.Append(' '); builder.Append(val.GetValueFormatted(varformat)); //builder.Append(String.Format("<{0}>", val.TypeName)); } result=builder.ToString(); return true; } else { result=String.Empty; // clear the result string } return false; }
public void Format_GridColumn(GridViewDataTextColumn col, ValueFormat valF) { col.HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center; col.HeaderStyle.Font.Bold = true; col.HeaderStyle.Font.Name = "Arial"; col.HeaderStyle.Font.Size = new FontUnit(9, UnitType.Point); col.CellStyle.Font.Name = "Arial"; col.CellStyle.Font.Size = new FontUnit(9, UnitType.Point); switch (valF) { case ValueFormat.Date: case ValueFormat.DateTime: case ValueFormat.ShortTime: case ValueFormat.Time: col.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center; break; case ValueFormat.Numeric: col.PropertiesEdit.DisplayFormatString = "#,##0"; col.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right; break; } }
public static string FormatValue(int value, ValueFormat format) { var output = string.Empty; switch (format) { case ValueFormat.None: output = value.ToString(); break; case ValueFormat.WithSpace: output = value.ToString("# ### ### ##0").Trim(); break; case ValueFormat.WithComma: output = value.ToString("#,### ### ##0").Trim(','); break; } return output; }
/// <summary> /// Sets the value format for every field. /// </summary> /// <param name="format"></param> public void SetValueFormat( ValueFormat format ) { foreach ( FieldControl fc in _fieldControls ) { fc.ValueFormat = format; } AdjustSize(); }
/// <summary> /// Sets the value format for a specific field. /// </summary> /// <param name="fieldIndex"></param> /// <param name="format"></param> public void SetValueFormat( int fieldIndex, ValueFormat format ) { if ( IsValidFieldIndex( fieldIndex ) ) { _fieldControls[ fieldIndex ].ValueFormat = format; } AdjustSize(); }
public override string GetValueFormatted(ValueFormat format) { string str; if ((format&ValueFormat.VALUE_QUOTE_ALWAYS)!=0 || (format&ValueFormat.STRING_QUOTE_ALWAYS)!=0) str=String.Format("\"{0}\"", _value); else if ((format&ValueFormat.STRING_QUOTE_EMPTY)!=0 && String.IsNullOrEmpty(_value)) return "\"\""; else if ((format&ValueFormat.STRING_QUOTE_WHITESPACE)!=0 && (!String.IsNullOrEmpty(_value) && (_value.IndexOf('\t')>-1 || _value.IndexOf(' ')>-1 || _value.IndexOf('\n')>-1))) str=String.Format("\"{0}\"", _value); else if ((format&ValueFormat.STRING_SAFE_BOOL)!=0 && Variable.VariableToBool(this)!=-1) str=String.Format("\"{0}\"", _value); else if ((format&ValueFormat.STRING_SAFE_NUMBER)!=0 && isNumeric(true)) str=String.Format("\"{0}\"", _value); else if ((format&ValueFormat.STRING_QUOTE_CONTROL)!=0 && (_value.IndexOf(CHAR_OPENBRACE)>-1 || _value.IndexOf(CHAR_CLOSEBRACE)>-1 || _value.IndexOf(CHAR_EQUALSIGN)>-1)) str=String.Format("\"{0}\"", _value); else str=_value; return Variable.EscapeString(str, format); }
public abstract string GetValueFormatted(ValueFormat format);
public override string GetValueFormatted(ValueFormat format) { if ((format&ValueFormat.VALUE_QUOTE_ALWAYS)!=0) return String.Format("\"{0:0.0###}\"", _value); return _value.ToString("0.0###"); }
public override string GetValueFormatted(ValueFormat format) { if ((format&ValueFormat.VALUE_QUOTE_ALWAYS)!=0) { return String.Format("\"{0}\"", _value); } return _value.ToString(); }
public string GetNameFormatted(ValueFormat format) { string str; if ((format&ValueFormat.VALUE_QUOTE_ALWAYS)!=0) str=String.Format("\"{0}\"", _name); else if ((format&ValueFormat.STRING_QUOTE_EMPTY)!=0 && String.IsNullOrEmpty(_name)) return "\"\""; else if ((format&ValueFormat.STRING_QUOTE_WHITESPACE)!=0 && (!String.IsNullOrEmpty(_name) && (_name.IndexOf('\t')>-1 || _name.IndexOf(' ')>-1 || _name.IndexOf('\n')>-1))) str=String.Format("\"{0}\"", _name); else if ((format&ValueFormat.STRING_QUOTE_CONTROL)!=0 && (_name.IndexOf(CHAR_OPENBRACE)>-1 || _name.IndexOf(CHAR_CLOSEBRACE)>-1 || _name.IndexOf(CHAR_EQUALSIGN)>-1)) str=String.Format("\"{0}\"", _name); else str=_name; return EscapeString(str, format); }
public override string GetValueFormatted(ValueFormat format) { if ((format&ValueFormat.VALUE_QUOTE_ALWAYS)!=0 || (format&ValueFormat.BOOL_QUOTE)!=0) return _value ? "\"true\"" : "\"false\""; return _value ? "true" : "false"; }
public static string EscapeString(string str, ValueFormat format) { if (String.IsNullOrEmpty(str) || ((format&ValueFormat.STRING_ESCAPE_OTHER)==0 && (format&ValueFormat.STRING_ESCAPE_CONTROL)==0 && (format&ValueFormat.STRING_ESCAPE_NEWLINE)==0)) { return str; } bool isquoted=(str.Length>=2 && str[0]=='\"' && str[str.Length-1]=='\"' && !str.EndsWith("\\\"")); StringBuilder builder=new StringBuilder(str.Length+32); for (int i=0; i<str.Length; ++i) { char c=str[i]; if ((format&ValueFormat.STRING_ESCAPE_OTHER)!=0) { switch (c) { case CHAR_TAB: if (!isquoted) builder.Append("\\t"); else builder.Append(c); continue; case CHAR_QUOTE: if (/*!isquoted && */(i>0 && i<(str.Length-1))) builder.Append("\\\""); else builder.Append(CHAR_QUOTE); continue; case CHAR_BACKSLASH: if ((i+1)!=str.Length) { char c2=GetEscapeChar(str[i+1]); switch (c2) { case CHAR_BACKSLASH: i++; // we don't want to see the slash again; the continue below makes the i-uppage 2 goto case CHAR_EOF; case CHAR_EOF: builder.Append("\\\\"); break; default: builder.Append('\\'+c2); i++; // already a valid escape sequence break; } } else { builder.Append("\\\\"); } continue; } } if ((format&ValueFormat.STRING_ESCAPE_CONTROL)!=0 && !isquoted) { switch (c) { case CHAR_OPENBRACE: builder.Append("\\{"); continue; case CHAR_CLOSEBRACE: builder.Append("\\}"); continue; case CHAR_EQUALSIGN: builder.Append("\\="); continue; } } if ((format&ValueFormat.STRING_ESCAPE_NEWLINE)!=0 && !isquoted) { switch (c) { case CHAR_NEWLINE: builder.Append("\\n"); continue; case CHAR_CARRIAGERETURN: builder.Append("\\r"); continue; } } builder.Append(c); } return builder.ToString(); }
/// <summary> /// Create an IDictionary containing key->value mappings, where value can be a single string or a string[]. /// </summary> /// <param name="s">the string containing the name-value format</param> /// <param name="option">what kind of value to map to</param> /// <param name="caseInSensitive">true = ignore case</param> /// <returns></returns> /// <remarks> /// Input string format is: /// "key1|value1||key2|value2a|value2b|value2c||key3||key4||key5|value5" /// where names should not be duplicate. Where the value is missing, an empty string is inserted. /// </remarks> public static IDictionary KeyValueMap(this string s, ValueFormat option, bool caseInSensitive) { string[] nvArray = s.Split(_Separator, StringSplitOptions.RemoveEmptyEntries); var map = new HybridDictionary(nvArray.Length, caseInSensitive); foreach (string nv in nvArray) { int p = nv.IndexOf('|'); if (p == -1) { if (option == ValueFormat.Arrays) map[nv] = new string[0]; else map[nv] = string.Empty; } else { string key = nv.Substring(0, p); if (option == ValueFormat.Strings) { map[key] = nv.Substring(p + 1); } else { string[] values = nv.Substring(p + 1).Split('|'); if (option == ValueFormat.Mix && values.Length == 1) map[key] = values[0]; else { for (int k = 0; k < values.Length; k++) if (values[k] == Pilcrow) values[k] = string.Empty; map[key] = values; } } } } return map; }
/// <summary> /// Overrides the base method to construct a list of Guid values for the Transport format. /// </summary> /// <param name="format">The format to create a new list for.</param> /// <returns>A new list for the given format.</returns> protected override IList CreateList(ValueFormat format) { return format == ValueFormat.Transport ? new List<Guid>() : base.CreateList(format); }
public static string FormatValue(int value, ValueFormat format) { return TextComponent.FormatValue((float)value, format); }
public static string FormatValue(float value, ValueFormat format) { var output = string.Empty; switch (format) { case ValueFormat.None: { output = value.ToString(); break; } case ValueFormat.WithSpace: { if (value < 0f) { output = "-" + (-value).ToString("# ### ### ##0").Trim(); } else { output = value.ToString("# ### ### ##0").Trim(); } break; } case ValueFormat.WithComma: { if (value < 0f) { output = "-" + (-value).ToString("#,### ### ##0").Trim(','); } else { output = value.ToString("#,### ### ##0").Trim(','); } break; } case ValueFormat.TimeHMS: { var t = TimeSpan.FromSeconds(value); output = string.Format("{0:D2}:{1:D2}:{2:D2}", t.Hours, t.Minutes, t.Seconds); break; } case ValueFormat.TimeMS: { var t = TimeSpan.FromSeconds(value); output = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds); break; } case ValueFormat.TimeHMSms: { var t = TimeSpan.FromMilliseconds(value); output = string.Format("{0:D2}:{1:D2}:{2:D2}`{3:D2}", t.Hours, t.Minutes, t.Seconds, t.Milliseconds); break; } case ValueFormat.TimeMSms: { var t = TimeSpan.FromMilliseconds(value); output = string.Format("{0:D2}:{1:D2}`{2:D2}", t.Minutes, t.Seconds, t.Milliseconds); break; } } return output; }