public int ArrColumn(String Text)
 {
     CharEnumerator ce = Text.GetEnumerator();
     ce.MoveNext();
     int index = 0, columns = 0;
     while (index != Text.Length)
     {
         if (ce.Current.CompareTo(']')==0)
             break;
         index++;
         if(ce.Current.CompareTo(',')==0)
         columns++;
         ce.MoveNext();
     }
     return columns+1;
 }
Exemple #2
0
        public static void SendDifference(String contextBefore, String contextAfter)
        {
            if (contextBefore == contextAfter)
            {
                return;
            }

            int lengthBefore = contextBefore.Length;
            int lengthAfter = contextAfter.Length;

            if (contextBefore.Length > contextAfter.Length)
            {
                SendBackspace(contextBefore.Length - contextAfter.Length);
                lengthBefore = lengthAfter;
            }

            CharEnumerator bit, ait;
            int match = 0;
            for (
                bit = contextBefore.GetEnumerator(), ait = contextAfter.GetEnumerator();
                bit.MoveNext() && ait.MoveNext();
                match++)
            {
                if (bit.Current != ait.Current)
                {
                    break;
                }
            }

            if (match < lengthBefore)
            {
                SendBackspace(lengthBefore - match);
            }

            if (match < contextAfter.Length)
            {
                SendKeyStrokes(contextAfter.Substring(match));
            }
        }
 public int ArrRow(String Text)
 {
     CharEnumerator ce = Text.GetEnumerator();
     ce.MoveNext();
     int index=0,rows=0;
     while (index != Text.Length)
     {
         if(ce.Current.CompareTo('[')==0)
             rows++;
           index++;
           ce.MoveNext();
     }
     return rows;
 }
    public override void VisitLoopElement(LoopElement element)
    {
        resultMessage += "parsing loop element"+"\n";
        loop = element.getText();
        int inc=0;
        int mode = 0;
        CharEnumerator ce = loop.GetEnumerator();
        string remloop="0";
        ce.MoveNext();
        while( inc < loop.Length)
        {
            //Console.WriteLine("Writing loop value {0}", ce.Current);

            if (ce.Current.CompareTo('(') == 0 && mode != -1)
                mode = 1;
            if (ce.Current.CompareTo(' ') == 0)
            {
                remloop = loop.Substring(inc);
                break;

            }

            if (mode == 1 && ce.Current.CompareTo('(')!=0)
            {
               loopvar = string.Concat(loopvar, ce.Current.ToString());
            }

            ce.MoveNext();
            inc++;
        }
        inc = 0;
        mode = 0;
        Console.WriteLine(" variable met in loop element:{0}",loopvar);
        resultMessage += String.Format(" variable met in loop element:{0}", loopvar)+"\n";
        Console.WriteLine(" substring left to parse:{0}", remloop);
        resultMessage += string.Format(" substring left to parse:{0}", remloop)+"\n";
        ce = remloop.GetEnumerator();
        ce.MoveNext();
        ce.MoveNext();
        string startvar="";
        string endvar="";
        while (inc < remloop.Length)
        {
            if (ce.Current.CompareTo('.') > 0 && mode == 0)
            {
                startvar += ce.Current.ToString();
            }
            else if(ce.Current.CompareTo('.')==0)
            {
                mode = 1;
            }
            else if (ce.Current.CompareTo(')') == 0)
            {
                break;
            }
            if (mode == 1 && ce.Current.CompareTo('.')!=0)
            {
                endvar += ce.Current.ToString();
            }
            ce.MoveNext();
            inc++;
        }
        Console.WriteLine("starting var of the loop is: {0}\n ending var of the loop is:{1}", startvar,endvar);
        resultMessage += string.Format("starting var of the loop is: {0}\n ending var of the loop is:{1}", startvar, endvar)+"\n";
        startloopvar = int.Parse(startvar);
        endloopvar = int.Parse(endvar);
    }
