Esempio n. 1
0
        public static bool TryParse(ref string error, string input, out FloatList data)
        {
            data = null;
            List <float> values = new List <float>();
            int          i      = 0;

            BurnWhiteSpace(ref i, input);
            var length = input.Length;

            while (i < length)
            {
                float p                   = 0;
                char  c                   = input[i];
                bool  exponential         = false;
                bool  negative            = false;
                bool  negativeExponential = false;
                // Read in the Data
                int pastDecimal = -1;
                int exponent    = 0;
                p = 0;
                do
                {
                    if (exponential)
                    {
                        if (c == '-')
                        {
                            negativeExponential = true;
                        }
                        else if (c == '+')
                        {
                            // do nothing
                        }
                        else if ((c <'0' | c> '9'))
                        {
                            error = "We found a " + c + " while trying to read in the data!";
                            return(false);
                        }
                        else
                        {
                            exponent = exponent * 10 + (c - '0');
                        }
                    }
                    else
                    {
                        if ((c == '.'))
                        {
                            pastDecimal = 0;
                        }
                        else
                        {
                            if (c == 'e' | c == 'E')
                            {
                                exponential = true;
                            }
                            else if (c == '-')
                            {
                                negative = true;
                            }
                            else if ((c <'0' | c> '9'))
                            {
                                error = "We found a " + c + " while trying to read in the data!";
                                return(false);
                            }
                            else
                            {
                                p = p * 10 + (c - '0');
                                if (pastDecimal >= 0)
                                {
                                    pastDecimal++;
                                }
                            }
                        }
                    }
                } while (++i < length && ((c = input[i]) != '\t' & c != '\n' & c != '\r' & c != ' ' & c != ','));
                if (negativeExponential)
                {
                    exponent = -exponent;
                }
                if (pastDecimal > 0)
                {
                    p = p * (float)Math.Pow(0.1, pastDecimal - exponent);
                }
                if (negative)
                {
                    p = -p;
                }
                BurnWhiteSpace(ref i, input);
                values.Add(p);
            }
            data        = new FloatList();
            data.Values = values.ToArray();
            return(true);
        }
Esempio n. 2
0
        public static bool TryParse(string input, out FloatList data)
        {
            string error = null;

            return(TryParse(ref error, input, out data));
        }