Garrett D'Amore wrote:
> 
> Jan Pechanec wrote:
> > On Mon, 14 Jan 2008, [EMAIL PROTECTED] wrote:
[snip]
> What I would do is use strtok_r, and then you can use a nested structure:
> 
> char *l1, *l2, *nvp, *name, *value;
> 
> for (nvp = strtok_r(str, ";", &l1); nvp != NULL; nvp = strtok_r(NULL,
> ';', &l1)) {
>         name = strtok_r(nvp, "=", &l2);
>         value = strtok_r(NULL, "", &l2);
> }
> 
> The only possible problem with this approach, is that it will skip cases
> like ";;" (an empty name-value pair), and it can't parse "name==value"
> properly.  (It will see the value as 'value', rather than '=value'.)  I
> once had a version of strtok that did not collapse multiple delimiters.
> I.e. if a token delimiter appeared twice in a row, it would see an empty
> string as a token value.  There are cases where this kind of parsing is
> useful.

Another issue you may have to check is whether the input data may
contain non-ASCII characters (e.g. UTF-8, ShiftJIS etc.) and whether the
format allows to "escape" special characters (e.g. "\;" - both cases
would AFAIK require custom code...

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [EMAIL PROTECTED]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to