예제 #1
0
        /// <summary>
        /// Creates a new Hastable from the Information stored in a Serialized Array String generated by php.
        /// </summary>
        /// <param name="str">The serialized Array</param>
        /// <returns>The generated Hashtable</returns>
        public static Hashtable GetHashtableFromSerializedArray(string str)
        {
            Hashtable sths             = BuildSerializedArrayTokenHandlers();
            SerializedTokenHandler sth = null;
            int index = 0;

            //go throug the string character wise
            while (index < str.Length)
            {
                int  oldindex = index;
                char curToken = str[index];
                sth = (SerializedTokenHandler)sths[curToken];

                if (sth != null)
                {
                    object obj = sth(str, ref index);
                    if (obj != null)
                    {
                        return((Hashtable)obj);
                    }
                }

                if (index == oldindex)
                {
                    index++;
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Behandelt ein Array Token
        /// </summary>
        /// <param name="str">Die Zeichenkette</param>
        /// <param name="index">Der aktuelle Index der Zeichenkette</param>
        /// <param name="data">Data enthält das Hashtableelement das initialisiert werden soll</param>
        /// <returns>Ein neuer Hashtable welcher das Array darstellt</returns>
        /// <remarks>
        ///		Ein serialisiertes Array hat z.B. die Form
        ///		<code>
        ///			a:4:{s:4:"code";s:6:"700666";i:1;s:10:"16.09.1978";i:2;b:0;s:4:"test";s:23:"Das ist: {} "ein" test;";}
        ///		</code>
        ///	</remarks>
        protected static object ArrayHandler(string str, ref int index)
        {
            str = str.Substring(index);
            string[] tokens = str.Split(":".ToCharArray(), 3);
            if (tokens.Length < 3)
            {
                throw new Exception("Ungültiger Array Token");
            }
            int len = ToInt(tokens[1]);

            index += 3;             //2x':', 1x'{'
            index += tokens[0].Length;
            index += tokens[1].Length;

            //jetzt die Elemente des Array erzeugen
            Hashtable ret              = new Hashtable();
            Hashtable sths             = BuildSerializedArrayTokenHandlers();
            SerializedTokenHandler sth = null;
            object key       = null;
            int    itemcount = 0;

            //go throug the string character wise
            while ((index < str.Length) && (itemcount < len))
            {
                int  oldindex = index;
                char curToken = str[index];

                if (curToken == '}')
                {
                    break;
                }
                sth = (SerializedTokenHandler)sths[curToken];

                if (sth != null)
                {
                    key = sth(str, ref index);
                    if (key != null)
                    {
                        index++;                         //1x';'
                        curToken = str[index];

                        sth = (SerializedTokenHandler)sths[curToken];
                        if (sth != null)
                        {
                            ret[key] = sth(str, ref index);
                            itemcount++;
                        }
                        else
                        {
                            throw new Exception("Der Werttoken '" + curToken + "' ist nicht bekannt!");
                        }
                    }
                    else
                    {
                        throw new Exception("Der Schlüssel darf nicht null sein!");
                    }
                }
                else
                {
                    throw new Exception("Der Schlüsseltoken '" + curToken + "' ist nicht bekannt!");
                }

                index++;                 //1x';'
            }

            index++;             //1x'}';
            if (itemcount != len)
            {
                throw new Exception("Das Array konnte nicht korrekt verarbeitet werden. Die Anzahl der Elemente ist zu klein!");
            }

            return(ret);
        }