]> git.lyx.org Git - lyx.git/commitdiff
the convert patch
authorLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 27 Jan 2005 21:05:44 +0000 (21:05 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Thu, 27 Jan 2005 21:05:44 +0000 (21:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9538 a592a061-630c-0410-9148-cb99ea01b6c8

76 files changed:
ChangeLog
configure.ac
po/POTFILES.in
src/BufferView_pimpl.C
src/ChangeLog
src/Chktex.C
src/Spacing.C
src/Spacing.h
src/buffer.C
src/chset.C
src/client/ChangeLog
src/client/debug.C
src/debug.C
src/frontends/gtk/ChangeLog
src/frontends/gtk/GGraphics.C
src/frontends/gtk/GPrint.C
src/frontends/gtk/xftFontLoader.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/QExternal.C
src/frontends/qt2/QExternalDialog.C
src/frontends/qt2/QGraphics.C
src/frontends/qt2/QPrefs.C
src/frontends/qt2/QWrap.C
src/frontends/qt2/qfont_loader.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FontInfo.C
src/frontends/xforms/FormExternal.C
src/frontends/xforms/FormGraphics.C
src/frontends/xforms/FormPreferences.C
src/frontends/xforms/FormPrint.C
src/frontends/xforms/xfont_loader.C
src/graphics/ChangeLog
src/graphics/GraphicsParams.h
src/graphics/PreviewLoader.C
src/insets/ChangeLog
src/insets/ExternalTransforms.C
src/insets/insetbibitem.C
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetexternal.C
src/insets/insetgraphics.C
src/insets/insetgraphicsParams.C
src/insets/insettabular.C
src/insets/insettext.C
src/insets/updatableinset.C
src/insets/updatableinset.h
src/lyxfunc.C
src/lyxlayout.h
src/lyxlex.C
src/lyxlex.h
src/mathed/ChangeLog
src/mathed/math_parser.C
src/mathed/math_sizeinset.C
src/support/ChangeLog
src/support/Makefile.am
src/support/atoi.C [deleted file]
src/support/convert.C
src/support/convert.h
src/support/lstrings.C
src/support/lstrings.h
src/support/lyxlib.h
src/support/tests/.cvsignore [new file with mode: 0644]
src/support/tests/Makefile.am [new file with mode: 0644]
src/support/tests/boost.C [new file with mode: 0644]
src/support/tests/convert.C [new file with mode: 0644]
src/support/tests/lstrings.C [new file with mode: 0644]
src/support/tests/regfiles/convert [new file with mode: 0644]
src/support/tests/regfiles/lstrings [new file with mode: 0644]
src/support/tests/test_convert [new file with mode: 0755]
src/support/tests/test_lstrings [new file with mode: 0755]
src/tabular.C
src/tex2lyx/ChangeLog
src/tex2lyx/Spacing.h
src/tex2lyx/tex2lyx.C
src/text3.C
src/vspace.C

index f67954d214a654c47f5eb99dfa795eafb1117dc3..ec310c697b9edd8c27ad6d1e97319f50898b0df7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * configure.ac: add src/support/tests/Makefile 
+
 2005-01-21  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * configure.ac: indicate in final info whether aiksaurus is used.
index b7a4f6fb070214e26660372b290f5dae20983a66..0524255537da6fc535c24c2cf86861074950ad89 100644 (file)
@@ -413,6 +413,7 @@ AC_CONFIG_FILES([Makefile  m4/Makefile \
        src/graphics/Makefile \
        src/insets/Makefile \
        src/support/Makefile \
+       src/support/tests/Makefile \
        src/frontends/Makefile \
        src/frontends/controllers/Makefile \
        src/frontends/xforms/Makefile \
index c6b71a96474920a1a24e77035313a2358c480662..c22855c2e5b2545e52d8fea62573b695b1d044de 100644 (file)
@@ -206,6 +206,7 @@ src/paragraph.C
 src/rowpainter.C
 src/support/filefilterlist.C
 src/support/package.C.in
+src/support/path_defines.C
 src/text.C
 src/text2.C
 src/text3.C
index f4a23d4a151028e6b5f6abc20a93a4de8ac34f02..7491e27213e26af48a1458d9a254455cdedc8ea5 100644 (file)
@@ -88,7 +88,6 @@ using lyx::support::IsDirWriteable;
 using lyx::support::MakeDisplayPath;
 using lyx::support::MakeAbsPath;
 using lyx::support::package;
-using lyx::support::strToUnsignedInt;
 
 using std::endl;
 using std::istringstream;
@@ -966,7 +965,7 @@ FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
                break;
 
        case LFUN_BOOKMARK_GOTO:
-               flag.enabled(bv_->isSavedPosition(strToUnsignedInt(cmd.argument)));
+               flag.enabled(bv_->isSavedPosition(convert<unsigned int>(cmd.argument)));
                break;
        case LFUN_TRACK_CHANGES:
                flag.enabled(true);
@@ -975,7 +974,7 @@ FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
 
        case LFUN_OUTPUT_CHANGES: {
                LaTeXFeatures features(*buf, buf->params(), false);
-               flag.enabled(buf && buf->params().tracking_changes 
+               flag.enabled(buf && buf->params().tracking_changes
                        && features.isAvailable("dvipost"));
                flag.setOnOff(buf->params().output_changes);
                break;
@@ -1052,11 +1051,11 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_BOOKMARK_SAVE:
-               savePosition(strToUnsignedInt(cmd.argument));
+               savePosition(convert<unsigned int>(cmd.argument));
                break;
 
        case LFUN_BOOKMARK_GOTO:
-               restorePosition(strToUnsignedInt(cmd.argument));
+               restorePosition(convert<unsigned int>(cmd.argument));
                break;
 
        case LFUN_REF_GOTO: {
index 6a90aa38161046da1209048ab91dc396c3405a68..dff1a7ae7078c471a0086e8c8c4342cf05f04d9e 100644 (file)
@@ -1,20 +1,28 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * lyxlayout.[Ch]: change some vars from float to double
+
+       * buffer.C (readFile): make a local var const
+
+       * Several files: use convert<> instead of atoi,strToXXX and friends
+
 2005-01-24  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * LaTeXFeatures.[Ch]: Add a static list packages_ that
        holds the contens of packages.lst. New functions getAvailable
        and isAvailable to parse and check that list, resp.
-       
+
        * LyXAction.C:
        * lfuns.h:
        * BufferView_pimpl.C: new LFUN_OUTPUT_CHANGES.
-       
+
        * bufferparams.[Ch]: new param output_changes.
-       
+
        * Buffer.C: increase file format to 240.
        Use output_changes and isVailable.
-       
-       * changes.[Ch]: 
-       * paragraph.C: 
+
+       * changes.[Ch]:
+       * paragraph.C:
        * paragraph_pimpl.C: Use output_changes and isVailable.
 
 2005-01-23  Angus Leeming  <leeming@lyx.org>
@@ -28,7 +36,7 @@
 
 2005-01-20  Angus Leeming  <leeming@lyx.org>
 
-       * lyxfont.C (setLyXFamily, setLyXSeries, setLyXShape, setLyXSize) 
+       * lyxfont.C (setLyXFamily, setLyXSeries, setLyXShape, setLyXSize)
        (setLyXMisc): (char string literal) != (char string literal) is
        performing a comparison on the addresses. Convert one operand
        explicitly to string to guarantee expected behaviour.
@@ -40,7 +48,7 @@
        * lyxlex_pimpl.[Ch]: use USE_COMPRESSION guard.
 
        * output_plaintext.C: remove unneeded #include gzstream.h.
-       
+
 2005-01-20  Angus Leeming  <leeming@lyx.org>
 
        * SpellBase.h: rename some of the elements of the Result enum.
index 4ad44c2fca4447f674d3bed647f6f585718989f4..bb9258c207d60c570e0e835bbe7b4454f31f827c 100644 (file)
 
 #include "LaTeX.h" // TeXErrors
 
+#include "support/convert.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
-#include "support/lyxlib.h"
 #include "support/systemcall.h"
 
 #include <boost/format.hpp>
 
 #include <fstream>
 
-using lyx::support::atoi;
 using lyx::support::ChangeExtension;
 using lyx::support::OnlyFilename;
 using lyx::support::split;
@@ -82,7 +81,7 @@ int Chktex::scanLogFile(TeXErrors & terr)
                token = split(token, warno, ':');
                token = split(token, warning, ':');
 
-               int const lineno = atoi(line);
+               int const lineno = convert<int>(line);
 
 #if USE_BOOST_FORMAT
                msg % warno;
index 8846a742ea016f28fc4f3591b1af9ae95e0b92ed..d8ca162657ee33a306e4e61c4b2836443fddaff3 100644 (file)
@@ -18,9 +18,7 @@
 #include <sstream>
 #include <string>
 
-using lyx::support::strToDbl;
 
-//using std::ios;
 using std::ostream;
 using std::ostringstream;
 using std::string;
@@ -45,11 +43,11 @@ string const Spacing::getValueAsString() const
 
 double Spacing::getValue() const
 {
-       return strToDbl(getValueAsString());
+       return convert<double>(getValueAsString());
 }
 
 
-void Spacing::set(Spacing::Space sp, float val)
+void Spacing::set(Spacing::Space sp, double val)
 {
        set(sp, convert<string>(val));
 }
@@ -59,7 +57,7 @@ void Spacing::set(Spacing::Space sp, string const & val)
 {
        space = sp;
        if (sp == Other) {
-               switch (int(strToDbl(val) * 1000 + 0.5)) {
+               switch (int(convert<double>(val) * 1000 + 0.5)) {
                case 1000:
                        space = Single;
                        break;
index 5c9d2c653492e32930432d8bb561bee6245c3d1c..617ec9269e2d92e57bec69118705395de12b90a5 100644 (file)
@@ -35,7 +35,7 @@ public:
        ///
        Spacing() : space(Default), value("1.0") {}
        ///
-       Spacing(Spacing::Space sp, float val = 1.0) {
+       Spacing(Spacing::Space sp, double val = 1.0) {
                set(sp, val);
        }
        Spacing(Spacing::Space sp, std::string const & val) {
@@ -52,7 +52,7 @@ public:
        ///
        Spacing::Space getSpace() const { return space; }
        ///
-       void set(Spacing::Space sp, float val = 1.0);
+       void set(Spacing::Space sp, double val = 1.0);
        ///
        void set(Spacing::Space sp, std::string const & val);
        ///
index de2a6ac83bbeec15adb00b3a1c6fb8a3ba1bbedc..1d6c5fa04fe9594f86d2f366deaee1c537861d5b 100644 (file)
@@ -111,7 +111,6 @@ using lyx::support::removeAutosaveFile;
 using lyx::support::rename;
 using lyx::support::RunCommand;
 using lyx::support::split;
-using lyx::support::strToInt;
 using lyx::support::subst;
 using lyx::support::tempName;
 using lyx::support::trim;
@@ -609,7 +608,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
        //lyxerr << "           dot found at " << dot << endl;
        if (dot != string::npos)
                        tmp_format.erase(dot, 1);
-       int file_format = strToInt(tmp_format);
+       int const file_format = convert<int>(tmp_format);
        //lyxerr << "format: " << file_format << endl;
 
        if (file_format != LYX_FORMAT) {
@@ -650,7 +649,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
                                              filename));
                        return false;
                } else {
-                       bool ret = readFile(tmpfile, pit);
+                       bool const ret = readFile(tmpfile, pit);
                        // Do stuff with tmpfile name and buffer name here.
                        return ret;
                }
@@ -1185,7 +1184,7 @@ void Buffer::validate(LaTeXFeatures & features) const
 {
        LyXTextClass const & tclass = params().getLyXTextClass();
 
-       if (features.isAvailable("dvipost") && params().tracking_changes 
+       if (features.isAvailable("dvipost") && params().tracking_changes
                && params().output_changes) {
                features.require("dvipost");
                features.require("color");
index e97330e2ff656542af8955fa7b42a7e54dca04d1..6a5631566d1d5843526d9895da4bbdc86b871118 100644 (file)
 
 #include "debug.h"
 
+#include "support/convert.h"
 #include "support/filetools.h"
-#include "support/lyxlib.h"
 
 #include <boost/regex.hpp>
 
 #include <fstream>
 
-using lyx::support::atoi;
 using lyx::support::LibFileSearch;
 
 using boost::regex;
@@ -66,7 +65,7 @@ bool CharacterSet::loadFile(string const & fname)
        while (getline(ifs, line)) {
                smatch sub;
                if (regex_match(line, sub, reg)) {
-                       int const n = atoi(sub.str(1));
+                       int const n = convert<int>(sub.str(1));
                        string const str = sub.str(2);
                        if (lyxerr.debugging(Debug::KBMAP))
                                lyxerr << "Chardef: " << n
index 4e105820c497a288edc2cd84853e9e518772403c..79dd123ee26c7cc2af2eeb554c4200d5aa54c8f7 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * debug.C: use convert<> instead of atoi,strToXXX and friends
+
 2005-01-20  Asger Ottar Alstrup  <aalstrup@laerdal.dk>
 
        * pch.h: use the HAVE_UNISTD_H preprocessor guard.
index 5da41b9f67398abb4820664bd78dafcffcb5dde7..bcc16194d44abc071cd453e92f30269f0968cc9a 100644 (file)
@@ -14,6 +14,7 @@
 #include "debug.h"
 #include "gettext.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 
 #include <iostream>
@@ -22,7 +23,6 @@
 using lyx::support::ascii_lowercase;
 using lyx::support::bformat;
 using lyx::support::isStrInt;
-using lyx::support::strToInt;
 
 using std::setw;
 using std::string;
@@ -61,7 +61,7 @@ lyx_debug_trait::type lyx_debug_trait::value(string const & val)
                        break;
                // Is it a number?
                if (isStrInt(tmp))
-                       l |= static_cast<type>(strToInt(tmp));
+                       l |= static_cast<type>(convert<int>(tmp));
                else
                // Search for an explicit name
                for (int i = 0 ; i < numErrorTags ; ++i)
index 2ddb9462fb09d279ec4259e123c5667bf970bca6..75852f61d9730fe59f7e900152a419c17fba3930 100644 (file)
@@ -14,6 +14,7 @@
 #include "debug.h"
 #include "gettext.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 
 #include <iostream>
@@ -22,7 +23,6 @@
 using lyx::support::ascii_lowercase;
 using lyx::support::bformat;
 using lyx::support::isStrInt;
-using lyx::support::strToInt;
 
 using std::setw;
 using std::string;
@@ -78,13 +78,13 @@ lyx_debug_trait::type lyx_debug_trait::value(string const & val)
        type l = Debug::NONE;
        string v(val);
        while (!v.empty()) {
-               string::size_type st = v.find(',');
-               string tmp(ascii_lowercase(v.substr(0, st)));
+               string::size_type const st = v.find(',');
+               string const tmp(ascii_lowercase(v.substr(0, st)));
                if (tmp.empty())
                        break;
                // Is it a number?
                if (isStrInt(tmp))
-                       l |= static_cast<type>(strToInt(tmp));
+                       l |= static_cast<type>(convert<int>(tmp));
                else
                // Search for an explicit name
                for (int i = 0 ; i < numErrorTags ; ++i)
index 047230d8183ee5a23180db4146c2cac02c2d6263..ca86aff1af7ab1993670139cb23c5e62a46a31c8 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * Several files: use convert<> instead of atoi,strToXXX and friends
+
 2005-01-10  Angus Leeming  <leeming@lyx.org>
 
        * ghelpers.C:
index a3c3931f53b9debff655334a8e82776aed2427f4..f7b7daacb3a6c080f4d73145906aed1d80cf1040 100644 (file)
@@ -26,9 +26,9 @@
 #include "paper.h"
 #include "lyxrc.h" // for lyxrc.default_papersize
 
+#include "support/convert.h"
 #include "support/lyxlib.h"  // for float_equal
 #include "support/lstrings.h"
-#include "support/convert.h"
 
 #include "debug.h"
 
@@ -38,7 +38,6 @@ using std::string;
 namespace lyx {
 
 using support::float_equal;
-using support::strToDbl;
 using support::token;
 
 namespace frontend {
@@ -372,7 +371,7 @@ void GGraphics::update() {
                displaycombo_->set_active(0);
        }
 
-       outputscalespin_->get_adjustment()->set_value(strToDbl(igp.scale));
+       outputscalespin_->get_adjustment()->set_value(convert<double>(igp.scale));
        widthspin_->get_adjustment()->set_value(igp.width.value());
        unitsComboFromLength(widthunitscombo_, stringcol_,
                             igp.width, defaultUnit);
@@ -381,7 +380,7 @@ void GGraphics::update() {
                             igp.height, defaultUnit);
 
        if (!igp.scale.empty()
-               && !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
+               && !float_equal(convert<double>(igp.scale), 0.0, 0.05)) {
                // scaling sizing mode
                setscalingradio_->set_active(true);
        } else {
@@ -400,7 +399,7 @@ void GGraphics::update() {
        clipcheck_->set_active(igp.clip);
 
        // the extra section
-       anglespin_->get_adjustment()->set_value(strToDbl(igp.rotateAngle));
+       anglespin_->get_adjustment()->set_value(convert<double>(igp.rotateAngle));
 
        int origin_pos;
        if (igp.rotateOrigin.empty()) {
index 54ec6849a0fbf9509b7859cbd20ee6818ee7e07a..cd9de15b83a13e2d4ac4064877486f18d50ba36d 100644 (file)
@@ -21,8 +21,8 @@
 
 #include "PrinterParams.h"
 
-#include "support/lstrings.h"
 #include "support/convert.h"
+#include "support/lstrings.h"
 
 #include <libglademm.h>
 
@@ -47,9 +47,9 @@ void GPrint::apply()
        pp.all_pages = all_->get_active();
        pp.from_page = pp.to_page = 0;
        if (!fromEntry_->get_text().empty()) {
-               pp.from_page = strToInt(fromEntry_->get_text());
+               pp.from_page = convert<int>(fromEntry_->get_text());
                if (!toEntry_->get_text().empty())
-                       pp.to_page = strToInt(toEntry_->get_text());
+                       pp.to_page = convert<int>(toEntry_->get_text());
        }
        pp.odd_pages = odd_->get_active();
        pp.even_pages = even_->get_active();
@@ -93,7 +93,7 @@ void GPrint::updateUI()
        if (fromTo_->get_active()) {
                string from = fromEntry_->get_text();
                string to = toEntry_->get_text();
-               if (from.empty() || (!to.empty() && strToInt(from) > strToInt(to)))
+               if (from.empty() || (!to.empty() && convert<int>(from) > convert<int>(to)))
                        activate = ButtonPolicy::SMI_INVALID;
        }
        bool const enableCounter = printer_->get_active();
index 098d3a2e34df6d7b3a2cd1694ff40e8144321945..3024b63dffa842bb7c977b411958de059ec150b2 100644 (file)
@@ -26,6 +26,7 @@
 #include "frontends/LyXView.h"
 #include "frontends/lyx_gui.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 #include "support/systemcall.h"
 #include "support/filetools.h"
@@ -33,8 +34,6 @@
 #include <cmath>       // fabs()
 #include <vector>
 
-using lyx::support::strToDbl;
-
 using std::endl;
 using std::string;
 
@@ -131,7 +130,7 @@ XftPattern * xftFontLoader::getFontPattern(LyXFont::FONT_FAMILY family,
        string ffamily;
        int fweight;
        int fslant;
-       double fsize = strToDbl(lyxrc.font_sizes[size]) * lyxrc.zoom / 100.0;
+       double fsize = convert<double>(lyxrc.font_sizes[size]) * lyxrc.zoom / 100.0;
        XftPattern *fpat = XftPatternCreate();
 
        ffamily = familyString(family);
index a6727c5513497d20345a5a3aea828ab85640872f..c6a7e1c9dee7fe7c638819cdb528161f993ae680 100644 (file)
@@ -1,7 +1,11 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * Several files: use convert<> instead of atoi,strToXXX and friends
+
 2005-01-20  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * floatplacement.C (heredefinitelyClicked): remove bogus
-       semicolon. 
+       semicolon.
 
 2005-01-15  Angus Leeming  <leeming@lyx.org>
 
index 9c2a3b1aaa465e43326b449824469705b0220c72..f9b6fca91187b6026c147ba0b62c317d71a66ee5 100644 (file)
@@ -42,8 +42,6 @@
 namespace external = lyx::external;
 
 using lyx::support::isStrDbl;
-using lyx::support::strToDbl;
-using lyx::support::strToInt;
 using lyx::support::token;
 using lyx::support::trim;
 
@@ -134,7 +132,7 @@ void getDisplay(external::DisplayType & display,
        if (!displayCB.isChecked())
                display = external::NoDisplay;
 
-       scale = strToInt(fromqstr(scaleED.text()));
+       scale = convert<int>(fromqstr(scaleED.text()));
 }
 
 
@@ -211,7 +209,7 @@ void getSize(external::ResizeData & data,
                if (isValidLength(width, &w))
                        data.width = w;
                else if (isStrDbl(width))
-                       data.width = LyXLength(strToDbl(width),
+                       data.width = LyXLength(convert<double>(width),
                                           static_cast<LyXLength::UNIT>(unit));
                else
                        data.width = LyXLength();
@@ -255,10 +253,10 @@ void getCrop(external::ClipData & data,
        if (!bb_changed)
                return;
 
-       data.bbox.xl = strToInt(fromqstr(xlED.text()));
-       data.bbox.yb = strToInt(fromqstr(ybED.text()));
-       data.bbox.xr = strToInt(fromqstr(xrED.text()));
-       data.bbox.yt = strToInt(fromqstr(ytED.text()));
+       data.bbox.xl = convert<int>(fromqstr(xlED.text()));
+       data.bbox.yb = convert<int>(fromqstr(ybED.text()));
+       data.bbox.xr = convert<int>(fromqstr(xrED.text()));
+       data.bbox.yt = convert<int>(fromqstr(ytED.text()));
 }
 
 
index 65341e94f5a32b5c4d72dce8abd81a07fc04744f..39f3fa8367a637bf5a5600db5dfa75537ed67618 100644 (file)
@@ -18,6 +18,7 @@
 #include "controllers/ButtonController.h"
 #include "controllers/ControlExternal.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
 
@@ -38,7 +39,6 @@
 
 using lyx::support::float_equal;
 using lyx::support::isStrDbl;
-using lyx::support::strToDbl;
 using std::string;
 
 namespace lyx {
@@ -100,7 +100,7 @@ bool QExternalDialog::activateAspectratio() const
        if (wstr.empty())
                return false;
        bool const wIsDbl = isStrDbl(wstr);
-       if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
+       if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
                return false;
        LyXLength l;
        if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
@@ -110,7 +110,7 @@ bool QExternalDialog::activateAspectratio() const
        if (hstr.empty())
                return false;
        bool const hIsDbl = isStrDbl(hstr);
-       if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
+       if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
                return false;
        if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
                return false;
index f54d4596952e621775c2053a86caa252b39a30eb..6589682058dfc27ff3f22a9cddb48ee0c59d8746 100644 (file)
@@ -28,8 +28,8 @@
 
 #include "insets/insetgraphicsParams.h"
 
-#include "support/lstrings.h"
 #include "support/convert.h"
+#include "support/lstrings.h"
 #include "support/lyxlib.h"
 
 #include <qlineedit.h>
@@ -41,8 +41,6 @@
 #include <cmath>
 
 using lyx::support::float_equal;
-using lyx::support::strToDbl;
-using lyx::support::strToInt;
 using lyx::support::token;
 
 #ifndef CXX_GLOBAL_CSTD
@@ -257,7 +255,7 @@ void QGraphics::update_contents()
                dialog_->widthUnit->insertItem(unit_name_gui[i], -1);
 
        if (!igp.scale.empty()
-               && !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
+               && !float_equal(convert<double>(igp.scale), 0.0, 0.05)) {
                dialog_->width->setText(toqstr(igp.scale));
                dialog_->widthUnit->setCurrentItem(0);
        } else {
@@ -320,8 +318,8 @@ void QGraphics::apply()
                string rtX(fromqstr(dialog_->rtX->text()));
                string rtY(fromqstr(dialog_->rtY->text()));
                int bb_sum =
-                       strToInt(lbX) + strToInt(lbY) +
-                       strToInt(rtX) + strToInt(rtX);
+                       convert<int>(lbX) + convert<int>(lbY) +
+                       convert<int>(rtX) + convert<int>(rtX);
                if (bb_sum) {
                        if (lbX.empty())
                                bb = "0 ";
@@ -378,11 +376,11 @@ void QGraphics::apply()
 
        igp.noUnzip = dialog_->unzipCB->isChecked();
 
-       igp.lyxscale = strToInt(fromqstr(dialog_->displayscale->text()));
+       igp.lyxscale = convert<int>(fromqstr(dialog_->displayscale->text()));
 
        igp.rotateAngle = fromqstr(dialog_->angle->text());
 
-       float rotAngle = strToDbl(igp.rotateAngle);
+       double rotAngle = convert<double>(igp.rotateAngle);
        if (std::abs(rotAngle) > 360.0) {
                rotAngle -= 360.0 * floor(rotAngle / 360.0);
                igp.rotateAngle = convert<string>(rotAngle);
index 3e2a9bedd9bd63a4ca457d6b72c07dfac31218de..f180a995f8d08ba9b2e99df566786eb77055049e 100644 (file)
@@ -24,7 +24,7 @@
 #include "ui/QPrefScreenFontsModule.h"
 #include "ui/QPrefColorsModule.h"
 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
-#include "ui/QPrefCygwinPathModule.h"  
+#include "ui/QPrefCygwinPathModule.h"
 #endif
 #include "ui/QPrefDisplayModule.h"
 #include "ui/QPrefPathsModule.h"
@@ -61,7 +61,6 @@
 #include <sstream>
 
 using lyx::support::compare_no_case;
-using lyx::support::strToDbl;
 
 using std::distance;
 using std::endl;
index e67ab77f3542e555e2de150af839d35a91f7c33e..72fd1181b1b5f7dde3593118f6f5ff03f2ec38b9 100644 (file)
@@ -27,7 +27,6 @@
 #include <qlineedit.h>
 #include <qpushbutton.h>
 
-using lyx::support::strToDbl;
 
 using std::string;
 
@@ -59,7 +58,7 @@ void QWrap::build_dialog()
 
 void QWrap::apply()
 {
-       double const value = strToDbl(fromqstr(dialog_->widthED->text()));
+       double const value = convert<double>(fromqstr(dialog_->widthED->text()));
        LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
        if (dialog_->widthED->text().isEmpty())
                unit = LyXLength::UNIT_NONE;
index 62b3c05a8ad5304d7ef664e769a4bbd7072bdee0..8353046132bd32ebebb38a77f4cf85c45f808bd0 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "frontends/lyx_gui.h"
 
+#include "support/convert.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/systemcall.h"
@@ -38,7 +39,6 @@ using lyx::support::LibFileSearch;
 using lyx::support::OnlyPath;
 using lyx::support::QuoteName;
 using lyx::support::Systemcall;
-using lyx::support::strToDbl;
 
 using std::endl;
 using std::make_pair;
@@ -316,7 +316,7 @@ qfont_loader::font_info::font_info(LyXFont const & f)
                }
        }
 
-       font.setPointSizeFloat(strToDbl(lyxrc.font_sizes[f.size()])
+       font.setPointSizeFloat(convert<double>(lyxrc.font_sizes[f.size()])
                               * lyxrc.zoom / 100.0);
 
        switch (f.series()) {
index 6300ff4ca1b4a3efa493fe306884b3c90986aa24..ea035a25a79384ce4840c1df9272c5842217f906 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * Several files: use convert<> instead of atoi,strToXXX and friends
+
 2005-01-20  Angus Leeming  <leeming@lyx.org>
 
        * FormPreferences.C: change the tooltip messages to reflect the
index bb30ae35429047a262b202127d270bb3ae12fab9..675ce939b327ad48835468ce880820647eba40d6 100644 (file)
@@ -32,7 +32,6 @@ using std::string;
 
 namespace lyx {
 
-using support::atoi;
 using support::token;
 
 namespace frontend {
@@ -143,14 +142,14 @@ void FontInfo::query()
                        string name(list[i]);
                        lyxerr[Debug::FONT] << "match #" << i << ' '
                                            << name << endl;
-                       sizes[i] = atoi(token(name, '-', 7));
+                       sizes[i] = convert<int>(token(name, '-', 7));
                        strings[i] = name;
                        if (sizes[i] == 0) {
                                if (scaleindex == -1) {
                                        scaleindex = i;
                                }
                                scalable = true;
-                       } else if (atoi(token(name, '-', 12)) == 0)
+                       } else if (convert<int>(token(name, '-', 12)) == 0)
                                // Ignore bogus matches of scalable fonts.
                                sizes[i] = 0;
                };
index c4cd302c7cd1a63ad1cba35f8a70ab1d22230236..7bffb9c4755c9022cd29df8707e150d39e8d4631 100644 (file)
@@ -47,8 +47,6 @@ using support::bformat;
 using support::float_equal;
 using support::getStringFromVector;
 using support::isStrDbl;
-using support::strToDbl;
-using support::strToInt;
 using support::token;
 using support::trim;
 
@@ -145,7 +143,7 @@ void getDisplay(external::DisplayType & display,
        if (!fl_get_button(displayCB))
                display = external::NoDisplay;
 
-       scale = strToInt(getString(scaleED));
+       scale = convert<int>(getString(scaleED));
 }
 
 
@@ -243,13 +241,12 @@ void getSize(external::ResizeData & data,
                if (isValidLength(width, &w))
                        data.width = w;
                else if (isStrDbl(width))
-                       data.width = LyXLength(strToDbl(width),
+                       data.width = LyXLength(convert<double>(width),
                                           static_cast<LyXLength::UNIT>(unit));
                else
                        data.width = LyXLength();
 
-               data.scale = string();
-
+               data.scale.erase();
        } else {
                // scaling instead of a width
                data.scale = width;
@@ -299,10 +296,10 @@ void getCrop(external::ClipData & data,
        if (!bb_changed)
                return;
 
-       data.bbox.xl = strToInt(getString(xlED));
-       data.bbox.yb = strToInt(getString(ybED));
-       data.bbox.xr = strToInt(getString(xrED));
-       data.bbox.yt = strToInt(getString(ytED));
+       data.bbox.xl = convert<int>(getString(xlED));
+       data.bbox.yb = convert<int>(getString(ybED));
+       data.bbox.xr = convert<int>(getString(xrED));
+       data.bbox.yt = convert<int>(getString(ytED));
 }
 
 
@@ -696,7 +693,7 @@ bool FormExternal::activateAspectratio() const
        if (wstr.empty())
                return false;
        bool const wIsDbl = isStrDbl(wstr);
-       if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
+       if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
                return false;
        LyXLength l;
        if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
@@ -706,7 +703,7 @@ bool FormExternal::activateAspectratio() const
        if (hstr.empty())
                return false;
        bool const hIsDbl = isStrDbl(hstr);
-       if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
+       if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
                return false;
        if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
                return false;
index b25b931f1d41bd5a2bf88d5bf489f14f46cf3a48..d794ac0f4279a1641c17c221400d2af4ee790cbe 100644 (file)
@@ -51,8 +51,6 @@ namespace lyx {
 using support::bformat;
 using support::float_equal;
 using support::getStringFromVector;
-using support::strToDbl;
-using support::strToInt;
 using support::token;
 
 namespace frontend {
@@ -306,7 +304,7 @@ void FormGraphics::apply()
        igp.filename.set(getString(file_->input_filename),
                         kernel().bufferFilepath());
 
-       igp.lyxscale = strToInt(getString(file_->input_lyxscale));
+       igp.lyxscale = convert<int>(getString(file_->input_lyxscale));
        if (igp.lyxscale == 0) {
                igp.lyxscale = 100;
        }
@@ -332,13 +330,13 @@ void FormGraphics::apply()
        if (fl_get_choice(file_->choice_width) == 1) {
                igp.scale = getString(file_->input_width);
                if (igp.scale.empty()
-                       || float_equal(strToDbl(igp.scale), 0.0, 0.05)
-                       || float_equal(strToDbl(igp.scale), 100.0, 0.05)) {
-                       igp.scale = string();
+                       || float_equal(convert<double>(igp.scale), 0.0, 0.05)
+                       || float_equal(convert<double>(igp.scale), 100.0, 0.05)) {
+                       igp.scale.erase();
                }
                igp.width = LyXLength();
        } else {
-               igp.scale = string();
+               igp.scale.erase();
                igp.width = LyXLength(getLengthFromWidgets(file_->input_width,
                                                           file_->choice_width));
        }
@@ -411,7 +409,7 @@ void FormGraphics::apply()
        igp.rotateAngle = getString(extra_->input_rotate_angle);
 
        // map angle into -360 (clock-wise) to +360 (counter clock-wise)
-       float rotAngle = strToDbl(igp.rotateAngle);
+       double rotAngle = convert<double>(igp.rotateAngle);
        if (std::abs(rotAngle) > 360.0) {
                 rotAngle -= 360.0 * floor(rotAngle / 360.0);
                 igp.rotateAngle = convert<string>(rotAngle);
@@ -461,7 +459,7 @@ void FormGraphics::update() {
        }
 
        // set width input fields according to scaling or width/height input
-       if (!igp.scale.empty() && !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
+       if (!igp.scale.empty() && !float_equal(convert<double>(igp.scale), 0.0, 0.05)) {
                fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
                fl_set_input_maxchars(file_->input_width, 0);
                fl_set_input(file_->input_width, igp.scale.c_str());
@@ -478,7 +476,7 @@ void FormGraphics::update() {
 
        // disable height input in case of scaling
        bool const disable_height = (!igp.scale.empty()
-               && !float_equal(strToDbl(igp.scale), 0.0, 0.05));
+               && !float_equal(convert<double>(igp.scale), 0.0, 0.05));
        setEnabled(file_->input_height, !disable_height);
        setEnabled(file_->choice_height, !disable_height);
 
@@ -502,11 +500,9 @@ void FormGraphics::update() {
        // the extra section
        fl_set_input(extra_->input_rotate_angle, igp.rotateAngle.c_str());
 
-       int origin_pos;
-       if (igp.rotateOrigin.empty()) {
-               origin_pos = 1;
-       } else {
-               origin_pos = 1 + findPos(origins_, igp.rotateOrigin);
+       int origin_pos = 1;
+       if (!igp.rotateOrigin.empty()) {
+               origin_pos += findPos(origins_, igp.rotateOrigin);
        }
        fl_set_choice(extra_->choice_origin, origin_pos);
 
index 042af27d8d18c9106454646cf06cb9538f30ca98..26b5c1ac3bc30da4eb17cf0b4543ad94ff9a5b2f 100644 (file)
@@ -28,6 +28,7 @@
 #include "LColor.h"
 #include "lyxfont.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 #include "support/package.h"
 #include "support/filetools.h"
@@ -52,7 +53,6 @@ using support::AddName;
 using support::ChangeExtension;
 using support::package;
 using support::rtrim;
-using support::strToDbl;
 using support::trim;
 
 namespace frontend {
@@ -2825,38 +2825,37 @@ bool FormPreferences::ScreenFonts::input()
 
        // Make sure that all fonts all have positive entries
        // Also note that an empty entry is returned as 0.0 by strToDbl
-       if (0.0 >= strToDbl(getString(dialog_->input_tiny))
-           || 0.0 >= strToDbl(getString(dialog_->input_script))
-           || 0.0 >= strToDbl(getString(dialog_->input_footnote))
-           || 0.0 >= strToDbl(getString(dialog_->input_small))
-           || 0.0 >= strToDbl(getString(dialog_->input_normal))
-           || 0.0 >= strToDbl(getString(dialog_->input_large))
-           || 0.0 >= strToDbl(getString(dialog_->input_larger))
-           || 0.0 >= strToDbl(getString(dialog_->input_largest))
-           || 0.0 >= strToDbl(getString(dialog_->input_huge))
-           || 0.0 >= strToDbl(getString(dialog_->input_huger))) {
+       if (0.0 >= convert<double>(fl_get_input(dialog_->input_tiny))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_script))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_footnote))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_small))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_normal))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_large))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_larger))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_largest))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_huge))
+           || 0.0 >= convert<double>(fl_get_input(dialog_->input_huger))) {
                activate = false;
                str = _("Fonts must be positive!");
-
-       } else if (strToDbl(getString(dialog_->input_tiny)) >
+       } else if (convert<double>(fl_get_input(dialog_->input_tiny)) >
                   // Fontsizes -- tiny < script < footnote etc.
-                  strToDbl(getString(dialog_->input_script)) ||
-                  strToDbl(getString(dialog_->input_script)) >
-                  strToDbl(getString(dialog_->input_footnote)) ||
-                  strToDbl(getString(dialog_->input_footnote)) >
-                  strToDbl(getString(dialog_->input_small)) ||
-                  strToDbl(getString(dialog_->input_small)) >
-                  strToDbl(getString(dialog_->input_normal)) ||
-                  strToDbl(getString(dialog_->input_normal)) >
-                  strToDbl(getString(dialog_->input_large)) ||
-                  strToDbl(getString(dialog_->input_large)) >
-                  strToDbl(getString(dialog_->input_larger)) ||
-                  strToDbl(getString(dialog_->input_larger)) >
-                  strToDbl(getString(dialog_->input_largest)) ||
-                  strToDbl(getString(dialog_->input_largest)) >
-                  strToDbl(getString(dialog_->input_huge)) ||
-                  strToDbl(getString(dialog_->input_huge)) >
-                  strToDbl(getString(dialog_->input_huger))) {
+                  convert<double>(fl_get_input(dialog_->input_script)) ||
+                  convert<double>(fl_get_input(dialog_->input_script)) >
+                  convert<double>(fl_get_input(dialog_->input_footnote)) ||
+                  convert<double>(fl_get_input(dialog_->input_footnote)) >
+                  convert<double>(fl_get_input(dialog_->input_small)) ||
+                  convert<double>(fl_get_input(dialog_->input_small)) >
+                  convert<double>(fl_get_input(dialog_->input_normal)) ||
+                  convert<double>(fl_get_input(dialog_->input_normal)) >
+                  convert<double>(fl_get_input(dialog_->input_large)) ||
+                  convert<double>(fl_get_input(dialog_->input_large)) >
+                  convert<double>(fl_get_input(dialog_->input_larger)) ||
+                  convert<double>(fl_get_input(dialog_->input_larger)) >
+                  convert<double>(fl_get_input(dialog_->input_largest)) ||
+                  convert<double>(fl_get_input(dialog_->input_largest)) >
+                  convert<double>(fl_get_input(dialog_->input_huge)) ||
+                  convert<double>(fl_get_input(dialog_->input_huge)) >
+                  convert<double>(fl_get_input(dialog_->input_huger))) {
                activate = false;
 
                str = _("Fonts must be input in the order Tiny > Smallest > Smaller > Small > Normal > Large > Larger > Largest > Huge > Huger.");
index 1d892878586b434293d0d74586cfafb4d5a1d3ca..f966da573d61c619c6977c33ae2cd08b6df3e1c6 100644 (file)
@@ -31,8 +31,6 @@ using std::string;
 
 namespace lyx {
 
-using support::strToInt;
-
 namespace frontend {
 
 typedef FormController<ControlPrint, FormView<FD_print> > base_class;
@@ -128,10 +126,10 @@ void FormPrint::apply()
        pp.from_page = pp.to_page = 0;
        if (!getString(dialog_->input_from_page).empty()) {
                // we have at least one page requested
-               pp.from_page = strToInt(fl_get_input(dialog_->input_from_page));
+               pp.from_page = convert<int>(fl_get_input(dialog_->input_from_page));
                if (!getString(dialog_->input_to_page).empty()) {
                        // okay we have a range
-                       pp.to_page = strToInt(fl_get_input(dialog_->input_to_page));
+                       pp.to_page = convert<int>(fl_get_input(dialog_->input_to_page));
                } // else we only print one page.
        }
 
@@ -228,18 +226,18 @@ ButtonPolicy::SMInput FormPrint::input(FL_OBJECT * ob, long)
                bool const to_input = static_cast<bool>(*to);
 
                setEnabled(dialog_->input_to_page, from_input);
-               if (!from_input || (to_input && strToInt(from) > strToInt(to))) {
+               if (!from_input || (to_input && convert<int>(from) > convert<int>(to))) {
                        // Invalid input. Either 'from' is empty, or 'from' > 'to'.
                        // Probably editting these fields, so deactivate OK/Apply until input is valid again.
                        activate = ButtonPolicy::SMI_INVALID;
-               } else if (!to_input || strToInt(from) == strToInt(to)) {
+               } else if (!to_input || convert<int>(from) == convert<int>(to)) {
                        // Valid input. Either there's only 'from' input, or 'from' == 'to'.
                        // Deactivate OK/Apply if odd/even selection implies no pages.
                        bool const odd_pages = static_cast<bool>(fl_get_button(dialog_->check_odd_pages));
                        bool const even_pages = static_cast<bool>(fl_get_button(dialog_->check_even_pages));
                        bool const odd_only = odd_pages && !even_pages;
                        bool const even_only = even_pages && !odd_pages;
-                       bool const from_is_odd = static_cast<bool>(strToInt(from) % 2);
+                       bool const from_is_odd = static_cast<bool>(convert<int>(from) % 2);
                        if ( (from_is_odd && even_only) || (!from_is_odd && odd_only) ) {
                                activate = ButtonPolicy::SMI_INVALID;
                        }
index f9a1a74837e0a2544f3a53feb55bd0c12a843875..ffe46322f6a41c7a033aca9b73fd4069cf2c9cf4 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "frontends/lyx_gui.h"
 
+#include "support/convert.h"
 #include "support/filetools.h"
-#include "support/lstrings.h"
 #include "support/systemcall.h"
 
 #include "lyx_forms.h"
@@ -33,7 +33,6 @@ using std::string;
 namespace lyx {
 
 using support::LibFileSearch;
-using support::strToDbl;
 using support::OnlyPath;
 using support::Systemcall;
 
@@ -333,7 +332,7 @@ XFontStruct * xfont_loader::doLoad(LyXFont::FONT_FAMILY family,
 
        getFontinfo(family, series, shape);
        // FIXME! CHECK! Should we use 72.0 or 72.27? (Lgb)
-       int fsize = int((strToDbl(lyxrc.font_sizes[size]) * lyxrc.dpi *
+       int fsize = int((convert<double>(lyxrc.font_sizes[size]) * lyxrc.dpi *
                          (lyxrc.zoom/100.0)) / 72.27 + 0.5);
 
        string font = fontinfo[family][series][shape]->getFontname(fsize);
index 8166642e0291b5852c41088448184edd4ba11dc7..b202c4ac1ae317d84646863b046dbbf7362881a9 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * PreviewLoader.C (Impl): use convert<> instead of atoi,strToXXX
+       and friends
+
+       * GraphicsParams.h (class Params): change angle from float to double
+
 2005-01-06  Lars Gullik Bjonnes  <larsbj@gullik.net>
 
        * PreviewLoader.C (unique_filename): tostr -> convert
index 1f633e768560c795f93652f42cf28a43deb163a7..222b50f85c0b752aa98e238bce57d71f36c278bb 100644 (file)
@@ -69,7 +69,7 @@ public:
         *  image.
         */
        /// Rotation angle.
-       float angle;
+       double angle;
 };
 
 bool operator==(Params const &, Params const &);
index 8dbc512ce32f4c1a51d4ad977445b7f9a10d6108..ddedc11b2c9b43a162fcfdf0d1a1b37b43f32c6e 100644 (file)
@@ -320,7 +320,7 @@ PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
        : parent_(p), buffer_(b), font_scaling_factor_(0.0)
 {
        font_scaling_factor_ = 0.01 * lyxrc.dpi * lyxrc.zoom *
-               support::strToDbl(lyxrc.preview_scale_factor);
+               convert<double>(lyxrc.preview_scale_factor);
 
        lyxerr[Debug::GRAPHICS] << "The font scaling factor is "
                                << font_scaling_factor_ << endl;
index 135b8a8e98cb36eed5d4e62f433a70c02a42c06f..74c311c28b4dc5a4e891d710a9d19bce962570e0 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * Several files: use convert<> instead of atoi,strToXXX and friends
+
 2005-01-23  Angus Leeming  <leeming@lyx.org>
 
        * insetbibitem.h (bibitemWidest): declare the function.
index ffc66cfb12ccb733d2df30918465a5a438690953..43b69eece17870fd81558d4d0ef30a87cfc722bb 100644 (file)
@@ -25,7 +25,6 @@
 #include <sstream>
 
 using lyx::support::float_equal;
-using lyx::support::strToDbl;
 
 using std::string;
 
@@ -54,20 +53,20 @@ bool ResizeData::no_resize() const
 
 bool ResizeData::usingScale() const
 {
-       return (!scale.empty() && !float_equal(strToDbl(scale), 0.0, 0.05));
+       return (!scale.empty() && !float_equal(convert<double>(scale), 0.0, 0.05));
 }
 
 
 bool RotationData::no_rotation() const
 {
-       return (angle.empty() || std::abs(strToDbl(angle)) < 0.1);
+       return (angle.empty() || std::abs(convert<double>(angle)) < 0.1);
 }
 
 
 string const RotationData::adjAngle() const
 {
        // Ensure that angle lies in the range -360 < angle < 360
-       double rotAngle = strToDbl(angle);
+       double rotAngle = convert<double>(angle);
        if (std::abs(rotAngle) > 360.0) {
                rotAngle -= 360.0 * floor(rotAngle / 360.0);
                return convert<string>(rotAngle);
@@ -103,7 +102,7 @@ string const ResizeLatexCommand::front_impl() const
 
        std::ostringstream os;
        if (data.usingScale()) {
-               double const scl = strToDbl(data.scale) / 100.0;
+               double const scl = convert<double>(data.scale) / 100.0;
                os << "\\scalebox{" << scl << "}[" << scl << "]{";
        } else {
                string width  = "!";
@@ -235,7 +234,7 @@ string const ResizeLatexOption::option_impl() const
 
        std::ostringstream os;
        if (data.usingScale()) {
-               double scl = strToDbl(data.scale);
+               double const scl = convert<double>(data.scale);
                if (!float_equal(scl, 100.0, 0.05))
                        os << "scale=" << scl / 100.0 << ',';
                return os.str();
index 97dca124735548691da66068e1779ee02183e6f8..19144e23104a65c0388056698498f82d43af5757 100644 (file)
@@ -28,7 +28,6 @@
 #include "support/convert.h"
 
 using lyx::support::prefixIs;
-using lyx::support::strToInt;
 
 using std::max;
 using std::string;
@@ -103,7 +102,7 @@ void InsetBibitem::read(Buffer const &, LyXLex & lex)
                lex.printError("InsetCommand: Parse error: `$$Token'");
 
        if (prefixIs(getContents(), key_prefix)) {
-               int key = strToInt(getContents().substr(key_prefix.length()));
+               int const key = convert<int>(getContents().substr(key_prefix.length()));
                key_counter = max(key_counter, key);
        }
 }
index 3a9a6704644d2849bdca853d571305a327b0e02f..17bf4215ca2097927b45b30401b05bf67d839cb7 100644 (file)
@@ -210,7 +210,7 @@ void InsetCollapsable::getCursorPos
                y = yo();
                return;
        }
-       
+
        InsetText::getCursorPos(sl, x, y);
        if (status_ == Open) {
                if (openinlined_)
@@ -408,7 +408,7 @@ void InsetCollapsable::setLabelFont(LyXFont & font)
 }
 
 
-void InsetCollapsable::scroll(BufferView & bv, float sx) const
+void InsetCollapsable::scroll(BufferView & bv, double sx) const
 {
        UpdatableInset::scroll(bv, sx);
 }
@@ -418,4 +418,3 @@ void InsetCollapsable::scroll(BufferView & bv, int offset) const
 {
        UpdatableInset::scroll(bv, offset);
 }
-
index 6fbc5658dc32fec56d4ed1ba6ab1ec04eef354b2..763b5b49f08a8d27c8188e7287394f611652550c 100644 (file)
@@ -73,7 +73,7 @@ public:
        ///
        int scroll(bool recursive = true) const;
        ///
-       void scroll(BufferView & bv, float sx) const;
+       void scroll(BufferView & bv, double sx) const;
        ///
        void scroll(BufferView & bv, int offset) const;
        ///
index 3bbf20e91badb8b03b0141e152534dcf5f2e1dfa..522ccc6081e87c501425601b03f114922b1ad5ab 100644 (file)
@@ -228,7 +228,7 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
 
        if (!resizedata.no_resize()) {
                using support::float_equal;
-               double scl = support::strToDbl(resizedata.scale);
+               double const scl = convert<double>(resizedata.scale);
                if (!float_equal(scl, 0.0, 0.05)) {
                        if (!float_equal(scl, 100.0, 0.05))
                                os << "\tscale "
@@ -524,7 +524,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
        gparams.scale = eparams.lyxscale;
        if (eparams.clipdata.clip)
                gparams.bb = eparams.clipdata.bbox;
-       gparams.angle = lyx::support::strToDbl(eparams.rotationdata.adjAngle());
+       gparams.angle = convert<double>(eparams.rotationdata.adjAngle());
 
        switch (eparams.display) {
        case external::DefaultDisplay:
index 0ef5fcc8708358dc34dd3d13603d68b1769287ed..e6e69ca92da75cfdcea6c642d50995203f1814b6 100644 (file)
@@ -74,6 +74,7 @@ TODO
 #include "frontends/Alert.h"
 #include "frontends/LyXView.h"
 
+#include "support/convert.h"
 #include "support/filetools.h"
 #include "support/lyxalgo.h" // lyx::count
 #include "support/lyxlib.h" // lyx::sum
@@ -99,7 +100,6 @@ using lyx::support::GetExtension;
 using lyx::support::IsFileReadable;
 using lyx::support::OnlyFilename;
 using lyx::support::rtrim;
-using lyx::support::strToDbl;
 using lyx::support::subst;
 using lyx::support::Systemcall;
 using lyx::support::unzipFile;
@@ -299,7 +299,7 @@ string const InsetGraphics::createLatexOptions() const
            options << " draft,\n";
        if (params().clip)
            options << " clip,\n";
-       double const scl = strToDbl(params().scale);
+       double const scl = convert<double>(params().scale);
        if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
                if (!float_equal(scl, 100.0, 0.05))
                        options << " scale=" << scl / 100.0
@@ -316,7 +316,7 @@ string const InsetGraphics::createLatexOptions() const
        // Make sure rotation angle is not very close to zero;
        // a float can be effectively zero but not exactly zero.
        if (!params().rotateAngle.empty()
-               && !float_equal(strToDbl(params().rotateAngle), 0.0, 0.001)) {
+               && !float_equal(convert<double>(params().rotateAngle), 0.0, 0.001)) {
            options << "  angle=" << params().rotateAngle << ",\n";
            if (!params().rotateOrigin.empty()) {
                options << "  origin=" << params().rotateOrigin[0];
@@ -405,7 +405,7 @@ string const InsetGraphics::createDocBookAttributes() const
        // Right now it only works with my version of db2latex :-)
 
        ostringstream options;
-       double const scl = strToDbl(params().scale);
+       double const scl = convert<double>(params().scale);
        if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
                if (!float_equal(scl, 100.0, 0.05))
                        options << " scale=\""
index 8e0496ef344a89c0c388ea71432497765867e8be..fd9678471c48f428560de8c41701984cb1875c8b 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "graphics/GraphicsParams.h"
 
+#include "support/convert.h"
 #include "support/filetools.h"
 #include "support/lyxlib.h"
 #include "support/lstrings.h"
@@ -28,8 +29,6 @@
 
 using lyx::support::float_equal;
 using lyx::support::readBB_from_PSFile;
-using lyx::support::strToDbl;
-using lyx::support::strToInt;
 using lyx::support::token;
 
 using std::string;
@@ -155,8 +154,8 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
                os << "\tlyxscale " << lyxscale << '\n';
        if (display != lyx::graphics::DefaultDisplay)
                os << "\tdisplay " << lyx::graphics::displayTranslator().find(display) << '\n';
-       if (!scale.empty() && !float_equal(strToDbl(scale), 0.0, 0.05)) {
-               if (!float_equal(strToDbl(scale), 100.0, 0.05))
+       if (!scale.empty() && !float_equal(convert<double>(scale), 0.0, 0.05)) {
+               if (!float_equal(convert<double>(scale), 100.0, 0.05))
                        os << "\tscale " << scale << '\n';
        } else {
                if (!width.zero())
@@ -178,7 +177,7 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
                os << "\tclip\n";
 
        if (!rotateAngle.empty()
-               && !float_equal(strToDbl(rotateAngle), 0.0, 0.001))
+               && !float_equal(convert<double>(rotateAngle), 0.0, 0.001))
                os << "\trotateAngle " << rotateAngle << '\n';
        if (!rotateOrigin.empty())
                os << "\trotateOrigin " << rotateOrigin << '\n';
@@ -267,7 +266,7 @@ lyx::graphics::Params InsetGraphicsParams::as_grfxParams() const
        lyx::graphics::Params pars;
        pars.filename = filename.absFilename();
        pars.scale = lyxscale;
-       pars.angle = lyx::support::strToDbl(rotateAngle);
+       pars.angle = convert<double>(rotateAngle);
 
        if (clip) {
                pars.bb = bb;
@@ -276,8 +275,9 @@ lyx::graphics::Params InsetGraphicsParams::as_grfxParams() const
                string const tmp = readBB_from_PSFile(filename.absFilename());
                lyxerr[Debug::GRAPHICS] << "BB_from_File: " << tmp << std::endl;
                if (!tmp.empty()) {
-                       unsigned int const bb_orig_xl = strToInt(token(tmp, ' ', 0));
-                       unsigned int const bb_orig_yb = strToInt(token(tmp, ' ', 1));
+#warning why not convert to unsigned int? (Lgb)
+                       unsigned int const bb_orig_xl = convert<int>(token(tmp, ' ', 0));
+                       unsigned int const bb_orig_yb = convert<int>(token(tmp, ' ', 1));
 
                        // new pars.bb values must be >= zero
                        if  (pars.bb.xl > bb_orig_xl)
index a247e0a472c4e937d1c4ddbe1dcfcf39c25cfe9c..6a10ab8f77c438f5dd4a126e2e389d62e273ce5e 100644 (file)
@@ -33,6 +33,8 @@
 #include "ParagraphParameters.h"
 #include "undo.h"
 
+#include "support/convert.h"
+
 #include "frontends/Alert.h"
 #include "frontends/font_metrics.h"
 #include "frontends/LyXView.h"
@@ -46,8 +48,6 @@
 using lyx::graphics::PreviewLoader;
 
 using lyx::support::ltrim;
-using lyx::support::strToInt;
-using lyx::support::strToDbl;
 
 using boost::shared_ptr;
 
@@ -496,9 +496,9 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
                if (cmd.argument.empty())
                        break;
                if (cmd.argument.find('.') != cmd.argument.npos)
-                       scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
+                       scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
                else
-                       scroll(cur.bv(), strToInt(cmd.argument));
+                       scroll(cur.bv(), convert<int>(cmd.argument));
                break;
 
        case LFUN_RIGHTSEL:
@@ -878,7 +878,7 @@ bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd,
                        break;
 
                case LyXTabular::SET_USEBOX:
-                       status.setOnOff(strToInt(argument) == tabular.getUsebox(cur.idx()));
+                       status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
                        break;
 
                case LyXTabular::SET_LTFIRSTHEAD:
@@ -1496,7 +1496,7 @@ void InsetTabular::tabularFeatures(LCursor & cur,
                break;
 
        case LyXTabular::SET_USEBOX: {
-               LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
+               LyXTabular::BoxType val = LyXTabular::BoxType(convert<int>(value));
                if (val == tabular.getUsebox(cur.idx()))
                        val = LyXTabular::BOX_NONE;
                for (row_type i = sel_row_start; i <= sel_row_end; ++i)
index a402cbb526500b43118a582dbc87b424448dd1b3..144aa4fb4578f668634fd5281beaa1143b791e0e 100644 (file)
@@ -57,7 +57,6 @@ using lyx::pos_type;
 using lyx::graphics::PreviewLoader;
 
 using lyx::support::isStrUnsignedInt;
-using lyx::support::strToUnsignedInt;
 
 using boost::bind;
 using boost::ref;
index eb68e226db539b46c313eec9bfe510c0f419d906..1018a97bde0d12f5575bd1bed0d36f18bf5fb2d0 100644 (file)
 #include "funcrequest.h"
 #include "lyxtext.h"
 
-#include "support/lstrings.h"
+#include "support/convert.h"
 
 #include <boost/assert.hpp>
 
-using lyx::support::strToDbl;
-using lyx::support::strToInt;
-
-
 
 // An updatable inset is highly editable by definition
 InsetBase::EDITABLE UpdatableInset::editable() const
@@ -39,7 +35,7 @@ InsetBase::EDITABLE UpdatableInset::editable() const
 }
 
 
-void UpdatableInset::scroll(BufferView & bv, float s) const
+void UpdatableInset::scroll(BufferView & bv, double s) const
 {
        if (!s) {
                scx = 0;
@@ -52,7 +48,7 @@ void UpdatableInset::scroll(BufferView & bv, float s) const
 
        if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
                return;
-       if (s > 0 && xo_ > 0)
+       if (s > 0.0 && xo_ > 0)
                return;
 
        scx = int(s * workW / 2);
@@ -100,9 +96,9 @@ void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_SCROLL_INSET:
                if (cmd.argument.empty()) {
                        if (cmd.argument.find('.') != cmd.argument.npos)
-                               scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
+                               scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
                        else
-                               scroll(cur.bv(), strToInt(cmd.argument));
+                               scroll(cur.bv(), convert<int>(cmd.argument));
                        cur.bv().update();
                }
                break;
index 1bc7253025fd145e4f00539533cee6cbb2f76642..e2a5972ffecb7add953f0c17bcdccb3bce2fb963 100644 (file)
@@ -40,7 +40,7 @@ protected:
        ///  An updatable inset could handle lyx editing commands
        virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
        /// scrolls to absolute position in bufferview-workwidth * sx units
-       void scroll(BufferView &, float sx) const;
+       void scroll(BufferView &, double sx) const;
        /// scrolls offset pixels
        void scroll(BufferView &, int offset) const;
 };
index 3420f6443de1ae4c88ea88866fe2ae280e685638..79b08db2903c134c6885d54fc37775a2b0a948fc 100644 (file)
@@ -113,8 +113,6 @@ using lyx::support::Path;
 using lyx::support::QuoteName;
 using lyx::support::rtrim;
 using lyx::support::split;
-using lyx::support::strToInt;
-using lyx::support::strToUnsignedInt;
 using lyx::support::subst;
 using lyx::support::Systemcall;
 using lyx::support::token;
index 25452e7a0f37957f8d0a46fa70949af0c60a97e3..25d07d90a8fa5dbb87dfba3c49056266bb7e526c 100644 (file)
@@ -110,17 +110,17 @@ public:
        /// Text that dictates the width of the indentation of indented pars
        std::string parindent;
        ///
-       float parskip;
+       double parskip;
        ///
-       float itemsep;
+       double itemsep;
        ///
-       float topsep;
+       double topsep;
        ///
-       float bottomsep;
+       double bottomsep;
        ///
-       float labelbottomsep;
+       double labelbottomsep;
        ///
-       float parsep;
+       double parsep;
        ///
        Spacing spacing;
        ///
index 664d95cfe91a5e8febc8ff2cdb0f90fe759d6766..6758dc167d767a3632e2525785e5a0a6eaa6c6b4 100644 (file)
@@ -18,6 +18,7 @@
 #include "debug.h"
 #include "lyxlex_pimpl.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 
 using lyx::support::compare_ascii_no_case;
@@ -25,8 +26,6 @@ using lyx::support::isStrDbl;
 using lyx::support::isStrInt;
 using lyx::support::ltrim;
 using lyx::support::prefixIs;
-using lyx::support::strToDbl;
-using lyx::support::strToInt;
 using lyx::support::subst;
 using lyx::support::trim;
 
@@ -121,20 +120,20 @@ int LyXLex::lex()
 int LyXLex::getInteger() const
 {
        if (isStrInt(pimpl_->getString()))
-               return strToInt(pimpl_->getString());
+               return convert<int>(pimpl_->getString());
        pimpl_->printError("Bad integer `$$Token'");
        return -1;
 }
 
 
-float LyXLex::getFloat() const
+double LyXLex::getFloat() const
 {
        // replace comma with dot in case the file was written with
        // the wrong locale (should be rare, but is easy enough to
        // avoid).
-       string str = subst(pimpl_->getString(), ",", ".");
+       string const str = subst(pimpl_->getString(), ",", ".");
        if (isStrDbl(str))
-               return strToDbl(str);
+               return convert<double>(str);
        pimpl_->printError("Bad float `$$Token'");
        return -1;
 }
@@ -256,7 +255,7 @@ LyXLex & LyXLex::operator>>(std::string & s)
 }
 
 
-LyXLex & LyXLex::operator>>(float & s)
+LyXLex & LyXLex::operator>>(double & s)
 {
        if (isOK()) {
                next();
index cc13fbd93585ebe91f389b45f2b9a430d8f1e533..dc16b52b1a7a7a19c3f1764d72dbb123e70c02fa 100644 (file)
@@ -96,7 +96,7 @@ public:
        ///
        bool getBool() const;
        ///
-       float getFloat() const;
+       double getFloat() const;
        ///
        std::string const getString() const;
 
@@ -131,8 +131,6 @@ public:
 
        /// extract string
        LyXLex & operator>>(std::string &);
-       /// extract float
-       LyXLex & operator>>(float &);
        /// extract double
        LyXLex & operator>>(double &);
        /// extract integer
index 82577fe5349cd4c88389d99d9fd36a481f19a82e..3de9c489f6775a5f4f5d6d31a7afd62713e1a94d 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * math_parser.C,math_sizeinset.C: use convert<> instead of
+       atoi,strToXXX and friends
+
 2005-01-20  Angus Leeming  <leeming@lyx.org>
 
        * math_spaceinset.C (validate):
index 9bf89d8e0846966e77d46fbf78ce99682f20ddc9..1903f0432e11cfbf34596d8888a587a17216b170 100644 (file)
@@ -62,11 +62,10 @@ following hack as starting point to write some macros:
 
 #include "lyxlex.h"
 #include "debug.h"
-#include "support/lyxlib.h"
 
-#include <sstream>
+#include "support/convert.h"
 
-using lyx::support::atoi;
+#include <sstream>
 
 using std::endl;
 using std::fill;
@@ -854,9 +853,9 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                        return;
                                }
 
-                               string arg  = getArg('[', ']');
+                               string const arg  = getArg('[', ']');
                                if (!arg.empty())
-                                       nargs = atoi(arg);
+                                       nargs = convert<int>(arg);
 
                        }
 
index 7bed06ea227d51762f7bd61101dd589dabd5a4db..099e421694406a9cd9f88930cd9581e0db0b6363 100644 (file)
 #include "math_parser.h"
 #include "math_streamstr.h"
 
+#include "support/convert.h"
 #include "support/std_ostream.h"
-#include "support/lyxlib.h"
-
-using lyx::support::atoi;
 
 using std::auto_ptr;
 
 
 MathSizeInset::MathSizeInset(latexkeys const * l)
-       : MathNestInset(1), key_(l), style_(Styles(atoi(l->extra)))
+       : MathNestInset(1), key_(l), style_(Styles(convert<int>(l->extra)))
 {}
 
 
index 6e7e56bc99b7f5df79d7864a8e7702805aa8f193..3338ae73918a180546c465dd8aafd98d15dfd51d 100644 (file)
@@ -1,3 +1,24 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * tests: add some code for automatic regression testing, can be
+       improved or removed as we see fit
+       
+       * lyxlib.h (atoi): delete func
+       
+       * lstrings.[Ch] (strToInt): delete func
+       (strToUnsignedInt): delete func
+       (strToDbl): delete func
+
+       * Makefile.am: add subdir tests, delete atoi.C
+
+       * atoi.C: delete file
+
+       * convert.C: add specializations for converting to int, unsigned
+       int, double from string, and for converting to int and double from
+       char const *
+
+       * convert.h: remove commented code
+
 2005-01-22  Angus Leeming   <leeming@lyx.org>
 
        * path.C (Path): revert the patch since the if statement has side
@@ -28,7 +49,7 @@
        * filetools.[Ch] (LibScriptSearch): modify the code that replaces
        the $$s placeholder with a path, so that it now inserts the path
        of the lyx support directory, not the scripts subdirectory.
-       
+
 2005-01-19  Asger Ottar Alstrup  <aalstrup@laerdal.dk>
 
        * lyxsum.C, socktools.C, tempname.C, userinfo.C: use the
index de6adecb9c6387474a856a33739525f7eb056729..47ad20e263eefc954b5a3b596dd761f6435956f3 100644 (file)
@@ -1,5 +1,7 @@
 include $(top_srcdir)/config/common.am
 
+SUBDIRS = . tests
+
 noinst_LTLIBRARIES = libsupport.la
 
 CLEANFILES += path_defines.C
@@ -20,7 +22,6 @@ libsupport_la_SOURCES = \
        FileMonitor.h \
        FileMonitor.C \
        abort.C \
-       atoi.C \
        chdir.C \
        convert.C \
        convert.h \
diff --git a/src/support/atoi.C b/src/support/atoi.C
deleted file mode 100644 (file)
index 674c2ed..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * \file atoi.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author Jean-Marc Lasgouttes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "support/lyxlib.h"
-
-#include <cstdlib>
-
-#ifndef CXX_GLOBAL_CSTD
-using std::atoi;
-#endif
-
-int lyx::support::atoi(std::string const & nstr)
-{
-       return ::atoi(nstr.c_str());
-}
index 800ae8fc99afd9015edf0a3a65c830013d3478e8..262f937addd8e60bb947e0ea2c9929959dd79ef0 100644 (file)
@@ -83,3 +83,38 @@ string convert<string>(double d)
 {
        return lexical_cast<string>(d);
 }
+
+
+template<>
+int convert<int>(string const s)
+{
+       return strtol(s.c_str(), 0, 10);
+}
+
+
+template<>
+unsigned int convert<unsigned int>(string const s)
+{
+       return strtoul(s.c_str(), 0, 10);
+}
+
+
+template<>
+double convert<double>(string const s)
+{
+       return strtod(s.c_str(), 0);
+}
+
+
+template<>
+int convert<int>(char const * cptr)
+{
+       return strtol(cptr, 0, 10);
+}
+
+
+template<>
+double convert<double>(char const * cptr)
+{
+       return strtod(cptr, 0);
+}
index da1947b843ad25c67213827f707f593737a240f4..66b136491fb92dcb5046280925eee6f115f9830e 100644 (file)
 #ifndef CONVERT_H
 #define CONVERT_H
 
-#if 0
-#include <boost/static_assert.hpp>
-
-// Commented out since BOOST_STATIC_ASSERT does not work with gcc 4.0
-template <class Target, class Source>
-Target convert(Source arg)
-{
-       // We use a static assert here since we want all instances of
-       // this template to be specializations.
-       BOOST_STATIC_ASSERT(sizeof(bool) == 0);
-       return Target();
-}
-#else
 template <class Target, class Source>
 Target convert(Source arg);
-#endif
 
 #endif
index 65c238ecfc6596eec8f7f3d03b46bd20d702e06c..fb7af0a7328a373cd9c33ce41dcba1598c88b39a 100644 (file)
@@ -37,7 +37,6 @@ using std::string;
 using std::vector;
 
 #ifndef CXX_GLOBAL_CSTD
-using std::atof;
 using std::isdigit;
 using std::tolower;
 using std::toupper;
@@ -158,32 +157,6 @@ bool isStrUnsignedInt(string const & str)
 }
 
 
-int strToInt(string const & str)
-{
-       if (isStrInt(str)) {
-               // Remove leading and trailing white space chars.
-               string const tmpstr = trim(str);
-               // Do the conversion proper.
-               return atoi(tmpstr);
-       } else {
-               return 0;
-       }
-}
-
-
-unsigned int strToUnsignedInt(string const & str)
-{
-       if (isStrUnsignedInt(str)) {
-               // Remove leading and trailing white space chars.
-               string const tmpstr = trim(str);
-               // Do the conversion proper.
-               return atoi(tmpstr);
-       } else {
-               return 0;
-       }
-}
-
-
 bool isStrDbl(string const & str)
 {
        if (str.empty()) return false;
@@ -214,19 +187,6 @@ bool isStrDbl(string const & str)
 }
 
 
-double strToDbl(string const & str)
-{
-       if (isStrDbl(str)) {
-               // Remove leading and trailing white space chars.
-               string const tmpstr = trim(str);
-               // Do the conversion proper.
-               return ::atof(tmpstr.c_str());
-       } else {
-               return 0.0;
-       }
-}
-
-
 char lowercase(char c)
 {
        return char(tolower(c));
index ab75fd6202e11565d7fea1939f8f5525bb5d4929..995d96b0809c15c815931fb3a2b24d5b11e24425 100644 (file)
@@ -60,18 +60,9 @@ bool isStrInt(std::string const & str);
 /// does the std::string represent an unsigned integer value ?
 bool isStrUnsignedInt(std::string const & str);
 
-///
-int strToInt(std::string const & str);
-
-/// convert string to an unsigned integer
-unsigned int strToUnsignedInt(std::string const & str);
-
 ///
 bool isStrDbl(std::string const & str);
 
-///
-double strToDbl(std::string const & str);
-
 ///
 char lowercase(char c);
 
index 54569babb6d54f506c1734388df106814d66c511..4b5569967c76713469e0f3cbd32b48a9bbb65c8f 100644 (file)
@@ -46,8 +46,6 @@ bool putenv(std::string const & varname, std::string const & value);
 int unlink(std::string const & file);
 /// remove the given directory
 int rmdir(std::string const & file);
-/// convert the given string to an integer
-int atoi(std::string const & nstr);
 /// (securely) create a temporary file in the given dir with the given prefix
 std::string const tempName(std::string const & dir = std::string(),
                      std::string const & mask = std::string());
diff --git a/src/support/tests/.cvsignore b/src/support/tests/.cvsignore
new file mode 100644 (file)
index 0000000..161abf4
--- /dev/null
@@ -0,0 +1,6 @@
+Makefile
+Makefile.in
+.deps
+.libs
+convert
+lstrings
diff --git a/src/support/tests/Makefile.am b/src/support/tests/Makefile.am
new file mode 100644 (file)
index 0000000..fb77a02
--- /dev/null
@@ -0,0 +1,26 @@
+include $(top_srcdir)/config/common.am
+
+TESTS = \
+       test_convert \
+       test_lstrings
+
+check_PROGRAMS = \
+       convert \
+       lstrings
+
+AM_CPPFLAGS = $(BOOST_INCLUDES)
+
+convert_LDADD = ../convert.o
+convert_SOURCES = \
+       convert.C \
+       boost.C
+
+lstrings_LDADD = ../lstrings.o
+lstrings_SOURCES = \
+       lstrings.C \
+       boost.C
+
+regfiles: ${check_PROGRAMS}
+       for all in ${check_PROGRAMS} ; do \
+               ./$$all > regfiles/$$all ; \
+       done
diff --git a/src/support/tests/boost.C b/src/support/tests/boost.C
new file mode 100644 (file)
index 0000000..443551a
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * \file boost.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include <boost/assert.hpp>
+
+#include <cstdlib>
+#include <exception>
+
+namespace boost {
+
+void throw_exception(std::exception const & /*e*/)
+{
+       BOOST_ASSERT(false);
+}
+
+
+void assertion_failed(char const * /*expr*/, char const * /*function*/,
+                     char const * /*file*/, long /*line*/)
+{
+       ::abort();
+}
+
+
+}
diff --git a/src/support/tests/convert.C b/src/support/tests/convert.C
new file mode 100644 (file)
index 0000000..c2b2169
--- /dev/null
@@ -0,0 +1,86 @@
+#include <config.h>
+
+#include "../convert.h"
+
+#include <iostream>
+
+using namespace std;
+
+void convert_int()
+{
+       cout << convert<int>("123") << '\n'
+            << convert<int>(" 123") << '\n'
+            << convert<int>("123 ") << '\n'
+            << convert<int>(" 123 ") << '\n'
+
+            << convert<int>("123 123") << '\n'
+            << convert<int>(" 123 123") << '\n'
+            << convert<int>("123 123 ") << '\n'
+            << convert<int>(" 123 123 ") << '\n'
+
+            << convert<int>("-123") << '\n'
+            << convert<int>(" -123") << '\n'
+            << convert<int>("-123 ") << '\n'
+            << convert<int>(" -123 ") << '\n'
+
+            << convert<int>("-123 123") << '\n'
+            << convert<int>(" -123 123") << '\n'
+            << convert<int>("-123 123 ") << '\n'
+            << convert<int>(" -123 123 ") << '\n'
+
+            << convert<int>("") << '\n'
+            << convert<int>("abc") << '\n'
+            << convert<int>(" abc") << '\n'
+            << convert<int>("abc ") << '\n'
+            << convert<int>(" abc ") << '\n'
+
+            << convert<int>(" 123 abc") << '\n'
+            << convert<int>("123 abc ") << '\n'
+            << convert<int>(" 123 abc ") << '\n'
+            << convert<int>("123  abc") << endl;
+}
+
+
+void convert_unsigned()
+{
+       cout << convert<unsigned int>(string("123")) << '\n'
+            << convert<unsigned int>(string(" 123")) << '\n'
+            << convert<unsigned int>(string("123 ")) << '\n'
+            << convert<unsigned int>(string(" 123 ")) << '\n'
+
+            << convert<unsigned int>(string("123 123")) << '\n'
+            << convert<unsigned int>(string(" 123 123")) << '\n'
+            << convert<unsigned int>(string("123 123 ")) << '\n'
+            << convert<unsigned int>(string(" 123 123 ")) << '\n'
+
+            << convert<unsigned int>(string()) << '\n'
+            << convert<unsigned int>(string("abc")) << '\n'
+            << convert<unsigned int>(string(" abc")) << '\n'
+            << convert<unsigned int>(string("abc ")) << '\n'
+            << convert<unsigned int>(string(" abc ")) << '\n'
+
+            << convert<unsigned int>(string(" 123 abc")) << '\n'
+            << convert<unsigned int>(string("123 abc ")) << '\n'
+            << convert<unsigned int>(string(" 123 abc ")) << '\n'
+            << convert<unsigned int>(string("123  abc")) << endl;
+}
+
+
+void convert_string()
+{
+       cout << convert<string>(123) << '\n'
+            << convert<string>(4294967173u) << '\n'
+            << convert<string>(true) << '\n'
+            << convert<string>(false) << '\n'
+
+            << convert<string>('a') << '\n'
+            << convert<string>(1.0) << '\n'
+            << convert<string>(1.1) << endl;
+}
+
+int main()
+{
+       convert_int();
+       convert_unsigned();
+       convert_string();
+}
diff --git a/src/support/tests/lstrings.C b/src/support/tests/lstrings.C
new file mode 100644 (file)
index 0000000..99db7de
--- /dev/null
@@ -0,0 +1,25 @@
+#include "../lstrings.h"
+
+#include <iostream>
+
+using namespace lyx::support;
+
+using namespace std;
+
+void test_lowercase()
+{
+       cout << lowercase('A') << endl;
+       cout << lowercase("AlLe") << endl;
+}
+
+void test_uppercase()
+{
+       cout << uppercase('a') << endl;
+       cout << uppercase("AlLe") << endl;
+}
+
+int main() 
+{
+       test_lowercase();
+       test_uppercase();
+}
diff --git a/src/support/tests/regfiles/convert b/src/support/tests/regfiles/convert
new file mode 100644 (file)
index 0000000..81a562e
--- /dev/null
@@ -0,0 +1,49 @@
+123
+123
+123
+123
+123
+123
+123
+123
+-123
+-123
+-123
+-123
+-123
+-123
+-123
+-123
+0
+0
+0
+0
+0
+123
+123
+123
+123
+123
+123
+123
+123
+123
+123
+123
+123
+0
+0
+0
+0
+0
+123
+123
+123
+123
+123
+4294967173
+true
+false
+a
+1
+1.1
diff --git a/src/support/tests/regfiles/lstrings b/src/support/tests/regfiles/lstrings
new file mode 100644 (file)
index 0000000..aeef9c6
--- /dev/null
@@ -0,0 +1,4 @@
+a
+alle
+A
+ALLE
diff --git a/src/support/tests/test_convert b/src/support/tests/test_convert
new file mode 100755 (executable)
index 0000000..bce7764
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+regfile=`cat regfiles/convert`
+output=`./convert`
+
+test "$regfile" = "$output"
+exit $?
diff --git a/src/support/tests/test_lstrings b/src/support/tests/test_lstrings
new file mode 100755 (executable)
index 0000000..624fdb0
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+regfile=`cat regfiles/lstrings`
+output=`./lstrings`
+
+test "$regfile" = "$output"
+exit $?
index d43d6b58925a0aa26add94e890ed183b5e5d4e4f..f07b3e48c28aa6831c3f0feb19cef526996bd1dc 100644 (file)
@@ -37,7 +37,6 @@
 using lyx::support::ltrim;
 using lyx::support::prefixIs;
 using lyx::support::rtrim;
-using lyx::support::strToInt;
 using lyx::support::suffixIs;
 
 using boost::shared_ptr;
@@ -249,7 +248,7 @@ bool getTokenValue(string const & str, char const * token, int & num)
        num = 0;
        if (!getTokenValue(str, token, tmp))
                return false;
-       num = strToInt(tmp);
+       num = convert<int>(tmp);
        return true;
 }
 
index 2db09aee4bb36216210ba4229e87cdac29cfe089..a38374eb21b3b4c57064e89e4613e6656e192d85 100644 (file)
@@ -1,3 +1,9 @@
+2005-01-27  Lars Gullik Bjonnes  <larsbj@gullik.net>
+
+       * Spacing (set): take double instead of float
+
+       * tex2lyx.C: convert stuff
+
 2005-01-11  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * Spacing.h: remove unused parameters
index a83ca24756c263023b15829c61043917f163c3c8..9d50b274881b8ac2e5f32ed3437655b789183bb5 100644 (file)
@@ -29,7 +29,7 @@ public:
                Default
        };
        ///
-       void set(Spacing::Space, float = 1.0) {}
+       void set(Spacing::Space, double = 1.0) {}
        ///
        void set(Spacing::Space, std::string const &) {}
 };
index ae440bab13aeb7b398619382e5a9ba513db89c02..0b43803621b7e6c23d479263b0e748e5a06eba1c 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "debug.h"
 #include "lyxtextclass.h"
+
+#include "support/convert.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
@@ -50,7 +52,6 @@ using std::map;
 using lyx::support::isStrUnsignedInt;
 using lyx::support::ltrim;
 using lyx::support::rtrim;
-using lyx::support::strToUnsignedInt;
 using lyx::support::IsFileReadable;
 using lyx::support::IsFileWriteable;
 
@@ -137,7 +138,7 @@ void add_known_command(string const & command, string const & o1,
        string const opt1 = rtrim(ltrim(o1, "["), "]");
        if (isStrUnsignedInt(opt1)) {
                // The command has arguments
-               nargs = strToUnsignedInt(opt1);
+               nargs = convert<unsigned int>(opt1);
                if (nargs > 0 && o2) {
                        // The first argument is optional
                        arguments.push_back(optional);
index e46b83972155339d13ccfa9cb4015d2e309f6f76..daf8a9ab7216eb6825835c9f4273700d5af815b1 100644 (file)
@@ -70,8 +70,6 @@ using lyx::cap::pasteSelection;
 using lyx::cap::replaceSelection;
 
 using lyx::support::isStrUnsignedInt;
-using lyx::support::strToUnsignedInt;
-using lyx::support::atoi;
 using lyx::support::token;
 
 using std::endl;
@@ -886,7 +884,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
 #warning FIXME Check if the arg is in the domain of available selections.
 #endif
                if (isStrUnsignedInt(cmd.argument))
-                       pasteSelection(cur, strToUnsignedInt(cmd.argument));
+                       pasteSelection(cur, convert<unsigned int>(cmd.argument));
                else
                        pasteSelection(cur, 0);
                cur.clearSelection(); // bug 393
@@ -1331,7 +1329,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                else {
                        string s = cmd.argument;
                        string const s1 = token(s, ' ', 1);
-                       int const nargs = s1.empty() ? 0 : atoi(s1);
+                       int const nargs = s1.empty() ? 0 : convert<int>(s1);
                        string const s2 = token(s, ' ', 2);
                        string const type = s2.empty() ? "newcommand" : s2;
                        cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));
index 9313ab09a31b606bd5bb0bd280f6f74767b485a0..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;
 
@@ -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';
                }
@@ -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));
        }
 }