ParseInt() public method

Try parsing current as int
public ParseInt ( ) : int
return int
示例#1
0
 /// <summary>
 /// Parses an accessor.
 /// </summary>
 /// <param name="lexer">the lexer to read the tokens from</param>
 /// <param name="defaultFormat">the default format</param>
 /// <returns>the parsed <see cref="IAccessor{T}"/></returns>
 private IAccessor<decimal> ParseAccessor(Lexer lexer, string defaultFormat)
 {
     var start = lexer.ParseInt() - 1;
     var length = lexer.ParseInt();
     var format = defaultFormat;
     if (Formats.Contains(lexer.Current))
     {
         format = lexer.Parse();
     }
     return (IAccessor<decimal>) GetAccessor(start, length, format, Encoding);
 }
示例#2
0
        /// <summary>
        /// Parses an accessor.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>the parsed <see cref="IAccessor{T}"/></returns>
        private IAccessor <decimal> ParseAccessor(Lexer lexer, string defaultFormat)
        {
            var start  = lexer.ParseInt() - 1;
            var length = lexer.ParseInt();
            var format = defaultFormat;

            if (Formats.Contains(lexer.Current) || lexer.Current.StartsWith(AsciiDecimalFormat))
            {
                format = lexer.Parse();
            }
            return((IAccessor <decimal>)GetAccessor(start, length, format, Encoding));
        }
        /// <summary>
        /// Parses an individual comparer.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>a single <see cref="IComparer{T}"/></returns>
        private IComparer <byte[]> ParseComparer(Lexer lexer, string defaultFormat)
        {
            var    start  = lexer.ParseInt() - 1;
            var    length = lexer.ParseInt();
            string format;

            if (lexer.Current == AscendingOrder || lexer.Current == DescendingOrder)
            {
                // if we have the order token no format is specified, thus use the default one
                format = defaultFormat;
            }
            else
            {
                // otherwise the current token is the format
                format = lexer.Parse();
            }
            var ascending = lexer.Current == AscendingOrder;

            IComparer <byte[]> comparer;

            if (format == StringFormat)
            {
                comparer = new StringComparer
                {
                    Encoding     = Encoding,
                    SortEncoding = SortEncoding,
                    Ascending    = ascending,
                    Start        = start,
                    Length       = length
                };
            }
            else
            {
                var accessor = GetAccessor(start, length, format, Encoding) as IAccessor <decimal>;
                comparer = new DefaultComparer <decimal> {
                    Ascending = ascending, Accessor = accessor
                };
            }

            return(comparer);
        }
示例#4
0
        /// <summary>
        /// Parses a sub-formatter
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="outputIndex">the index in the output record for the sub-formatter</param>
        /// <returns>the parsed <see cref="ISubFormatter"/></returns>
        private ISubFormatter ParseSubFormatter(Lexer lexer, ref int outputIndex)
        {
            var element = lexer.Parse();
            var column  = element.IndexOf(':');

            if (column != -1)
            {
                outputIndex = int.Parse(element.Substring(0, column)) - 1;
                element     = element.Substring(column + 1);
            }
            ISubFormatter subFormatter;
            Match         match;

            if ((match = StringConstantRegex.Match(element)).Success)
            {
                var constant = lexer.Parse();
                constant     = constant.Substring(1, constant.Length - 2);
                subFormatter = GetStringConstantFormatter(GetN(match), constant, outputIndex);
            }
            else if ((match = HexOfSpaceRegex.Match(element)).Success)
            {
                if (lexer.Current != null && lexer.Current.StartsWith("'"))
                {
                    subFormatter = GetHexConstantFormatter(GetN(match), lexer.Parse(), outputIndex);
                }
                else
                {
                    subFormatter = GetStringConstantFormatter(GetN(match), " ", outputIndex);
                }
            }
            else
            {
                var start  = int.Parse(element) - 1;
                var length = lexer.ParseInt();
                if (NumberFormats.Contains(lexer.Current))
                {
                    subFormatter = ParseEditFormatter(start, length, outputIndex, lexer);
                }
                else
                {
                    subFormatter = new CopyFormatter
                    {
                        InputIndex  = start,
                        Length      = length,
                        OutputIndex = outputIndex
                    };
                }
            }
            outputIndex += subFormatter.Length;

            return(subFormatter);
        }
示例#5
0
        /// <summary>
        /// Parses an individual comparer.
        /// </summary>
        /// <param name="lexer">the lexer to read the tokens from</param>
        /// <param name="defaultFormat">the default format</param>
        /// <returns>a single <see cref="IComparer{T}"/></returns>
        private IComparer<byte[]> ParseComparer(Lexer lexer, string defaultFormat)
        {
            var start = lexer.ParseInt() - 1;
            var length = lexer.ParseInt();
            string format;

            if (lexer.Current == AscendingOrder || lexer.Current == DescendingOrder)
            {
                // if we have the order token no format is specified, thus use the default one
                format = defaultFormat;
            }
            else
            {
                // otherwise the current token is the format
                format = lexer.Parse();
            }
            var ascending = lexer.Current == AscendingOrder;

            IComparer<byte[]> comparer;
            if (format == StringFormat)
            {
                comparer = new StringComparer
                {
                    Encoding = Encoding,
                    SortEncoding = SortEncoding,
                    Ascending = ascending,
                    Start = start,
                    Length = length
                };
            }
            else
            {
                var accessor = GetAccessor(start, length, format, Encoding) as IAccessor<decimal>;
                comparer = new DefaultComparer<decimal> { Ascending = ascending, Accessor = accessor };
            }

            return comparer;
        }