Exemple #5
0
        private void initialize()
        {
            /* start initialize */

            int choice, i;
            String[] classes = new String[ 6 ] { "Warrior", "Theif", "Monk", "White Mage", "Black Mage", "Red Mage" };
            String name;
            Character[] characters = new Character[ Party.MAXPARTY ];

            for (i = 0; i < Party.MAXPARTY; i++)
            {/* start loop */

                mView.sendOutput("What class type do you want? You get 3.");
                mView.sendOutput(classes.GetEnumerator(), TypeEnum.STRING);
                choice = (int)mView.getInput(TypeEnum.INT);
                name = (string)mView.getInput(TypeEnum.STRING);

                characters[ i ] = CharacterCreationFactory(choice, name);

            }/* end loop */

            mGoodGuys = new Party(characters);
            mBattle = new BattleSystem(this, mGoodGuys);
            mDungeon = new Dungeon(this, mGoodGuys);
        }
        /*
         * validate number of brackets
         */
        private ValidationResponce vBreckets(String inStr)
        {
            bool error = false;
            int errorBegin = -1;
            int errorEnd = -1;
            ValidationResponce response = new ValidationResponce();
            String currErrorType = "validEr1";
            int openedSquareBrackets = 0;
            int closedSquareBrackets = 0;
            int openedRoundBrackets = 0;
            int closedRoundBrackets = 0;

            CharEnumerator ce = inStr.GetEnumerator();

            while (ce.MoveNext())
            {
                switch (ce.Current)
                {
                    case '(':
                        {
                            //   currErrorType = "validEr1";
                            openedSquareBrackets++;
                            break;
                        }
                    case ')':
                        {
                            //       currErrorType = "validEr1";
                            closedSquareBrackets++;
                            break;
                        }
                    case '[':
                        {
                            //    currErrorType = "validEr1";
                            openedRoundBrackets++;
                            break;
                        }
                    case ']':
                        {
                            //   currErrorType = "validEr1";
                            closedRoundBrackets++;
                            break;
                        }
                }

            }
            //  args = new String[] { ce.Current.ToString() };
            if (openedSquareBrackets != closedSquareBrackets)
            {
                error = true;
                errorBegin = inStr.LastIndexOf("(");
                errorEnd = inStr.LastIndexOf(")");
            }
            else if (openedRoundBrackets != closedRoundBrackets)
            {
                error = true;
                errorBegin = inStr.LastIndexOf("[");
                errorEnd = inStr.LastIndexOf("]");
            }
            response.setResponce(error, errorBegin, errorEnd, currErrorType);
            return response;
        }
		/// <summary>
		/// Returns an IEnumerator containing the names of the keys of the message body.
		/// </summary>
		/// <param name="message">The message where to get the keys names from</param>
		/// <returns>An IEnumerator containing the keys of the message body</returns>
		public static System.Collections.IEnumerator Keys(System.Messaging.Message message)
		{
			System.String[] tempString = new System.String[((System.Collections.SortedList)message.Body).Keys.Count];
			((System.Collections.SortedList)message.Body).Keys.CopyTo(tempString, 0);
			return tempString.GetEnumerator();
		}
