Esempio n. 1
0
        private int GetValueIndexForProperty(string property)
        {
            int propertyIndex = rawValue.IndexOf(property, StringComparison.Ordinal);

            if (propertyIndex == -1)
            {
                return(-1);
            }

            CharEnumerator it      = rawValue.GetEnumerator();
            int            counter = 0;

            while (counter <= propertyIndex + property.Length)
            {
                it.MoveNext();
                counter++;
            }
            while (it.Current == ' ' || it.Current == ':')
            {
                it.MoveNext();
                counter++;
            }

            counter--;
            it.Dispose();
            return(counter);
        }
Esempio n. 2
0
        private void ParseBigParanthesesPair(CharEnumerator charSequence, SetableNumberDisk symbol)
        {
            var c = PeekNextChar(charSequence);

            if (c == null || c != '{')
            {
                return;
            }
            var list = new List <char>();

            charSequence.MoveNext();
            while (charSequence.MoveNext() && charSequence.Current != '}')
            {
                list.Add(charSequence.Current);
            }
            int number = -1;

            try {
                number = int.Parse(new string(list.ToArray()));
            }
            catch {
                throw new InvalidExpressionException(
                          @"in  Big Parantheses block must be a number for skip , ex :\d{3}");
            }

            symbol.Skip = number;
        }
Esempio n. 3
0
        private static char Symbol(CharEnumerator chars)
        {
            while (chars.MoveNext())
            {
                if (chars.Current == ';')
                {
                    if (chars.MoveNext())
                    {
                        char s = chars.Current;
                        if (chars.MoveNext())
                        {
                            if (chars.Current == '}')
                            {
                                return(s);
                            }

                            throw new FormatException("The tolerance string representation is not well formatted");
                        }
                        throw new FormatException("The tolerance string representation is not well formatted");
                    }
                    throw new FormatException("The tolerance string representation is not well formatted");
                }
            }
            throw new FormatException("The tolerance string representation is not well formatted");
        }
        protected virtual List <object> GetChildren(CharEnumerator charEnumerator)
        {
            List <object> children = new List <object>();

            while (charEnumerator.MoveNext())
            {
                if (charEnumerator.Current != '<')
                {
                    children.Add(new ParsedText(charEnumerator));
                }

                try {
                    if (charEnumerator.Current == '<' && charEnumerator.MoveNext() && charEnumerator.Current != '/')
                    {
                        children.Add(new ParsedElement(charEnumerator));
                    }
                    else
                    {
                        break;
                    }
                } catch (InvalidOperationException) {
                    break;
                }
            }
            return(children);
        }
        private char[,] CipherWrite(string data, List <int> map)
        {
            CharEnumerator charEnum       = data.GetEnumerator();
            bool           existsNextChar = charEnum.MoveNext();

            char[,] matrix = new char[Key.Length, (int)Math.Ceiling((decimal)data.Length / Key.Length)];
            foreach (int startColumn in map)
            {
                int x = startColumn;
                for (int y = 0; y < matrix.GetLength(1); y++)
                {
                    if (existsNextChar)
                    {
                        matrix[x, y] = charEnum.Current;
                    }
                    if (x == 0)
                    {
                        x = matrix.GetLength(0) - 1;
                    }
                    else
                    {
                        x--;
                    }
                    existsNextChar = charEnum.MoveNext();
                }
            }
            return(matrix);
        }
Esempio n. 6
0
        public static Tuple <int, int> ToNumericCoordinates(string coordinates)
        {
            string first  = string.Empty;
            string second = string.Empty;

            CharEnumerator ce = coordinates.GetEnumerator();

            while (ce.MoveNext())
            {
                if (char.IsLetter(ce.Current))
                {
                    first += ce.Current;
                }
                else
                {
                    second += ce.Current;
                }
            }

            int i = 0;

            ce = first.GetEnumerator();
            while (ce.MoveNext())
            {
                i = (26 * i) + ALPHABET.IndexOf(ce.Current) + 1;
            }

            string str = i.ToString();

            return(Tuple.Create(Convert.ToInt32(second), Convert.ToInt32(str)));
        }
