public static new UnitValueRange Parse(string v, string u)
        {
            ValueQualifier vq = DoubleValue.FindQualifier(ref v);

            string[] parts = v.Split('-');
            double   d1 = Double.NaN, d2 = 0;

            switch (parts.Length)
            {
            case 0:
                d1 = d2 = double.Parse(v);
                break;

            case 1:
                d1 = d2 = double.Parse(parts[0].Trim());
                break;

            case 2:
                d1 = double.Parse(parts[0].Trim());
                d2 = double.Parse(parts[1].Trim());
                break;
            }
            if (!double.IsNaN(d1))
            {
                return(new UnitValueRange(d1, d2, u, vq));
            }
            throw new Exception(String.Format("UnitValueRange.Parse failed: {0}", v));
        }
Example #2
0
        public static UnitValue Parse(string v, string unit)
        {
            if (String.IsNullOrEmpty(v))
            {
                throw new ArgumentException("v cannot be null or empty.");
            }
            ValueQualifier vq = DoubleValue.FindQualifier(ref v);
            double         d;

            //"2.267 moststableallotrope"
            if (double.TryParse(v, out d) || DoubleValue.TryParseScientific(v, out d))
            {
                return(new UnitValue(d, unit, vq));
            }
            throw new ArgumentException("Failed to parse UnitValue: " + v);
        }
Example #3
0
        public UnitValue(string sVal)
        {
            if (String.IsNullOrWhiteSpace(sVal))
            {
                throw new ArgumentException();
            }
            ValueQualifier vq = DoubleValue.FindQualifier(ref sVal);

            foreach (String fs in _falseStarts)
            {
                if (sVal.StartsWith(fs))
                {
                    sVal = sVal.Substring(fs.Length + 1).Trim();
                    break;
                }
            }
            sVal = RemoveBrackets(sVal);
            int  i1 = 0;
            bool dF = false;

            while (i1 < sVal.Length && !IsDigit(sVal[i1], ref dF))
            {
                i1++;
            }
            StringBuilder sb = new StringBuilder();

            dF = false;
            while (i1 < sVal.Length && IsDigit(sVal[i1], ref dF))
            {
                sb.Append(sVal[i1++]);
            }
            if (sb.Length == 0)
            {
                throw new ArgumentException(String.Format("Unable to parse double from string '{0}'.", sVal));
            }
            Value     = double.Parse(sb.ToString());
            sVal      = sVal.Substring(i1).Trim();
            Units     = sVal;
            Qualifier = vq;
        }
Example #4
0
        public static QualifiedString Parse(string v)
        {
            ValueQualifier vq = DoubleValue.FindQualifier(ref v);

            return(new QualifiedString(v.Trim(), vq));
        }