Lars Gullik Bjønnes wrote:

> Georg Baum <[EMAIL PROTECTED]>
> writes:
> | -           if (contains(s,"%%BoundingBox:") && !contains(s,"atend")) {
> | -                   string const bb = ltrim(s.substr(14));
> | -                   readBB_lyxerrMessage(file_, zipped, bb);
> | +           boost::smatch what;
> | +           regex_match(s, what, bbox_re);
> | +           if (what[0].matched) {
> 
>                 if (regex_match(s, what, bbox_re)) {
> 
> instead.
> 
> If it is not a full match the it is not interesting.

OK. I thought that what[0] was the full match, but your version looks better
anyway.

> I do not like the "if (zipped) unlink(file_)" spread all over.

It is IMO better than readBB_lyxerrMessage, because it is not clear at all
that readBB_lyxerrMessage unlinks the file.

> Either a nicer solution should be found (RAII) or readBB_lyxerrMessage
> should be retained.

I removed readBB_lyxerrMessage because of your #warning. Since I have no
time right now I undid that change and will commit the attached patch.


Georg


Log:

fix bug 1235
        * src/support/filetools.C
        (readBB_from_PSFile): sanitize return value
Index: src/support/filetools.C
===================================================================
--- src/support/filetools.C	(Revision 13547)
+++ src/support/filetools.C	(Arbeitskopie)
@@ -1172,12 +1172,22 @@ string const readBB_from_PSFile(string c
 		return string();
 	}
 
+	static boost::regex bbox_re(
+		"^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
 	std::ifstream is(file_.c_str());
 	while (is) {
 		string s;
 		getline(is,s);
-		if (contains(s,"%%BoundingBox:") && !contains(s,"atend")) {
-			string const bb = ltrim(s.substr(14));
+		boost::smatch what;
+		if (regex_match(s, what, bbox_re)) {
+			// Our callers expect the tokens in the string
+			// separated by single spaces.
+			// FIXME: change return type from string to something
+			// sensible
+			ostringstream os;
+			os << what.str(1) << ' ' << what.str(2) << ' '
+			   << what.str(3) << ' ' << what.str(4);
+			string const bb = os.str();
 			readBB_lyxerrMessage(file_, zipped, bb);
 			return bb;
 		}

Reply via email to