Angus Leeming <[EMAIL PROTECTED]> writes: | On Thursday 04 April 2002 12:01 pm, Lars Gullik Bjønnes wrote: >> Angus Leeming <[EMAIL PROTECTED]> writes: >> | where BoundingBox bb is set so: >> | >> | BoundingBox::BoundingBox(string const & bb) >> | { >> | if (bb.empty()) >> | return; >> | >> | string tmp1; >> | string tmp2 = split(bb, tmp1, ' '); >> | if (!isValidLength(tmp1)) >> | return; >> | >> | LyXLength const length_xl(tmp1); >> | >> | tmp2 = split(tmp2, tmp1, ' '); >> | if (!isValidLength(tmp1)) >> | return; >> | >> | LyXLength const length_yb(tmp1); >> | >> | tmp2 = split(tmp2, tmp1, ' '); >> | if (!isValidLength(tmp1) || !isValidLength(tmp2)) >> | return; >> >> Why isn't a regex used instead of this manuel parsing of the bb >> string? > | Sorry, you've lost me. What good would that be? Perhaps some sample code? I | learn best through examples.
First you decide what the form om a valid bb string is: number space number "([[:digit:]]+) ([[:digit]]+)" then a match function will return true if the bb string mathes the regexp. a match object will have match[0] = the whole string that matched match[1] = the contents of the first sub-match match[2] = the contents of the first sub-match regex rex("([[:digit:]]+) ([[:digit]])"); if (match(rex, bb)) { tmp1 = match[1]; tmp2 = match[2]; // check for validy (is this really needed?) ... // assign to length objects... LyXLength const length_xl(tmp1); ... } kindo stuff. -- Lgb