As I reported a while ago, IsValidGlueLength is broken (it cannot handle
the Glue part of the Length).

Attached patch fixes it. I hope its good (comments on std c++ string usage
welcome !)

thanks
john

p.s. Baruch's www-devel patch looks good to me ... should I apply it or is
someone else on it ?

-- 
Oak: Hackers are generally quite happy to use the masculine pronoun as a
 non-gender-specific reference, as they understand that "fixing" legacy
 systems is often more troublesome than conforming to their peculiarities.
Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/ChangeLog,v
retrieving revision 1.685
diff -u -p -r1.685 ChangeLog
--- ChangeLog   2000/11/15 03:22:04     1.685
+++ ChangeLog   2000/11/15 14:46:12
@@ -1,3 +1,8 @@
+2000-11-15  John Levon  <[EMAIL PROTECTED]>
+
+       * src/vspace.C (nextToken): fix so it can handle length phrases like
+               "10mm+-20mm", "40inplus16mmminus10cm" etc.
+
 2000-11-15  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>
 
        * src/support/lyxfunctional.h: make back_insert_fun_iterator(s)
Index: src/vspace.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/vspace.C,v
retrieving revision 1.27
diff -u -p -r1.27 vspace.C
--- src/vspace.C        2000/11/04 10:00:10     1.27
+++ src/vspace.C        2000/11/15 14:46:16
@@ -88,31 +88,54 @@ char nextToken(string & data)
                return '-';
        } else {
                string::size_type i;
+               string buffer;
+               
+               i = data.find_first_not_of("0123456789.");
+               if (i!=0) {
+                       if (number_index > 3) return 'E';
 
-               // I really mean assignment ("=") below, not equality!
-               if ((i = data.find_last_of("0123456789.")) != string::npos) {
-                       if (number_index > 3) return 'E';  // Error
-                        string buffer = data.substr(0, i + 1);
+                       // we have found some number
+                       if (i==string::npos) {
+                               buffer = data;
+                               i = data.size()+1;
+                       } else
+                               buffer = data.substr(0, i);
+
+                       lyx_advance(data, i);
+
                        if (isStrDbl(buffer)) {
                                number[number_index] = strToDbl(buffer);
-                               lyx_advance(data, i + 1);
                                ++number_index;
                                return 'n';
-                       } else 
-                               return 'E';  // Error
-               } else if ((i = data.find_last_of("abcdefghijklmnopqrstuvwxyz"))
-                          != string::npos) {
-                       if (unit_index > 3) return 'E';  // Error
-                       string buffer = data.substr(0, i + 1);
-                       unit[unit_index] = unitFromString(buffer);
+                       } else return 'E';
+               }
+               
+               i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz");
+               if (i!=0) {
+                       if (unit_index > 3) return 'E';
+
+                       // we have found some alphabetical string
+                       if (i==string::npos) {
+                               buffer = data;
+                               i = data.size()+1;
+                       } else
+                               buffer = data.substr(0, i);
+
+                       // possibly we have "mmplus" string or similar
+                       if (buffer.size() > 5 && (buffer.substr(2,4)==string("plus") 
+|| buffer.substr(2,5)==string("minus"))) {
+                               lyx_advance(data, 2);
+                               unit[unit_index] = unitFromString(buffer.substr(0,2));
+                       } else {
+                               lyx_advance(data, i);
+                               unit[unit_index] = unitFromString(buffer);
+                       }
+
                        if (unit[unit_index] != LyXLength::UNIT_NONE) {
-                               lyx_advance(data, i + 1);
                                ++unit_index;
                                return 'u';
-                       } else
-                               return 'E';  // Error
-               } else
-                       return 'E';  // Error
+                       } else return 'E';  // Error
+               }
+               return 'E';  // Error
        }
 }
 

Reply via email to