Esempio n. 7
0
    public static double ToNumber(this CharEnumerator enumerator, out bool hasNext)
    {
        var number = 0;

        hasNext = true;
        while (hasNext && Char.IsDigit(enumerator.Current))
        {
            number  = number * 10 + (int)Char.GetNumericValue(enumerator.Current);
            hasNext = enumerator.MoveNext();
        }

        if (!hasNext || enumerator.Current != '.')
        {
            return(number);
        }

        var    rank        = 1;
        double decimalPart = 0;

        hasNext = enumerator.MoveNext();
        while (hasNext && Char.IsDigit(enumerator.Current))
        {
            decimalPart = decimalPart * 10 + (int)Char.GetNumericValue(enumerator.Current);
            rank       *= 10;
            hasNext     = enumerator.MoveNext();
        }
        return(number + (decimalPart / rank));
    }
Esempio n. 8
0
            public static NailNumber Parse(CharEnumerator enumerator)
            {
                NailNumber result = null;

                if (!enumerator.MoveNext())
                {
                    return(null);
                }
                switch (enumerator.Current)
                {
                case '[':
                    var left = NailNumber.Parse(enumerator);
                    enumerator.MoveNext();
                    if (enumerator.Current != ',')
                    {
                        throw new InvalidOperationException("Failed to parse");
                    }
                    var right = NailNumber.Parse(enumerator);
                    enumerator.MoveNext();
                    if (enumerator.Current != ']')
                    {
                        throw new InvalidOperationException("Failed to parse");
                    }

                    result = new NailNumber(left, right);
                    break;

                case >= '0' and <= '9':
                    result = new NailNumber(enumerator.Current - '0');
                    break;
                }
                return(result);
            }
