X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fvspace.C;h=d12ecb820a497080a57fba93f34d1ffd60d2b6c5;hb=f448e22d483e1370bcbfbb7be8cb47ad7251ed77;hp=392b80c102c96e151a25a23afeab0b0902ae0446;hpb=4c295014fe141d56fcfd110473ab53c4e86e62d4;p=lyx.git diff --git a/src/vspace.C b/src/vspace.C index 392b80c102..d12ecb820a 100644 --- a/src/vspace.C +++ b/src/vspace.C @@ -87,33 +87,57 @@ char nextToken(string & data) lyx_advance(data, 5); return '-'; } else { - string::size_type i; - - // 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); - double x = strToDbl(buffer); - if (x || (buffer[0] == '0')) { - number[number_index] = x; - lyx_advance(data, i + 1); + string::size_type i = data.find_first_not_of("0123456789."); + + if (i != 0) { + if (number_index > 3) return 'E'; + + string buffer; + + // 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); ++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'; + + string buffer; + + // 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 } } @@ -169,7 +193,7 @@ bool isValidGlueLength (string const & data, LyXGlueLength * result) // To make isValidGlueLength recognize negative values as // the first number this little hack is needed: short val_sign = 1; // positive as default - switch(buffer[0]) { + switch (buffer[0]) { case '-': lyx_advance(buffer, 1); val_sign = -1; @@ -233,7 +257,7 @@ bool isValidLength(string const & data, LyXLength * result) // To make isValidLength recognize negative values // this little hack is needed: short val_sign = 1; // positive as default - switch(buffer[0]) { + switch (buffer[0]) { case '-': lyx_advance(buffer, 1); val_sign = -1; @@ -421,7 +445,7 @@ VSpace::VSpace (string const & data) else if (prefixIs (input, "vfill")) kin = VFILL; else if (isValidGlueLength (input, &len)) kin = LENGTH; - else if (sscanf (input.c_str(), "%f", &value) == 1) { + else if (sscanf(input.c_str(), "%f", &value) == 1) { // This last one is for reading old .lyx files // without units in added_space_top/bottom. // Let unit default to centimeters here.