]> git.lyx.org Git - lyx.git/blobdiff - src/vspace.C
the convert patch
[lyx.git] / src / vspace.C
index 2c9e4a9074169c07ff5be13cbe724d6c098c392f..2ed5a50faa57c104beb37c385edf3f08e9febcad 100644 (file)
@@ -17,6 +17,7 @@
 #include "lengthcommon.h"
 #include "lyxtext.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 
 using lyx::support::compare;
@@ -24,7 +25,6 @@ using lyx::support::isStrDbl;
 using lyx::support::ltrim;
 using lyx::support::prefixIs;
 using lyx::support::rtrim;
-using lyx::support::strToDbl;
 
 using std::string;
 
@@ -83,12 +83,12 @@ char nextToken(string & data)
                lyx_advance(data, 1);
                return '+';
        }
-               
+
        if (prefixIs(data, "plus")) {
                lyx_advance(data, 4);
                return '+';
        }
-       
+
        if (data[0] == '-') {
                lyx_advance(data, 1);
                return '-';
@@ -117,7 +117,7 @@ char nextToken(string & data)
                lyx_advance(data, i);
 
                if (isStrDbl(buffer)) {
-                       number[number_index] = strToDbl(buffer);
+                       number[number_index] = convert<double>(buffer);
                        ++number_index;
                        return 'n';
                }
@@ -193,7 +193,7 @@ LaTeXLength table[] = {
 
 const char * stringFromUnit(int unit)
 {
-       if (unit < 0 || unit >= num_units)
+       if (unit < 0 || unit > num_units)
                return 0;
        return unit_name[unit];
 }
@@ -337,7 +337,7 @@ bool isValidLength(string const & data, LyXLength * result)
 //
 
 VSpace::VSpace()
-       : kind_(NONE), len_(), keep_(false)
+       : kind_(DEFSKIP), len_(), keep_(false)
 {}
 
 
@@ -357,7 +357,7 @@ VSpace::VSpace(LyXGlueLength const & l)
 
 
 VSpace::VSpace(string const & data)
-       : kind_(NONE), len_(), keep_(false)
+       : kind_(DEFSKIP), len_(), keep_(false)
 {
        if (data.empty())
                return;
@@ -388,7 +388,7 @@ VSpace::VSpace(string const & data)
                // without units in added_space_top/bottom.
                // Let unit default to centimeters here.
                kind_ = LENGTH;
-               len_  = LyXGlueLength(LyXLength(strToDbl(input), LyXLength::CM));
+               len_  = LyXGlueLength(LyXLength(convert<double>(input), LyXLength::CM));
        }
 }
 
@@ -436,7 +436,6 @@ string const VSpace::asLyXCommand() const
 {
        string result;
        switch (kind_) {
-       case NONE:      break;
        case DEFSKIP:   result = "defskip";      break;
        case SMALLSKIP: result = "smallskip";    break;
        case MEDSKIP:   result = "medskip";      break;
@@ -444,7 +443,7 @@ string const VSpace::asLyXCommand() const
        case VFILL:     result = "vfill";        break;
        case LENGTH:    result = len_.asString(); break;
        }
-       if (keep_ && kind_ != NONE && kind_ != DEFSKIP)
+       if (keep_)
                result += '*';
        return result;
 }
@@ -453,9 +452,6 @@ string const VSpace::asLyXCommand() const
 string const VSpace::asLatexCommand(BufferParams const & params) const
 {
        switch (kind_) {
-       case NONE:
-               return string();
-
        case DEFSKIP:
                return params.getDefSkip().asLatexCommand(params);
 
@@ -471,9 +467,13 @@ string const VSpace::asLatexCommand(BufferParams const & params) const
        case VFILL:
                return keep_ ? "\\vspace*{\\fill}" : "\\vfill{}";
 
-       case LENGTH: 
+       case LENGTH:
                return keep_ ? "\\vspace*{" + len_.asLatexString() + '}'
                        : "\\vspace{" + len_.asLatexString() + '}';
+
+       default:
+               BOOST_ASSERT(false);
+               return string();
        }
 }
 
@@ -482,14 +482,10 @@ string const VSpace::asLatexCommand(BufferParams const & params) const
 int VSpace::inPixels(BufferView const & bv) const
 {
        // Height of a normal line in pixels (zoom factor considered)
-       int const default_height = defaultRowHeight(); 
+       int const default_height = defaultRowHeight();
 
        switch (kind_) {
 
-       case NONE:
-               // value for this is already set
-               return 0;
-
        case DEFSKIP:
                return bv.buffer()->params().getDefSkip().inPixels(bv);
 
@@ -510,5 +506,9 @@ int VSpace::inPixels(BufferView const & bv) const
 
        case LENGTH:
                return len_.len().inPixels(bv.workWidth());
+
+       default:
+               BOOST_ASSERT(false);
+               return 0;
        }
 }