예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
 public string ScanBoneName(IniToken token) => token.Text;
예제 #5
0
 private float ScanPercentage(IniToken token) => ScanFloat(token);
예제 #6
0
 public float ScanFloat(IniToken token)
 {
     return(ParseUtility.ParseFloat(GetFloatText(token)));
 }
예제 #7
0
        public bool IsFloat(IniToken token)
        {
            var floatText = GetFloatText(token);

            return(!string.IsNullOrEmpty(floatText) && ParseUtility.TryParseFloat(floatText, out _));
        }
예제 #8
0
 public byte ScanByte(IniToken token) => (byte)ScanInteger(token);
예제 #9
0
 private long ScanLong(IniToken token) => Convert.ToInt64(token.Text);
예제 #10
0
 public uint ScanUnsignedInteger(IniToken token) => Convert.ToUInt32(token.Text);
예제 #11
0
 public int ScanInteger(IniToken token) => Convert.ToInt32(token.Text);
예제 #12
0
 public bool IsInteger(IniToken token) => int.TryParse(token.Text, out _);
예제 #13
0
 public string ScanAssetReference(IniToken token) => token.Text;
예제 #14
0
 private void UnexpectedToken(IniToken token)
 {
     throw new IniParseException($"Unexpected token: {token}", token.Position);
 }