1

Following my previous question, I need to parse directive arguments, like these:

Listen 80

The parameters can get a bit complicated, with any kind of whitespace between arguments as well as escaped arguments.

My objective is to get a "complex" argument list like this:

cmd "C:\Documents and Settings\..." "msg=\"hello\"" msg="hello" "msg=""hello"""

into a TStringList of:

N | Text
--+-------------------------------
0 | cmd
1 | C:\Documents and Settings\...
2 | msg="hello"
3 | msg="hello"
4 | msg="hello"

One of my questions concern how quotes are escaped. I have two examples above, argument 2 and argument 4. In the first one, escaping is done by having a slash before the quote, while the second one is done by converting double (double)quotes into a single quote, a syntax associated with pascal (I think?)

How would I go about parsing the arguments efficiently in objective pascal (Delphi)?

Community
  • 1
  • 1
Christian
  • 27,509
  • 17
  • 111
  • 155

0 Answers0