Question on (parse ...

Started by jsmall, October 13, 2004, 01:58:41 PM

Previous topic - Next topic

jsmall

If I try to parse:



  > (parse "Hello    World" {s+} 0)
   ("Hello" "World")

;; it works!  And

   > (parse "" {s+} 0)
   ()

;; it also works.  But then

   > (parse "    "  {s+} 0)
   ("" "")

;; Is this right?  I want to get back an empty list.

Lutz

#1
This is correct behaviour, 'parse' shows leading and trailing empty fields around separators. This gets clear when showing a CSV parsing example:



(parse "one,two,three" ",") => ("one" "two" "three")



but:



(parse "one,two,three," ",")  => ("one" "two" "three" "")



the trailing comma before the end of the record suggests, that there is an empty field between the comma end end of the record. Sometimes you have sequences with empty fields like:



(parse "1,2,,,5" ",") => ("1" "2" "" "" "6")



now the case you demonstrated, but with a comman separator instead:



(parse "," ",") => ("" "")



There are two empty fields separated by a comma



Lutz