NextWord() public static method

public static NextWord ( string sentence, string &sentenceRemainder ) : string
sentence string
sentenceRemainder string
return string
示例#1
0
        private void InitQuantity(string value, out string remainder)
        {
            var    number   = new StringBuilder();
            var    unit     = new StringBuilder();
            string nextWord = Physical.NextWord(value, out remainder).Trim();

            if (!double.TryParse(nextWord, out _value))
            {
                foreach (char c in nextWord)
                {
                    if (Char.IsNumber(c) || c == PLUS[0] || c == MINUS[0] || c == DECIMAL[0])
                    {
                        number.Append(c);
                    }
                    else
                    {
                        unit.Append(c);
                    }
                }
                double.TryParse(number.ToString(), out _value);
            }
            else
            {
                unit.Append(Physical.NextWord(remainder, out remainder));
            }

            _unit = new StandardUnit(unit.ToString());
            _unit.ValueChanged += _unit_ValueChanged;
        }
示例#2
0
        public QualifiedQuantity(string value, out string remainder)
        {
            if (Char.IsLetter(value[0]))
            {
                string q = Physical.NextWord(value, out remainder);
                if (!Physical.IsQualifier(q))
                {
                    throw new Exception(String.Format("Unknown Qualifier: {0}", q));
                }
                _hasQualifier = Enum.TryParse(q, true, out _qualifier);
            }

            _anyQuantity = new Quantity(value, out remainder);
        }
示例#3
0
        private void CreateRange(string value, out string remainder, double magnitude)
        {
            Quantity qty1;
            Quantity qty2;

            string nextWord = remainder = value.Trim(); //Physical.NextWord(value, out remainder);

            _magnitude = magnitude;

            if (nextWord.ToLower().StartsWith("range"))
            {
                nextWord = Physical.NextWord(remainder, out remainder);
            }
            if (nextWord.ToLower().StartsWith("max"))
            {
                nextWord    = Physical.NextWord(remainder, out remainder);
                _toQuantity = new Quantity(remainder, out remainder);
            }
            else if (nextWord.ToLower().StartsWith("min"))
            {
                nextWord      = Physical.NextWord(remainder, out remainder);
                _fromQuantity = new Quantity(remainder, out remainder);
            }
            else
            {
                if (nextWord.StartsWith(Quantity.PLUSMINUS1))
                {
                    remainder = CalculateRange(magnitude, nextWord, Quantity.PLUSMINUS1.Length);
                }
                else if (nextWord.StartsWith(Quantity.PLUSMINUS2))
                {
                    remainder = CalculateRange(magnitude, nextWord, Quantity.PLUSMINUS2.Length);
                }
                else
                {
                    _fromQuantity = new UncertainQuantity(remainder, out remainder);
                    string to = Physical.NextWord(remainder, out remainder);
                    _toQuantity = new Quantity(remainder, out remainder);
                }
            }
            if (ErrorLimit.IsErrorLimit(remainder))
            {
                _errorLimit = new ErrorLimit(remainder, out remainder);
            }
        }
示例#4
0
        public ErrorLimit(string value, out string remainder)
        {
            string nextWord = remainder = value.Trim(); //Physical.NextWord(value, out remainder);

            if (nextWord.ToLower().StartsWith("errlmt"))
            {
                nextWord = Physical.NextWord(nextWord, out remainder).Trim();
            }
            if (remainder.StartsWith(Quantity.PLUSMINUS1))
            {
                nextWord       = remainder;
                _minusQuantity = new Quantity(Quantity.MINUS + nextWord.Substring(1), out remainder);
                _plusQuantity  = new Quantity(nextWord.Substring(1), out remainder);
            }
            else if (remainder.StartsWith(Quantity.PLUSMINUS2))
            {
                nextWord       = remainder;
                _minusQuantity = new Quantity(Quantity.MINUS + nextWord.Substring(2), out remainder);
                _plusQuantity  = new Quantity(nextWord.Substring(2), out remainder);
            }
            else if (remainder.StartsWith(Quantity.PLUS))
            {
                string plusVal = remainder.Substring(1);
                _plusQuantity = new Quantity(plusVal, out remainder);
                if (remainder.StartsWith(Quantity.MINUS))
                {
                    _minusQuantity = new Quantity(remainder, out remainder);
                }
                else if (remainder.Length > 0 && Char.IsNumber(remainder[0]))
                {
                    throw new Exception(string.Format("Missing sign on the second error limit value. {0}", remainder));
                }
                else
                {
                    _plusQuantity = new Quantity(Quantity.MINUS + plusVal, out remainder);
                }
            }
            else if (remainder.StartsWith(Quantity.MINUS))
            {
                string minusVal = remainder;
                _minusQuantity = new Quantity(minusVal, out remainder);
                if (remainder.StartsWith(Quantity.PLUS))
                {
                    _plusQuantity = new Quantity(remainder.Substring(1), out remainder);
                }
                else if (remainder.Length > 0 && Char.IsNumber(remainder[0]))
                {
                    throw new Exception(string.Format("Missing sign on the second error limit value. {0}", remainder));
                }
                else
                {
                    _plusQuantity = new Quantity(minusVal.Substring(1), out remainder);
                }
            }
            else
            {
                nextWord       = remainder;
                _minusQuantity = new Quantity(Quantity.MINUS + nextWord, out remainder);
                _plusQuantity  = new Quantity(nextWord, out remainder);
            }

            if (!string.IsNullOrEmpty(remainder) && Physical.IsConfidence(remainder))
            {
                string key = Physical.NextWord(remainder, out remainder);
                _confidence = new Quantity(remainder, out remainder);
            }

            if (!string.IsNullOrEmpty(remainder) && Physical.IsResolution(remainder))
            {
                string key = Physical.NextWord(remainder, out remainder);
                _resolution = new Quantity(remainder, out remainder);
            }

            if (_confidence != null)
            {
                _confidence.ValueChanged += delegate { OnValueChanged(); }
            }
            ;
            if (_plusQuantity != null)
            {
                _plusQuantity.ValueChanged += delegate { OnValueChanged(); }
            }
            ;
            if (_minusQuantity != null)
            {
                _minusQuantity.ValueChanged += delegate { OnValueChanged(); }
            }
            ;
            if (_resolution != null)
            {
                _resolution.ValueChanged += delegate { OnValueChanged(); }
            }
            ;
        }