Esempio n. 9
0
        public bool Model(string word, List <char> alphabet)
        {
            if (word.Length == 0 && Finish.Contains(Initial))
            {
                return(true);
            }
            else if (word.Length == 0 && !Finish.Contains(Initial))
            {
                return(false);
            }
            else
            {
                CharEnumerator c = word.GetEnumerator();
                c.MoveNext();
                int letterI   = alphabet.IndexOf(c.Current);
                int nextState = DFATable[Initial][letterI][0];

                while (c.MoveNext())
                {
                    letterI   = alphabet.IndexOf(c.Current);
                    nextState = DFATable[nextState][letterI][0];
                }

                if (Finish.Contains(nextState))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 10
0
        private void ParseConstraint(CharEnumerator @enum, List <IToken> tokens)
        {
            bool done = false;

            @enum.MoveNext(); // eliminar '{'
            var property = new ParsedSegment();

            do
            {
                if (@enum.Current == '}')
                {
                    done = true;
                    break;
                }

                property.Push(@enum.Current);
            } while (@enum.MoveNext());

            RegisterToken(tokens, property);

            if (!done)
            {
                throw new InvalidOperationException("Expect '}'");
            }
        }
Esempio n. 11
0
        string ParseClass(CharEnumerator e, string name = null)
        {
            if (e.Current != 'L')
            {
                return(null);
            }

            var sb = new StringBuilder();

            if (!e.MoveNext())
            {
                throw new FormatException();
            }
            while (e.Current != ';')
            {
                sb.Append(e.Current == '/' ? '.' : e.Current);
                if (!e.MoveNext())
                {
                    throw new FormatException();
                }
            }

            if (name != null)
            {
                sb.Append(' ');
                sb.Append(name);
            }
            return(sb.ToString());
        }
Esempio n. 12
0
        private static bool NextNode(CharEnumerator enumerator, out INode node)
        {
            do
            {
                switch (enumerator.Current)
                {
                case '>':
                    node = new MoveRightNode();
                    return(true);

                case '<':
                    node = new MoveLeftNode();
                    return(true);

                case '+':
                    node = new IncrementNode();
                    return(true);

                case '-':
                    node = new DecrementNode();
                    return(true);

                case ',':
                    node = new InputNode();
                    return(true);

                case '.':
                    node = new OutputNode();
                    return(true);

                case '[':
                    var nodes = new List <INode>();
                    while (enumerator.MoveNext())
                    {
                        switch (enumerator.Current)
                        {
                        case ']':
                            node = new LoopNode(nodes);
                            return(true);

                        default:
                            if (NextNode(enumerator, out var nextNode))
                            {
                                nodes.Add(nextNode);
                            }
                            break;
                        }
                    }
                    throw new InvalidBFProgramException("Expected more symbols after encountering a loop begin symbol", true);

                case ']':
                    throw new InvalidBFProgramException("Encountered a loop end symbol without matching loop begin", false);

                default:
                    break;
                }
            }while (enumerator.MoveNext());
            node = null;
            return(false);
        }
Esempio n. 13
0
        public string BuildTwoByteAddrDataStr(string data)
        {
            string str1   = string.Empty;
            int    length = data.Length;

            if (length > 0)
            {
                string         str2       = string.Empty;
                CharEnumerator enumerator = data.GetEnumerator();
                enumerator.MoveNext();
                uint num = 0U;
                while (num < length)
                {
                    str2 += string.Format("{0:X2}", enumerator.Current);
                    if (((num + 1) % 4) == 0 && num != (length - 1))
                    {
                        str2 = str2 + ":";
                    }
                    ++num;
                    enumerator.MoveNext();
                }
                str1 += str2;
            }
            return(str1);
        }
Esempio n. 14
0
        //关键字或标识符处理
        public Token KeyorIdHandle(CharEnumerator pr)
        {
            char  c;
            Token token = new Token();

            c = pr.Current;
            if (c == '_' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
            {
                buffer.Append(c);
                pr.MoveNext();
                c = pr.Current;
                while (c == '_' || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c <= '9' && c >= '0'))
                {
                    buffer.Append(c);
                    pr.MoveNext();
                    c = pr.Current;
                    //buffer.Append(c);
                    //if (pr.MoveNext())
                    //{
                    //	c = pr.Current;
                    //}
                }
                foreach (var x in keyWord)
                {
                    if (x == buffer.ToString())
                    {
                        if (x == "false" || x == "true")
                        {
                            token.type   = "Bool";
                            token.value  = buffer.ToString();
                            token.Length = buffer.Length;
                            token.p      = pr;
                            buffer.Clear();
                            return(token);
                        }
                        else
                        {
                            token.type   = "Keyword";
                            token.value  = buffer.ToString();
                            token.Length = buffer.Length;
                            token.p      = pr;
                            buffer.Clear();
                            return(token);
                        }
                    }
                }
                token.type   = "ID";
                token.value  = buffer.ToString();
                token.Length = buffer.Length;
                token.p      = pr;
                buffer.Clear();
                return(token);
            }
            token.Length = buffer.Length;
            token.p      = pr;
            buffer.Clear();
            return(token);
        }
Esempio n. 15
0
        /// <summary>
        /// 解析伪类选择器
        /// </summary>
        /// <param name="enumerator">字符枚举器</param>
        /// <returns></returns>
        private static ICssPseudoClassSelector ParsePsedoclassSelector(CharEnumerator enumerator)
        {
            if (enumerator.Current != ':')
            {
                return(null);
            }

            EnsureNext(enumerator);

            var startOffset = enumerator.Offset;

            var name = ParseName(enumerator);

            if (name.IsNullOrEmpty())
            {
                throw FormatError(enumerator);
            }

            if (name.EqualsIgnoreCase("not"))
            {
                return(ParseNegationPseudoClass(enumerator));
            }


            if (enumerator.Current != '(')
            {
                return(CreatePseudoClassSelector(name));
            }

            var i          = 1;
            var argsOffset = enumerator.Offset + 1;

            while (enumerator.MoveNext())
            {
                if (enumerator.Current == '(')
                {
                    i++;
                }

                else if (enumerator.Current == ')')
                {
                    i--;
                }

                if (i == 0)
                {
                    enumerator.MoveNext();

                    var args = enumerator.SubString(argsOffset, enumerator.Offset - argsOffset - 1);

                    return(CreatePseudoClassSelector(name, args));
                }
            }

            throw new FormatException("意外的遇到字符串的结束");
        }
Esempio n. 16
0
 public bool SkipUntil(char c)
 {
     if (HasContent)
     {
     }
     // ReSharper disable once AssignmentInConditionalExpression
     while (HasContent = enumerator.MoveNext() && enumerator.Current != NullChar)
     {
     }
 }
Esempio n. 17
0
        //字符处理
        public Token CharHandle(CharEnumerator pr)
        {
            char  c;
            Token token = new Token();

            c = pr.Current;
            if (c == '\'')
            {
                buffer.Append(c);
                pr.MoveNext();
                c = pr.Current;
                while (c != '\'')
                {
                    buffer.Append(c);
                    if (pr.MoveNext())
                    {
                        c = pr.Current;
                    }
                    else
                    {
                        token.isLast = true;
                        token.type   = "Spelling error";
                        token.value  = buffer.ToString().Substring(0, 2) + "...";
                        token.Length = buffer.Length;
                        token.p      = pr;
                        buffer.Clear();
                        return(token);
                    }
                }
                buffer.Append(c);
                if (buffer.Length - 2 != 1)
                {
                    pr.MoveNext();
                    token.type   = "Spelling error";
                    token.value  = buffer.ToString();
                    token.Length = buffer.Length;
                    token.p      = pr;
                    buffer.Clear();
                    return(token);
                }
                pr.MoveNext();
                token.type   = "Char";
                token.value  = buffer.ToString();
                token.Length = buffer.Length;
                token.p      = pr;
                buffer.Clear();
                return(token);
            }
            token.Length = buffer.Length;
            token.p      = pr;
            buffer.Clear();
            return(token);
        }
Esempio n. 18
0
 private void ConvertItem(CharEnumerator format, int flags)
 {
     if (format.Current == '(')
     {
         format.MoveNext();
         ConvertTuple(format, flags);
         format.MoveNext();
     }
     else
     {
         ConvertSimple(format, flags);
     }
 }
Esempio n. 19
0
        private static string ReadNumber(CharEnumerator e, StringBuilder val, char end)
        {
            val.Append(e.Current);
            var hasE   = false;
            var hasDot = e.Current == '.';

            while (e.MoveNext())
            {
                if (e.Current == '\t' || e.Current == ',' || e.Current == end)
                {
                    break;
                }

                val.Append(e.Current);
                if (e.Current == '.')
                {
                    if (hasDot)
                    {
                        Throw(val);
                    }

                    hasDot = true;
                }
                else if (e.Current == 'e' || e.Current == 'E')
                {
                    if (hasE)
                    {
                        Throw(val);
                    }

                    hasE = true;
                    e.MoveNext();
                    val.Append(e.Current);
                    if (!(e.Current >= '0' && e.Current <= '9' || e.Current == '-' || e.Current == '+'))
                    {
                        Throw(val);
                    }
                }
                else if (e.Current == '-')
                {
                    ReadDateFromNumber(e, val, end);
                    break;
                }
                else if (e.Current < '0' || e.Current > '9')
                {
                    Throw(val);
                }
            }

            return(val.ToString());
        }
Esempio n. 20
0
        //生成Token表并返回
        public List <Token> TokenHandle()
        {
            source += '\n';
            CharEnumerator pr = source.GetEnumerator();
            char           c;
            Token          token;
            Token          temp;

            pr.MoveNext();
            while (true)
            {
                c = pr.Current;
                while (c == ' ' || c == '\n' || c == '\t')
                {
                    if (pr.MoveNext())
                    {
                        c = pr.Current;
                    }
                    else
                    {
                        return(tokenList);
                    }
                }
                token = new Token();
                foreach (var getToken in typeHandleList)
                {
                    temp = getToken((CharEnumerator)pr.Clone());
                    if (temp.Length > token.Length)
                    {
                        token = temp;
                    }
                }
                if (token.Length > 0)
                {
                    pr = token.p;
                    if (token.isLast)
                    {
                        tokenList.Add(token);
                        return(tokenList);
                    }
                }
                else
                {
                    token.type  = "Illegal Character";
                    token.value = pr.Current.ToString();
                    pr.MoveNext();
                }
                tokenList.Add(token);
            }
        }
Esempio n. 21
0
        internal List <Token> Scan()
        {
            var tokens = new List <Token>();

            while (_enumerator.MoveNext())
            {
                PrepareForNextLexeme();
                ScanNextLexeme();
                RollbackIfNotAcceptLexeme();
                ProccessToken(tokens);
            }

            return(tokens);
        }
Esempio n. 22
0
        /// <summary>
        /// 获取字符串中指定位置开始的指定长度的字符串,支持汉字英文混合 汉字为2字节计数
        /// </summary>
        /// <param name="strSub">输入中英混合字符串</param>
        /// <param name="start">开始截取的起始位置</param>
        /// <param name="length">要截取的字符串长度</param>
        /// <returns></returns>
        public static string GetSubString(string strSub, int start, int length)
        {
            string temp = strSub;
            int    j = 0, k = 0, p = 0;

            CharEnumerator ce = temp.GetEnumerator();

            while (ce.MoveNext())
            {
                j += (ce.Current > 0 && ce.Current < 255) ? 1 : 2;

                if (j <= start)
                {
                    p++;
                }
                else
                {
                    if (j == GetLength(temp))
                    {
                        temp = temp.Substring(p, k + 1);
                        break;
                    }
                    if (j <= length + start)
                    {
                        k++;
                    }
                    else
                    {
                        temp = temp.Substring(p, k);
                        break;
                    }
                }
            }
            return(temp);
        }
Esempio n. 23
0
        public int FindEndOfTerm(string f)
        {
            CharEnumerator f_char = f.GetEnumerator();
            int            index  = 0;
            bool           overt  = false;

            while (f_char.MoveNext())
            {
                char c = f_char.Current;
                if (c == '(')
                {
                    overt = true;
                }
                if (c == ')')
                {
                    overt = false;
                }
                if (c == '+' && !overt)
                {
                    return(index);
                }
                index++;
            }
            return(f.Length);
        }
Esempio n. 24
0
        private static bool BufferEqualToString(StringBuffer a, string b)
        {
            if (a is null)
            {
                return(b is null);
            }

            if (a.Count != b?.Length)
            {
                return(false);
            }

            Enumerator     t = a.GetEnumerator();
            CharEnumerator o = b.GetEnumerator();

            bool result = true;

            while (o.MoveNext() && t.MoveNext())
            {
                if (t.Current != o.Current)
                {
                    result = false;
                    break;
                }
            }

            t.Dispose();
            //o.Dispose();

            return(result);
        }
Esempio n. 25
0
        private bool NextValue(CharEnumerator cursor, out string value)
        {
            Characters.Escaper escape = Characters.NoEscape;

            builder.Clear();
            while (true)
            {
                if (!cursor.MoveNext())
                {
                    value = builder.ToString();
                    return(false);
                }

                if (Characters.IsEscape(cursor.Current))
                {
                    escape = Characters.Unescape;
                    continue;
                }

                if (Characters.IsTerminator(cursor.Current))
                {
                    value = builder.ToString();
                    return(true);
                }

                builder.Append(escape(cursor.Current));
                escape = Characters.NoEscape;
            }
        }
Esempio n. 26
0
        private bool IsParenthesesvalid(string s)
        {
            CharEnumerator cn     = s.GetEnumerator();
            int            overt  = 0;
            int            closed = 0;

            while (cn.MoveNext())
            {
                char c = cn.Current;
                if (c == '(')
                {
                    overt++;
                }
                else
                {
                    if (c == ')')
                    {
                        closed++;
                    }
                    if (closed > overt)
                    {
                        return(false);
                    }
                }
            }
            if (closed < overt)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 27
0
        public bool IsParenthesesNested(string f)
        {
            CharEnumerator fchar = f.GetEnumerator();
            bool           overt = false;

            while (fchar.MoveNext())
            {
                char c = fchar.Current;
                if (c == '(')
                {
                    if (overt)
                    {
                        return(true);
                    }
                    else
                    {
                        overt = true;
                    }
                }
                if (c == ')' && overt)
                {
                    overt = false;
                }
            }
            return(false);
        }
Esempio n. 28
0
        private static QueryToken TokenizeQueryString(CharEnumerator queryEnum, StringBuilder builder)
        {
            if (queryEnum.MoveNext())
            {
                switch (queryEnum.Current)
                {
                case '(':
                    return(DoLeftParenForm(queryEnum, builder));

                case ')':
                    return(DoRightParenForm(builder));

                case ' ':
                    return(DoSpaceForm(queryEnum, builder));

                default:
                    return(DoDefaultForm(queryEnum, builder));
                }
            }

            if (builder.Length > 0)
            {
                return(DoRightParenForm(builder));
            }

            return(QueryToken.Empty);
        }
Esempio n. 29
0
        private static DatumReferenceValue ParseDatumReferenceValue(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(null);
            }

            StringBuilder value            = new StringBuilder();
            ToleranceMaterialCondition mat = ToleranceMaterialCondition.None;

            CharEnumerator chars = s.GetEnumerator();

            while (chars.MoveNext())
            {
                char token = chars.Current;
                if (token == '{')
                {
                    char symbol = Symbol(chars);
                    mat = ParseMaterialCondition(symbol);
                }
                else
                {
                    value.Append(token);
                }
            }

            DatumReferenceValue d = new DatumReferenceValue
            {
                Value             = value.ToString(),
                MaterialCondition = mat
            };

            return(d);
        }
Esempio n. 30
0
        /// <summary>
        /// 从此实例检索子字符串。 子字符串从指定的字符位置开始且具有指定的长度。
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="start">开始位置</param>
        /// <param name="length">长度</param>
        /// <param name="append">尾部追加</param>
        /// <returns></returns>
        public static string Substr(this string str, int start, int length, string append)
        {
            if (start >= length)
            {
                return("");
            }

            int _start = start, _length = 0;

            CharEnumerator ce = str.GetEnumerator();

            while (ce.MoveNext())
            {
                _start++;
                if (_start <= length)
                {
                    _length++;
                }
                else
                {
                    return(str.Substring(start, _length));
                }
            }

            return(str);
        }
Esempio n. 31
0
 private bool InternalValidate(CharEnumerator password) {
     while(password.MoveNext()){
         for (int i = 0; i < m_Validators.Length; i++) {
             m_Validators[i].InspectChar(password.Current);
         }
     }
     bool result = true;
     m_LastStrength = 0;
     for (int i = 0; i < m_Validators.Length; i++) {
         result &= m_Validators[i].IsValidated();
         m_LastStrength += m_Validators[i].PasswordStrength;
         m_Validators[i].Reset();
     }
     m_LastStrength /= m_Validators.Length;
     return result;
 }