public ParseResult <Offset> ParsePartial(ValueCursor cursor)
            {
                int startIndex = cursor.Index;
                // TODO: Do better than this. It's horrible, and may well be invalid
                // for some cultures. Or just remove the NumberPattern from 2.0...
                int longestPossible = Math.Min(maxLength, cursor.Length - cursor.Index);

                for (int length = longestPossible; length >= 0; length--)
                {
                    string candidate = cursor.Value.Substring(cursor.Index, length);
                    int    milliseconds;
                    if (Int32.TryParse(candidate, NumberStyles.Integer | NumberStyles.AllowThousands,
                                       formatInfo.NumberFormat, out milliseconds))
                    {
                        if (milliseconds < -NodaConstants.MillisecondsPerStandardDay ||
                            NodaConstants.MillisecondsPerStandardDay < milliseconds)
                        {
                            cursor.Move(startIndex);
                            return(ParseResult <Offset> .ValueOutOfRange(cursor, milliseconds));
                        }
                        cursor.Move(cursor.Index + length);
                        return(ParseResult <Offset> .ForValue(Offset.FromMilliseconds(milliseconds)));
                    }
                }
                cursor.Move(startIndex);
                return(ParseResult <Offset> .CannotParseValue(cursor, "n"));
            }
            public ParseResult <Offset> Parse(string text)
            {
                int milliseconds;

                if (Int32.TryParse(text, NumberStyles.Integer | NumberStyles.AllowThousands,
                                   formatInfo.NumberFormat, out milliseconds))
                {
                    if (milliseconds < -NodaConstants.MillisecondsPerStandardDay ||
                        NodaConstants.MillisecondsPerStandardDay < milliseconds)
                    {
                        return(ParseResult <Offset> .ValueOutOfRange(new ValueCursor(text), milliseconds));
                    }
                    return(ParseResult <Offset> .ForValue(Offset.FromMilliseconds(milliseconds)));
                }
                return(ParseResult <Offset> .CannotParseValue(new ValueCursor(text), "n"));
            }
Beispiel #3
0
        private ParseResult <T> BuildNumberOutOfRangeResult <T>(int startIndex)
        {
            Move(startIndex);
            if (Current == '-')
            {
                MoveNext();
            }
            // End of string works like not finding a digit.
            while (GetDigit() != -1)
            {
                MoveNext();
            }
            string badValue = Value.Substring(startIndex, Index - startIndex);

            Move(startIndex);
            return(ParseResult <T> .ValueOutOfRange(this, badValue));
        }