private static string GetFloatText(IniToken token) { var floatText = string.Empty; var seenDot = false; foreach (var c in token.Text) { if (!char.IsDigit(c) && c != '.' && c != '-') { break; } if (c == '.') { if (seenDot) { break; } else { seenDot = true; } } floatText += c; } return(floatText); }
public static T ParseEnum<T>(IniToken token) where T : struct { var stringToValueMap = GetEnumMap<T>(); if (stringToValueMap.TryGetValue(token.Text.ToUpper(), out var enumValue)) return (T)(object)enumValue; throw new IniParseException($"Invalid value for type '{typeof(T).Name}': '{token.Text}'", token.Position); }
private bool ScanBoolean(IniToken token) { switch (token.Text.ToUpperInvariant()) { case "YES": return(true); case "NO": return(false); default: throw new IniParseException($"Invalid value for boolean: '{token.Text}'", token.Position); } }
public string ScanBoneName(IniToken token) => token.Text;
private float ScanPercentage(IniToken token) => ScanFloat(token);
public float ScanFloat(IniToken token) { return(ParseUtility.ParseFloat(GetFloatText(token))); }
public bool IsFloat(IniToken token) { var floatText = GetFloatText(token); return(!string.IsNullOrEmpty(floatText) && ParseUtility.TryParseFloat(floatText, out _)); }
public byte ScanByte(IniToken token) => (byte)ScanInteger(token);
private long ScanLong(IniToken token) => Convert.ToInt64(token.Text);
public uint ScanUnsignedInteger(IniToken token) => Convert.ToUInt32(token.Text);
public int ScanInteger(IniToken token) => Convert.ToInt32(token.Text);
public bool IsInteger(IniToken token) => int.TryParse(token.Text, out _);
public string ScanAssetReference(IniToken token) => token.Text;
private void UnexpectedToken(IniToken token) { throw new IniParseException($"Unexpected token: {token}", token.Position); }