hi,
shouldn't those two examples be the same?
array_sscanf("124dsf134", "%d%s%3d");
(5) Result: ({ /* 2 elements */ 124, "dsf134" })
array_sscanf("124dsf134", "%d%s%d");
(6) Result: ({ /* 3 elements */ 124, "dsf", 134 })
greetings, martin.
Yes, I guess it should. Wonder how much of a compatibility problem it would be to change that.
Personally I don't really like the dwim in %s in situations like that; I prefer to use %[...] instead. %s essentially becomes e.g. %[^0-9+-] if followed by %d, but there's no full backtracking if the following input specifier fails. Compare:
array_sscanf("abc-123", "%s%d");
(2) Result: ({ /* 2 elements */ "abc", -123 })
array_sscanf("abc-", "%s%d");
(3) Result: ({ /* 1 element */ "abc" })
If there was backtracking, the second case would return ({"abc-"}) since %d didn't parse "-" successfully. Now it's just lost.
On Thu, Dec 03, 2009 at 10:55:02PM +0000, Martin Stjernholm, Roxen IS @ Pike developers forum wrote:
If there was backtracking, the second case would return ({"abc-"}) since %d didn't parse "-" successfully. Now it's just lost.
on a related topic: is there a way to find out if the format has been parsed successfully? ie. in the above example, i'd like to get an error instead of an incomplete result. yes, i could check manually, but that implies that i understand or know the format, which is not aleays the case as it could come from somewhere else, even from user input.
i'd like to use sscanf as an alternative to regexp pattern matching
greetings, martin.
pike-devel@lists.lysator.liu.se