Example #1
0
        private static void DisplayParsedItems(PFParseString parse)
        {
            int    numItems;
            int    inx;
            string item;

            numItems = System.Convert.ToInt32(parse.NumItems);

            Program._messageLog.WriteLine("Use get first and next");
            item = (string)parse.GetFirst();
            while (!parse.EOL)
            {
                Program._messageLog.WriteLine(item);
                item = (string)parse.GetNext();
            }

            Program._messageLog.WriteLine("Use get last and prev");
            item = (string)parse.GetLast();
            while (!parse.EOL)
            {
                Program._messageLog.WriteLine(item);
                item = (string)parse.GetPrev();
            }

            Program._messageLog.WriteLine("for 1 to count");
            for (inx = 0; inx <= numItems - 1; inx++)
            {
                item = (string)(parse.Get(inx));
                Program._messageLog.WriteLine(inx.ToString() + ": " + item);
            }
        }
Example #2
0
        public static void RunCommandLineParseTest(MainForm frm)
        {
            PFParseString parse = new PFParseString();

            try
            {
                _msg.Length = 0;
                _msg.Append("RunCommandLineParseTest running ...");
                Program._messageLog.WriteLine(_msg.ToString());

                parse.QuotedValues = frm.chkQuotedValues.Checked;
                parse.KeyType      = frm.cboKeyType.Text == "NoKey" ? PFParseString.PFArgumentKeyType.NoKey
                                : frm.cboKeyType.Text == "CharKey" ? PFParseString.PFArgumentKeyType.CharKey
                                : PFParseString.PFArgumentKeyType.NamedKey;
                parse.Delimiters    = frm.txtDelimiters.Text;
                parse.StringToParse = frm.txtCommandLineToParse.Text;

                _msg.Length = 0;
                _msg.Append("Key type: ");
                _msg.Append(parse.KeyType.ToString());
                _msg.Append("\r\n");
                _msg.Append("Delimiters: ");
                _msg.Append(parse.Delimiters);
                _msg.Append("\r\n");
                _msg.Append("QuotedValues: ");
                _msg.Append(parse.QuotedValues.ToString());
                _msg.Append("\r\n");
                _msg.Append("String to parse: ");
                _msg.Append(parse.StringToParse);
                _msg.Append("\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;

                if (parse.KeyType == PFParseString.PFArgumentKeyType.NoKey)
                {
                    string val = string.Empty;
                    _msg.Append("Show first to last:\r\n");
                    val = parse.GetFirst();
                    while (parse.EOL == false)
                    {
                        _msg.Append(val);
                        _msg.Append("\r\n");
                        val = parse.GetNext();
                    }
                    _msg.Append("Show last to first:\r\n");
                    val = parse.GetLast();
                    while (parse.EOL == false)
                    {
                        _msg.Append(val);
                        _msg.Append("\r\n");
                        val = parse.GetPrev();
                    }
                    Program._messageLog.WriteLine(_msg.ToString());
                }
                else
                {
                    //is either CharKey or NamedKey
                    PFParseString.PFKeyValuePair kv = new PFParseString.PFKeyValuePair();
                    _msg.Append("Show first to last:\r\n");
                    kv = parse.GetFirstKeyValue();
                    while (kv.Key != string.Empty)
                    {
                        _msg.Append("Key = ");
                        _msg.Append(kv.Key);
                        _msg.Append(" Val = ");
                        _msg.Append(kv.Value);
                        _msg.Append("\r\n");
                        kv = parse.GetNextKeyValue();
                    }
                    _msg.Append("Show last to first:\r\n");
                    kv = parse.GetLastKeyValue();
                    while (kv.Key != string.Empty)
                    {
                        _msg.Append("Key = ");
                        _msg.Append(kv.Key);
                        _msg.Append(" Val = ");
                        _msg.Append(kv.Value);
                        _msg.Append("\r\n");
                        kv = parse.GetPrevKeyValue();
                    }
                    Program._messageLog.WriteLine(_msg.ToString());
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                ;
            }
        }