X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flengthcommon.cpp;h=f71d009dbd443cfa67f51b9b1db5d11e641381ce;hb=30eb6dfaebe1df2b38bcc4e69302a5ad2c2d1952;hp=a226a7e2e73bad977a8b64ff129bfb68582456cc;hpb=67af5a53880c87bcf258107f9e8716ae9746c15c;p=lyx.git diff --git a/src/lengthcommon.cpp b/src/lengthcommon.cpp index a226a7e2e7..f71d009dbd 100644 --- a/src/lengthcommon.cpp +++ b/src/lengthcommon.cpp @@ -19,9 +19,6 @@ #include "support/lassert.h" #include "support/lstrings.h" -#include -#include - using namespace std; using namespace lyx::support; @@ -35,7 +32,7 @@ char const * const unit_name[] = { "bp", "cc", "cm", "dd", "em", "ex", "in", "mm", "mu", "pc", "pt", "sp", "text%", "col%", "page%", "line%", - "theight%", "pheight%", "" }; + "theight%", "pheight%", "baselineskip%", "" }; int const num_units = int(sizeof(unit_name) / sizeof(unit_name[0]) - 1); @@ -45,7 +42,8 @@ char const * const unit_name_gui[] = { N_("ex"), N_("in[[unit of measure]]"), N_("mm"), N_("mu[[unit of measure]]"), N_("pc"), N_("pt"), N_("sp"), N_("Text Width %"), N_("Column Width %"), N_("Page Width %"), N_("Line Width %"), - N_("Text Height %"), N_("Page Height %"), "" }; + N_("Text Height %"), N_("Page Height %"), N_("Line Distance %"), "" }; + Length::UNIT unitFromString(string const & data) { @@ -206,7 +204,8 @@ LaTeXLength table[] = { }; -} // namespace anon +} // namespace + const char * stringFromUnit(int unit) { @@ -234,8 +233,11 @@ bool isValidGlueLength(string const & data, GlueLength * result) // forward approach leads to very long, tedious code that would be // much harder to understand and maintain. (AS) - if (data.empty()) + if (data.empty()) { + if (result) + *result = GlueLength(); return true; + } string buffer = ltrim(data); // To make isValidGlueLength recognize negative values as @@ -304,12 +306,13 @@ bool isValidLength(string const & data, Length * result) // The parser may seem overkill for lengths without // glue, but since we already have it, using it is // easier than writing something from scratch. - if (data.empty()) + if (data.empty()) { + if (result) + *result = Length(); return true; + } - string buffer = data; - int pattern_index = 0; - char pattern[3]; + string buffer = data; // To make isValidLength recognize negative values // this little hack is needed: @@ -337,19 +340,19 @@ bool isValidLength(string const & data, Length * result) int unit_index = 1; // entries at index 0 are sentinels // construct "pattern" from "data" + string pattern; while (!isEndOfData(buffer)) { - if (pattern_index > 2) + if (pattern.size() > 2) return false; - pattern[pattern_index] = nextToken(buffer, number, + char const token = nextToken(buffer, number, number_index, unit, unit_index); - if (pattern[pattern_index] == 'E') + if (token == 'E') return false; - ++pattern_index; + pattern += token; } - pattern[pattern_index] = '\0'; // only the most basic pattern is accepted here - if (strcmp(pattern, "nu") != 0) + if (pattern != "nu") return false; // It _was_ a correct length string.