Beispiel #1
0
        // 60px
        // 6.5em

        private static bool TryParseNumberOrMeasurement(string text, out CssValue?value)
        {
            int unitIndex = -1;

            char point;

            for (int i = 0; i < text.Length; i++)
            {
                point = text[i];

                if (point == ' ' || point == ',')
                {
                    value = null;
                    return(false);
                }

                if (char.IsNumber(point) || point == '.')
                {
                }
                else if (unitIndex == -1)
                {
                    unitIndex = i;
                }
            }

            if (unitIndex > 0)
            {
                value = new CssUnitValue(double.Parse(text.Substring(0, unitIndex), CultureInfo.InvariantCulture), text.Substring(unitIndex));
            }
            else
            {
                value = CssValue.Number(double.Parse(text, CultureInfo.InvariantCulture));
            }

            return(true);
        }