Example #1
0
        /// <summary>
        /// parse a string into DataBlock used in Postback, similar to Ajax's post back.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string[] Parse(string value)
        {
            List <string> results = new List <string>();

            string token = string.Empty;
            int    pos   = 0;

            while (pos < value.Length)
            {
                int len = Convert.ToInt32(TestRoutine.GetNextToken(value, ref pos, Delimiter));

                // advance past the delimiter
                pos++;

                token = value.Substring(pos, len);
                pos  += len;

                // advance past the delimiter
                pos++;

                #region Sanity Checks
                if (token.Length != len)
                {
                    throw new ArgumentOutOfRangeException("incorrect length");
                }
                #endregion

                results.Add(token);
            }

            return(results.ToArray());
        }
Example #2
0
        /// <summary>
        /// parse a string into DataBlock used in AJAX Postback.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static DeltaNode[] Parse(string value)
        {
            List <DeltaNode> results = new List <DeltaNode>();
            int pos = 0;

            while (pos < value.Length)
            {
                int len = Convert.ToInt32(TestRoutine.GetNextToken(value, ref pos, Delimiter));
                // advance past the delimiter
                pos++;

                string deltaType = TestRoutine.GetNextToken(value, ref pos, Delimiter);
                pos++;

                string variable = TestRoutine.GetNextToken(value, ref pos, Delimiter);
                pos++;

                string val = value.Substring(pos, len);
                // advance past the delimiter
                pos += len + 1;

                #region Sanity Checks
                if (val.Length != len)
                {
                    throw new ArgumentOutOfRangeException("incorrect length");
                }
                #endregion

                results.Add(new DeltaNode(deltaType, variable, val));
            }

            return(results.ToArray());
        }
Example #3
0
        void ITelephoneParser.Parse(string value)
        {
            try
            {
                StringBuilder buffer = new StringBuilder(value);

                // remove format chars...
                TestRoutine.RemoveFormatChar(buffer, delimiters);

                if (!TestRoutine.IsDigits(buffer.ToString()))
                {
                    // look for possible extension
                    int pos = -1, len = -1;
                    if (TestRoutine.FindToken(buffer, extensionTokens, out pos, out len))
                    {
                        // get the extension number.
                        int    pos2      = pos + len;
                        string extension = buffer.ToString().Substring(pos2);
                        this.Extension = extension;

                        // remove everything past the extension token.
                        buffer.Remove(pos, buffer.Length);
                    }
                }

                string buf = buffer.ToString();
                switch (buf.Length)
                {
                case 11:
                    if (buf[0] != '1')
                    {
                        goto default;
                    }
                    buf.Remove(0, 1);
                    goto case 10;

                case 10:
                    this.Areacode = buf.Substring(0, 3);
                    this.Prefix   = buf.Substring(3, 3);
                    this.Suffix   = buf.Substring(6, 4);
                    break;

                case 7:
                    this.Prefix = buf.Substring(0, 3);
                    this.Suffix = buf.Substring(3, 4);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("invalid phone: " + buf);
                }
            }
            catch (Exception ex)
            {
                DebuggerTool.AddData(ex, "value", value);
                throw;
            }
        }