Exemple #8
0
        public static object unpack(String jsonstr)
        {
            object _out = null;
            Hashtable _table = null;
            ArrayList _array = null;

            String key = "";
            String value = "";
            CharEnumerator c = jsonstr.GetEnumerator();

            Stack s = new Stack();

            Func<String, String> parsekey = (String _c) =>{
                key += _c;
                return key;
            };

            Func<String, String> parsevalue = (String _c) =>
            {
                value += _c;
                return value;
            };

            Func<String, String> parsesys = parsekey;

            Func<String, String> parsemap = (String _c) =>
            {
                parsesys = parsekey;

                if (value == "" || key == "")
                {
                    return _c;
                }

                value = value.Trim();
                while (value[0] == '\n' || value[0] == '\t')
                {
                    value = value.Substring(1, value.Length - 1);
                }
                String v = value;
                key = key.Trim();
                while (key[0] == '\n' || key[0] == '\t')
                {
                    key = key.Substring(1, key.Length - 1);
                }
                key = key.Substring(1, key.Length - 2);

                if (v == "true")
                {
                    _table[key] = true;
                }
                else if (v == "false")
                {
                    _table[key] = false;
                }
                else if (v == "null")
                {
                    _table[key] = null;
                }
                else
                {
                    if (v[0] == '\"' && v[v.Length - 1] == '\"')
                    {
                        v = v.Substring(1, v.Length - 2);
                        _table[key] = v;
                    }
                    else
                    {
                        int status = 0;

                        foreach (char _ch in v)
                        {
                            if ((_ch < '0' || _ch > '9') && _ch != '.')
                            {
                                throw new Exception("format error");
                            }

                            if (_ch == '.')
                            {
                                status++;
                            }
                        }

                        if (status == 0)
                        {
                            _table[key] = Convert.ToInt64(v);
                        }
                        else if (status == 1)
                        {
                            _table[key] = Convert.ToDouble(v);
                        }
                        else
                        {
                            throw new Exception("format error");
                        }
                    }

                }

                key = "";
                value = "";

                return _c;
            };

            Func<String, String> parsearray = (String _c) =>
            {
                value = value.Trim();

                if (value == "")
                {
                    return _c;
                }

                while (value[0] == '\n' || value[0] == '\t')
                {
                    value = value.Substring(1, value.Length - 1);
                }
                String v = value;

                if (v.ToLower() == "true")
                {
                    _array.Add(true);
                }
                else if (v.ToLower() == "false")
                {
                    _array.Add(false);
                }
                else if (v.ToLower() == "null")
                {
                    _array.Add(null);
                }
                else
                {
                    if (v[0] == '\"' && v[v.Length - 1] == '\"')
                    {
                        v = v.Substring(1, v.Length - 2);
                        _array.Add(v);
                    }
                    else
                    {
                        int status = 0;

                        foreach (char _ch in v)
                        {
                            if ((_ch < '0' || _ch > '9') && _ch != '.')
                            {
                                throw new Exception("format error");
                            }

                            if (_ch == '.')
                            {
                                status++;
                            }
                        }

                        if (status == 0)
                        {
                            _array.Add(Convert.ToInt64(v));
                        }
                        else if (status == 1)
                        {
                            _array.Add(Convert.ToDouble(v));
                        }
                        else
                        {
                            throw new Exception("format error");
                        }
                    }

                }

                key = "";
                value = "";

                return _c;
            };

            Func<String, String> parseenum = parsemap;

            Func<object, object> parsepop = (object o) =>{
                if (typeof(Hashtable).IsInstanceOfType(o))
                {
                    _table = (Hashtable)o;

                    parsesys = parsekey;
                    parseenum = parsemap;
                }
                else if (typeof(ArrayList).IsInstanceOfType(o))
                {
                    _array = (ArrayList)o;

                    parsesys = parsevalue;
                    parseenum = parsearray;
                }

                return o;
            };

            int count = 0;
            int escape = 0;
            while (c.MoveNext())
            {
                if (c.Current.ToString() == "\\"){
                    escape = 1;
                }else{
                    escape = 0;
                }

                if (c.Current.ToString() == "\"" && escape != 1)
                {
                    if (count == 0)
                    {
                        count++;
                    }
                    else
                    {
                        count = 0;
                    }
                }

                if (count == 0)
                {
                    if (c.Current.ToString() == "{")
                    {
                        parsesys = parsekey;
                        parseenum = parsemap;

                        Hashtable _newtable = new Hashtable();
                        if (_table != null)
                        {
                            key = key.Trim();
                            while (key[0] == '\n' || key[0] == '\t')
                            {
                                key = key.Substring(1, key.Length - 1);
                            }
                            s.Push(_table);
                            key = key.Substring(1, key.Length - 2);
                            _table[key] = _newtable;
                            _table = null;
                            key = "";
                        }
                        else if (_array != null)
                        {
                            s.Push(_array);
                            _array.Add(_newtable);
                            _array = null;
                        }
                        _table = _newtable;

                        continue;
                    }

                    if (c.Current.ToString() == "}")
                    {
                        parseenum(c.Current.ToString());

                        if (s.Count > 0)
                        {
                            parsepop(s.Pop());
                        }

                        continue;
                    }

                    if (c.Current.ToString() == "[")
                    {
                        parsesys = parsevalue;
                        parseenum = parsearray;

                        ArrayList _newarray = new ArrayList();
                        if (_table != null)
                        {
                            s.Push(_table);
                            key = key.Trim();
                            while (key[0] == '\n' || key[0] == '\t')
                            {
                                key = key.Substring(1, key.Length - 1);
                            }
                            key = key.Substring(1, key.Length - 2);
                            _table[key] = _newarray;
                            _table = null;
                            key = "";
                        }
                        else if (_array != null)
                        {
                            s.Push(_array);
                            _array.Add(_newarray);
                            _array = null;
                        }
                        _array = _newarray;

                        continue;
                    }

                    if (c.Current.ToString() == "]")
                    {
                        parseenum(c.Current.ToString());

                        if (s.Count > 0)
                        {
                            parsepop(s.Pop());
                        }

                        continue;
                    }

                    if (c.Current.ToString() == ",")
                    {
                        parseenum(c.Current.ToString());
                        continue;
                    }

                    if (c.Current.ToString() == ":")
                    {
                        parsesys = parsevalue;
                        continue;
                    }
                }

                parsesys(c.Current.ToString());

            }

            if (_table != null)
            {
                _out = _table;
            }
            else if (_array != null)
            {
                _out = _array;
            }

            return _out;
        }
 public Dictionary<String, String> Read(String response, String endpoint)
 {
     return Read(response.GetEnumerator(), endpoint);
 }
Exemple #10
0
        private void convertWordToEnglish(Dictionary<int, string> latinTable,
            String word, List<Char> list, bool asEntityCodeFlag)
        {
            bool addAkaar = false;
            char c = '\0';
            int halant = 0x4D;

            CharEnumerator iter = word.GetEnumerator();

            while (iter.MoveNext())
            {
                String result;
                c = iter.Current;
                if (isIndic(c))
                {
                    int hiBytes;
                    int loBytes;

                    splitBytes(c, out hiBytes, out loBytes);

                    if (latinTable.TryGetValue(c, out result))
                    {
                        // NOP
                    }
                    else if (loBytes == halant)
                    {
                        addAkaar = false;
                        continue;
                    }
                    else if (latinTable.TryGetValue(loBytes, out result))
                    {
                        // NOP
                    }
                    else
                    {
                        list.Add(c);
                        continue;
                    }

                    if (addAkaar && (!isVowel(c)))
                    {
                        list.AddRange(m_akaar.ToCharArray());
                    }
                    list.AddRange(result.ToCharArray());
                    addAkaar = isConsonant(c);

                }
                else if (isNoncharacter(c))
                {
                    continue;
                }
                else
                {
                    list.Add(c);
                    continue;
                }
            }

            if (addAkaar && (!isVowel(c)))
            {
                list.AddRange(m_akaar.ToCharArray());
            }
        }