From 342cdf432246110db37bee4e0aebb4b72c933ddb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 27 Jan 2005 21:05:44 +0000 Subject: [PATCH] the convert patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9538 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 4 ++ configure.ac | 1 + po/POTFILES.in | 1 + src/BufferView_pimpl.C | 9 ++- src/ChangeLog | 24 ++++--- src/Chktex.C | 5 +- src/Spacing.C | 8 +-- src/Spacing.h | 4 +- src/buffer.C | 7 +-- src/chset.C | 5 +- src/client/ChangeLog | 4 ++ src/client/debug.C | 4 +- src/debug.C | 8 +-- src/frontends/gtk/ChangeLog | 4 ++ src/frontends/gtk/GGraphics.C | 9 ++- src/frontends/gtk/GPrint.C | 8 +-- src/frontends/gtk/xftFontLoader.C | 5 +- src/frontends/qt2/ChangeLog | 6 +- src/frontends/qt2/QExternal.C | 14 ++--- src/frontends/qt2/QExternalDialog.C | 6 +- src/frontends/qt2/QGraphics.C | 14 ++--- src/frontends/qt2/QPrefs.C | 3 +- src/frontends/qt2/QWrap.C | 3 +- src/frontends/qt2/qfont_loader.C | 4 +- src/frontends/xforms/ChangeLog | 4 ++ src/frontends/xforms/FontInfo.C | 5 +- src/frontends/xforms/FormExternal.C | 21 +++---- src/frontends/xforms/FormGraphics.C | 26 ++++---- src/frontends/xforms/FormPreferences.C | 59 +++++++++--------- src/frontends/xforms/FormPrint.C | 12 ++-- src/frontends/xforms/xfont_loader.C | 5 +- src/graphics/ChangeLog | 7 +++ src/graphics/GraphicsParams.h | 2 +- src/graphics/PreviewLoader.C | 2 +- src/insets/ChangeLog | 4 ++ src/insets/ExternalTransforms.C | 11 ++-- src/insets/insetbibitem.C | 3 +- src/insets/insetcollapsable.C | 5 +- src/insets/insetcollapsable.h | 2 +- src/insets/insetexternal.C | 4 +- src/insets/insetgraphics.C | 8 +-- src/insets/insetgraphicsParams.C | 16 ++--- src/insets/insettabular.C | 12 ++-- src/insets/insettext.C | 1 - src/insets/updatableinset.C | 14 ++--- src/insets/updatableinset.h | 2 +- src/lyxfunc.C | 2 - src/lyxlayout.h | 12 ++-- src/lyxlex.C | 13 ++-- src/lyxlex.h | 4 +- src/mathed/ChangeLog | 5 ++ src/mathed/math_parser.C | 9 ++- src/mathed/math_sizeinset.C | 6 +- src/support/ChangeLog | 23 ++++++- src/support/Makefile.am | 3 +- src/support/atoi.C | 25 -------- src/support/convert.C | 35 +++++++++++ src/support/convert.h | 14 ----- src/support/lstrings.C | 40 ------------ src/support/lstrings.h | 9 --- src/support/lyxlib.h | 2 - src/support/tests/.cvsignore | 6 ++ src/support/tests/Makefile.am | 26 ++++++++ src/support/tests/boost.C | 33 ++++++++++ src/support/tests/convert.C | 86 ++++++++++++++++++++++++++ src/support/tests/lstrings.C | 25 ++++++++ src/support/tests/regfiles/convert | 49 +++++++++++++++ src/support/tests/regfiles/lstrings | 4 ++ src/support/tests/test_convert | 7 +++ src/support/tests/test_lstrings | 7 +++ src/tabular.C | 3 +- src/tex2lyx/ChangeLog | 6 ++ src/tex2lyx/Spacing.h | 2 +- src/tex2lyx/tex2lyx.C | 5 +- src/text3.C | 6 +- src/vspace.C | 6 +- 76 files changed, 538 insertions(+), 320 deletions(-) delete mode 100644 src/support/atoi.C create mode 100644 src/support/tests/.cvsignore create mode 100644 src/support/tests/Makefile.am create mode 100644 src/support/tests/boost.C create mode 100644 src/support/tests/convert.C create mode 100644 src/support/tests/lstrings.C create mode 100644 src/support/tests/regfiles/convert create mode 100644 src/support/tests/regfiles/lstrings create mode 100755 src/support/tests/test_convert create mode 100755 src/support/tests/test_lstrings diff --git a/ChangeLog b/ChangeLog index f67954d214..ec310c697b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-01-27 Lars Gullik Bjonnes + + * configure.ac: add src/support/tests/Makefile + 2005-01-21 Jean-Marc Lasgouttes * configure.ac: indicate in final info whether aiksaurus is used. diff --git a/configure.ac b/configure.ac index b7a4f6fb07..0524255537 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/po/POTFILES.in b/po/POTFILES.in index c6b71a9647..c22855c2e5 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index f4a23d4a15..7491e27213 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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(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(cmd.argument)); break; case LFUN_BOOKMARK_GOTO: - restorePosition(strToUnsignedInt(cmd.argument)); + restorePosition(convert(cmd.argument)); break; case LFUN_REF_GOTO: { diff --git a/src/ChangeLog b/src/ChangeLog index 6a90aa3816..dff1a7ae70 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,20 +1,28 @@ +2005-01-27 Lars Gullik Bjonnes + + * 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 * 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 @@ -28,7 +36,7 @@ 2005-01-20 Angus Leeming - * 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 * SpellBase.h: rename some of the elements of the Result enum. diff --git a/src/Chktex.C b/src/Chktex.C index 4ad44c2fca..bb9258c207 100644 --- a/src/Chktex.C +++ b/src/Chktex.C @@ -15,16 +15,15 @@ #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 #include -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(line); #if USE_BOOST_FORMAT msg % warno; diff --git a/src/Spacing.C b/src/Spacing.C index 8846a742ea..d8ca162657 100644 --- a/src/Spacing.C +++ b/src/Spacing.C @@ -18,9 +18,7 @@ #include #include -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(getValueAsString()); } -void Spacing::set(Spacing::Space sp, float val) +void Spacing::set(Spacing::Space sp, double val) { set(sp, convert(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(val) * 1000 + 0.5)) { case 1000: space = Single; break; diff --git a/src/Spacing.h b/src/Spacing.h index 5c9d2c6534..617ec9269e 100644 --- a/src/Spacing.h +++ b/src/Spacing.h @@ -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); /// diff --git a/src/buffer.C b/src/buffer.C index de2a6ac83b..1d6c5fa04f 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -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(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"); diff --git a/src/chset.C b/src/chset.C index e97330e2ff..6a5631566d 100644 --- a/src/chset.C +++ b/src/chset.C @@ -15,14 +15,13 @@ #include "debug.h" +#include "support/convert.h" #include "support/filetools.h" -#include "support/lyxlib.h" #include #include -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(sub.str(1)); string const str = sub.str(2); if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "Chardef: " << n diff --git a/src/client/ChangeLog b/src/client/ChangeLog index 4e105820c4..79dd123ee2 100644 --- a/src/client/ChangeLog +++ b/src/client/ChangeLog @@ -1,3 +1,7 @@ +2005-01-27 Lars Gullik Bjonnes + + * debug.C: use convert<> instead of atoi,strToXXX and friends + 2005-01-20 Asger Ottar Alstrup * pch.h: use the HAVE_UNISTD_H preprocessor guard. diff --git a/src/client/debug.C b/src/client/debug.C index 5da41b9f67..bcc16194d4 100644 --- a/src/client/debug.C +++ b/src/client/debug.C @@ -14,6 +14,7 @@ #include "debug.h" #include "gettext.h" +#include "support/convert.h" #include "support/lstrings.h" #include @@ -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(strToInt(tmp)); + l |= static_cast(convert(tmp)); else // Search for an explicit name for (int i = 0 ; i < numErrorTags ; ++i) diff --git a/src/debug.C b/src/debug.C index 2ddb9462fb..75852f61d9 100644 --- a/src/debug.C +++ b/src/debug.C @@ -14,6 +14,7 @@ #include "debug.h" #include "gettext.h" +#include "support/convert.h" #include "support/lstrings.h" #include @@ -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(strToInt(tmp)); + l |= static_cast(convert(tmp)); else // Search for an explicit name for (int i = 0 ; i < numErrorTags ; ++i) diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 047230d818..ca86aff1af 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,7 @@ +2005-01-27 Lars Gullik Bjonnes + + * Several files: use convert<> instead of atoi,strToXXX and friends + 2005-01-10 Angus Leeming * ghelpers.C: diff --git a/src/frontends/gtk/GGraphics.C b/src/frontends/gtk/GGraphics.C index a3c3931f53..f7b7daacb3 100644 --- a/src/frontends/gtk/GGraphics.C +++ b/src/frontends/gtk/GGraphics.C @@ -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(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(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(igp.rotateAngle)); int origin_pos; if (igp.rotateOrigin.empty()) { diff --git a/src/frontends/gtk/GPrint.C b/src/frontends/gtk/GPrint.C index 54ec6849a0..cd9de15b83 100644 --- a/src/frontends/gtk/GPrint.C +++ b/src/frontends/gtk/GPrint.C @@ -21,8 +21,8 @@ #include "PrinterParams.h" -#include "support/lstrings.h" #include "support/convert.h" +#include "support/lstrings.h" #include @@ -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(fromEntry_->get_text()); if (!toEntry_->get_text().empty()) - pp.to_page = strToInt(toEntry_->get_text()); + pp.to_page = convert(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(from) > convert(to))) activate = ButtonPolicy::SMI_INVALID; } bool const enableCounter = printer_->get_active(); diff --git a/src/frontends/gtk/xftFontLoader.C b/src/frontends/gtk/xftFontLoader.C index 098d3a2e34..3024b63dff 100644 --- a/src/frontends/gtk/xftFontLoader.C +++ b/src/frontends/gtk/xftFontLoader.C @@ -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 // fabs() #include -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(lyxrc.font_sizes[size]) * lyxrc.zoom / 100.0; XftPattern *fpat = XftPatternCreate(); ffamily = familyString(family); diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index a6727c5513..c6a7e1c9de 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,7 +1,11 @@ +2005-01-27 Lars Gullik Bjonnes + + * Several files: use convert<> instead of atoi,strToXXX and friends + 2005-01-20 Jean-Marc Lasgouttes * floatplacement.C (heredefinitelyClicked): remove bogus - semicolon. + semicolon. 2005-01-15 Angus Leeming diff --git a/src/frontends/qt2/QExternal.C b/src/frontends/qt2/QExternal.C index 9c2a3b1aaa..f9b6fca911 100644 --- a/src/frontends/qt2/QExternal.C +++ b/src/frontends/qt2/QExternal.C @@ -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(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(width), static_cast(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(fromqstr(xlED.text())); + data.bbox.yb = convert(fromqstr(ybED.text())); + data.bbox.xr = convert(fromqstr(xrED.text())); + data.bbox.yt = convert(fromqstr(ytED.text())); } diff --git a/src/frontends/qt2/QExternalDialog.C b/src/frontends/qt2/QExternalDialog.C index 65341e94f5..39f3fa8367 100644 --- a/src/frontends/qt2/QExternalDialog.C +++ b/src/frontends/qt2/QExternalDialog.C @@ -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(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(hstr), 0.0, 0.05)) return false; if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero())) return false; diff --git a/src/frontends/qt2/QGraphics.C b/src/frontends/qt2/QGraphics.C index f54d459695..6589682058 100644 --- a/src/frontends/qt2/QGraphics.C +++ b/src/frontends/qt2/QGraphics.C @@ -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 @@ -41,8 +41,6 @@ #include 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(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(lbX) + convert(lbY) + + convert(rtX) + convert(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(fromqstr(dialog_->displayscale->text())); igp.rotateAngle = fromqstr(dialog_->angle->text()); - float rotAngle = strToDbl(igp.rotateAngle); + double rotAngle = convert(igp.rotateAngle); if (std::abs(rotAngle) > 360.0) { rotAngle -= 360.0 * floor(rotAngle / 360.0); igp.rotateAngle = convert(rotAngle); diff --git a/src/frontends/qt2/QPrefs.C b/src/frontends/qt2/QPrefs.C index 3e2a9bedd9..f180a995f8 100644 --- a/src/frontends/qt2/QPrefs.C +++ b/src/frontends/qt2/QPrefs.C @@ -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 using lyx::support::compare_no_case; -using lyx::support::strToDbl; using std::distance; using std::endl; diff --git a/src/frontends/qt2/QWrap.C b/src/frontends/qt2/QWrap.C index e67ab77f35..72fd1181b1 100644 --- a/src/frontends/qt2/QWrap.C +++ b/src/frontends/qt2/QWrap.C @@ -27,7 +27,6 @@ #include #include -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(fromqstr(dialog_->widthED->text())); LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem(); if (dialog_->widthED->text().isEmpty()) unit = LyXLength::UNIT_NONE; diff --git a/src/frontends/qt2/qfont_loader.C b/src/frontends/qt2/qfont_loader.C index 62b3c05a8a..8353046132 100644 --- a/src/frontends/qt2/qfont_loader.C +++ b/src/frontends/qt2/qfont_loader.C @@ -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(lyxrc.font_sizes[f.size()]) * lyxrc.zoom / 100.0); switch (f.series()) { diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 6300ff4ca1..ea035a25a7 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2005-01-27 Lars Gullik Bjonnes + + * Several files: use convert<> instead of atoi,strToXXX and friends + 2005-01-20 Angus Leeming * FormPreferences.C: change the tooltip messages to reflect the diff --git a/src/frontends/xforms/FontInfo.C b/src/frontends/xforms/FontInfo.C index bb30ae3542..675ce939b3 100644 --- a/src/frontends/xforms/FontInfo.C +++ b/src/frontends/xforms/FontInfo.C @@ -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(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(token(name, '-', 12)) == 0) // Ignore bogus matches of scalable fonts. sizes[i] = 0; }; diff --git a/src/frontends/xforms/FormExternal.C b/src/frontends/xforms/FormExternal.C index c4cd302c7c..7bffb9c475 100644 --- a/src/frontends/xforms/FormExternal.C +++ b/src/frontends/xforms/FormExternal.C @@ -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(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(width), static_cast(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(getString(xlED)); + data.bbox.yb = convert(getString(ybED)); + data.bbox.xr = convert(getString(xrED)); + data.bbox.yt = convert(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(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(hstr), 0.0, 0.05)) return false; if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero())) return false; diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index b25b931f1d..d794ac0f42 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -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(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(igp.scale), 0.0, 0.05) + || float_equal(convert(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(igp.rotateAngle); if (std::abs(rotAngle) > 360.0) { rotAngle -= 360.0 * floor(rotAngle / 360.0); igp.rotateAngle = convert(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(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(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); diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 042af27d8d..26b5c1ac3b 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -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(fl_get_input(dialog_->input_tiny)) + || 0.0 >= convert(fl_get_input(dialog_->input_script)) + || 0.0 >= convert(fl_get_input(dialog_->input_footnote)) + || 0.0 >= convert(fl_get_input(dialog_->input_small)) + || 0.0 >= convert(fl_get_input(dialog_->input_normal)) + || 0.0 >= convert(fl_get_input(dialog_->input_large)) + || 0.0 >= convert(fl_get_input(dialog_->input_larger)) + || 0.0 >= convert(fl_get_input(dialog_->input_largest)) + || 0.0 >= convert(fl_get_input(dialog_->input_huge)) + || 0.0 >= convert(fl_get_input(dialog_->input_huger))) { activate = false; str = _("Fonts must be positive!"); - - } else if (strToDbl(getString(dialog_->input_tiny)) > + } else if (convert(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(fl_get_input(dialog_->input_script)) || + convert(fl_get_input(dialog_->input_script)) > + convert(fl_get_input(dialog_->input_footnote)) || + convert(fl_get_input(dialog_->input_footnote)) > + convert(fl_get_input(dialog_->input_small)) || + convert(fl_get_input(dialog_->input_small)) > + convert(fl_get_input(dialog_->input_normal)) || + convert(fl_get_input(dialog_->input_normal)) > + convert(fl_get_input(dialog_->input_large)) || + convert(fl_get_input(dialog_->input_large)) > + convert(fl_get_input(dialog_->input_larger)) || + convert(fl_get_input(dialog_->input_larger)) > + convert(fl_get_input(dialog_->input_largest)) || + convert(fl_get_input(dialog_->input_largest)) > + convert(fl_get_input(dialog_->input_huge)) || + convert(fl_get_input(dialog_->input_huge)) > + convert(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."); diff --git a/src/frontends/xforms/FormPrint.C b/src/frontends/xforms/FormPrint.C index 1d89287858..f966da573d 100644 --- a/src/frontends/xforms/FormPrint.C +++ b/src/frontends/xforms/FormPrint.C @@ -31,8 +31,6 @@ using std::string; namespace lyx { -using support::strToInt; - namespace frontend { typedef FormController > 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(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(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(*to); setEnabled(dialog_->input_to_page, from_input); - if (!from_input || (to_input && strToInt(from) > strToInt(to))) { + if (!from_input || (to_input && convert(from) > convert(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(from) == convert(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(fl_get_button(dialog_->check_odd_pages)); bool const even_pages = static_cast(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(strToInt(from) % 2); + bool const from_is_odd = static_cast(convert(from) % 2); if ( (from_is_odd && even_only) || (!from_is_odd && odd_only) ) { activate = ButtonPolicy::SMI_INVALID; } diff --git a/src/frontends/xforms/xfont_loader.C b/src/frontends/xforms/xfont_loader.C index f9a1a74837..ffe46322f6 100644 --- a/src/frontends/xforms/xfont_loader.C +++ b/src/frontends/xforms/xfont_loader.C @@ -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(lyxrc.font_sizes[size]) * lyxrc.dpi * (lyxrc.zoom/100.0)) / 72.27 + 0.5); string font = fontinfo[family][series][shape]->getFontname(fsize); diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 8166642e02..b202c4ac1a 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,10 @@ +2005-01-27 Lars Gullik Bjonnes + + * 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 * PreviewLoader.C (unique_filename): tostr -> convert diff --git a/src/graphics/GraphicsParams.h b/src/graphics/GraphicsParams.h index 1f633e7685..222b50f85c 100644 --- a/src/graphics/GraphicsParams.h +++ b/src/graphics/GraphicsParams.h @@ -69,7 +69,7 @@ public: * image. */ /// Rotation angle. - float angle; + double angle; }; bool operator==(Params const &, Params const &); diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 8dbc512ce3..ddedc11b2c 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -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(lyxrc.preview_scale_factor); lyxerr[Debug::GRAPHICS] << "The font scaling factor is " << font_scaling_factor_ << endl; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 135b8a8e98..74c311c28b 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2005-01-27 Lars Gullik Bjonnes + + * Several files: use convert<> instead of atoi,strToXXX and friends + 2005-01-23 Angus Leeming * insetbibitem.h (bibitemWidest): declare the function. diff --git a/src/insets/ExternalTransforms.C b/src/insets/ExternalTransforms.C index ffc66cfb12..43b69eece1 100644 --- a/src/insets/ExternalTransforms.C +++ b/src/insets/ExternalTransforms.C @@ -25,7 +25,6 @@ #include 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(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(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(angle); if (std::abs(rotAngle) > 360.0) { rotAngle -= 360.0 * floor(rotAngle / 360.0); return convert(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(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(data.scale); if (!float_equal(scl, 100.0, 0.05)) os << "scale=" << scl / 100.0 << ','; return os.str(); diff --git a/src/insets/insetbibitem.C b/src/insets/insetbibitem.C index 97dca12473..19144e2310 100644 --- a/src/insets/insetbibitem.C +++ b/src/insets/insetbibitem.C @@ -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(getContents().substr(key_prefix.length())); key_counter = max(key_counter, key); } } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 3a9a670464..17bf4215ca 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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); } - diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 6fbc5658dc..763b5b49f0 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -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; /// diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 3bbf20e91b..522ccc6081 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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(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(eparams.rotationdata.adjAngle()); switch (eparams.display) { case external::DefaultDisplay: diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 0ef5fcc870..e6e69ca92d 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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(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(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(params().scale); if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) { if (!float_equal(scl, 100.0, 0.05)) options << " scale=\"" diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index 8e0496ef34..fd9678471c 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -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(scale), 0.0, 0.05)) { + if (!float_equal(convert(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(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(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(token(tmp, ' ', 0)); + unsigned int const bb_orig_yb = convert(token(tmp, ' ', 1)); // new pars.bb values must be >= zero if (pars.bb.xl > bb_orig_xl) diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index a247e0a472..6a10ab8f77 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -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(strToDbl(cmd.argument))); + scroll(cur.bv(), static_cast(convert(cmd.argument))); else - scroll(cur.bv(), strToInt(cmd.argument)); + scroll(cur.bv(), convert(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(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(value)); if (val == tabular.getUsebox(cur.idx())) val = LyXTabular::BOX_NONE; for (row_type i = sel_row_start; i <= sel_row_end; ++i) diff --git a/src/insets/insettext.C b/src/insets/insettext.C index a402cbb526..144aa4fb45 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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; diff --git a/src/insets/updatableinset.C b/src/insets/updatableinset.C index eb68e226db..1018a97bde 100644 --- a/src/insets/updatableinset.C +++ b/src/insets/updatableinset.C @@ -23,14 +23,10 @@ #include "funcrequest.h" #include "lyxtext.h" -#include "support/lstrings.h" +#include "support/convert.h" #include -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(strToDbl(cmd.argument))); + scroll(cur.bv(), static_cast(convert(cmd.argument))); else - scroll(cur.bv(), strToInt(cmd.argument)); + scroll(cur.bv(), convert(cmd.argument)); cur.bv().update(); } break; diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index 1bc7253025..e2a5972ffe 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -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; }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 3420f6443d..79b08db290 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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; diff --git a/src/lyxlayout.h b/src/lyxlayout.h index 25452e7a0f..25d07d90a8 100644 --- a/src/lyxlayout.h +++ b/src/lyxlayout.h @@ -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; /// diff --git a/src/lyxlex.C b/src/lyxlex.C index 664d95cfe9..6758dc167d 100644 --- a/src/lyxlex.C +++ b/src/lyxlex.C @@ -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(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(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(); diff --git a/src/lyxlex.h b/src/lyxlex.h index cc13fbd935..dc16b52b1a 100644 --- a/src/lyxlex.h +++ b/src/lyxlex.h @@ -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 diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 82577fe534..3de9c489f6 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,8 @@ +2005-01-27 Lars Gullik Bjonnes + + * math_parser.C,math_sizeinset.C: use convert<> instead of + atoi,strToXXX and friends + 2005-01-20 Angus Leeming * math_spaceinset.C (validate): diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 9bf89d8e08..1903f0432e 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -62,11 +62,10 @@ following hack as starting point to write some macros: #include "lyxlex.h" #include "debug.h" -#include "support/lyxlib.h" -#include +#include "support/convert.h" -using lyx::support::atoi; +#include 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(arg); } diff --git a/src/mathed/math_sizeinset.C b/src/mathed/math_sizeinset.C index 7bed06ea22..099e421694 100644 --- a/src/mathed/math_sizeinset.C +++ b/src/mathed/math_sizeinset.C @@ -16,16 +16,14 @@ #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(l->extra))) {} diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 6e7e56bc99..3338ae7391 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,24 @@ +2005-01-27 Lars Gullik Bjonnes + + * 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 * 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 * lyxsum.C, socktools.C, tempname.C, userinfo.C: use the diff --git a/src/support/Makefile.am b/src/support/Makefile.am index de6adecb9c..47ad20e263 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -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 index 674c2edef3..0000000000 --- a/src/support/atoi.C +++ /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 - -#include "support/lyxlib.h" - -#include - -#ifndef CXX_GLOBAL_CSTD -using std::atoi; -#endif - -int lyx::support::atoi(std::string const & nstr) -{ - return ::atoi(nstr.c_str()); -} diff --git a/src/support/convert.C b/src/support/convert.C index 800ae8fc99..262f937add 100644 --- a/src/support/convert.C +++ b/src/support/convert.C @@ -83,3 +83,38 @@ string convert(double d) { return lexical_cast(d); } + + +template<> +int convert(string const s) +{ + return strtol(s.c_str(), 0, 10); +} + + +template<> +unsigned int convert(string const s) +{ + return strtoul(s.c_str(), 0, 10); +} + + +template<> +double convert(string const s) +{ + return strtod(s.c_str(), 0); +} + + +template<> +int convert(char const * cptr) +{ + return strtol(cptr, 0, 10); +} + + +template<> +double convert(char const * cptr) +{ + return strtod(cptr, 0); +} diff --git a/src/support/convert.h b/src/support/convert.h index da1947b843..66b136491f 100644 --- a/src/support/convert.h +++ b/src/support/convert.h @@ -16,21 +16,7 @@ #ifndef CONVERT_H #define CONVERT_H -#if 0 -#include - -// Commented out since BOOST_STATIC_ASSERT does not work with gcc 4.0 -template -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 Target convert(Source arg); -#endif #endif diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 65c238ecfc..fb7af0a732 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -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)); diff --git a/src/support/lstrings.h b/src/support/lstrings.h index ab75fd6202..995d96b080 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -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); diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index 54569babb6..4b5569967c 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -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 index 0000000000..161abf4cd4 --- /dev/null +++ b/src/support/tests/.cvsignore @@ -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 index 0000000000..fb77a02c1a --- /dev/null +++ b/src/support/tests/Makefile.am @@ -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 index 0000000000..443551a033 --- /dev/null +++ b/src/support/tests/boost.C @@ -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 + +#include + +#include +#include + +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 index 0000000000..c2b2169e54 --- /dev/null +++ b/src/support/tests/convert.C @@ -0,0 +1,86 @@ +#include + +#include "../convert.h" + +#include + +using namespace std; + +void convert_int() +{ + cout << convert("123") << '\n' + << convert(" 123") << '\n' + << convert("123 ") << '\n' + << convert(" 123 ") << '\n' + + << convert("123 123") << '\n' + << convert(" 123 123") << '\n' + << convert("123 123 ") << '\n' + << convert(" 123 123 ") << '\n' + + << convert("-123") << '\n' + << convert(" -123") << '\n' + << convert("-123 ") << '\n' + << convert(" -123 ") << '\n' + + << convert("-123 123") << '\n' + << convert(" -123 123") << '\n' + << convert("-123 123 ") << '\n' + << convert(" -123 123 ") << '\n' + + << convert("") << '\n' + << convert("abc") << '\n' + << convert(" abc") << '\n' + << convert("abc ") << '\n' + << convert(" abc ") << '\n' + + << convert(" 123 abc") << '\n' + << convert("123 abc ") << '\n' + << convert(" 123 abc ") << '\n' + << convert("123 abc") << endl; +} + + +void convert_unsigned() +{ + cout << convert(string("123")) << '\n' + << convert(string(" 123")) << '\n' + << convert(string("123 ")) << '\n' + << convert(string(" 123 ")) << '\n' + + << convert(string("123 123")) << '\n' + << convert(string(" 123 123")) << '\n' + << convert(string("123 123 ")) << '\n' + << convert(string(" 123 123 ")) << '\n' + + << convert(string()) << '\n' + << convert(string("abc")) << '\n' + << convert(string(" abc")) << '\n' + << convert(string("abc ")) << '\n' + << convert(string(" abc ")) << '\n' + + << convert(string(" 123 abc")) << '\n' + << convert(string("123 abc ")) << '\n' + << convert(string(" 123 abc ")) << '\n' + << convert(string("123 abc")) << endl; +} + + +void convert_string() +{ + cout << convert(123) << '\n' + << convert(4294967173u) << '\n' + << convert(true) << '\n' + << convert(false) << '\n' + + << convert('a') << '\n' + << convert(1.0) << '\n' + << convert(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 index 0000000000..99db7de81c --- /dev/null +++ b/src/support/tests/lstrings.C @@ -0,0 +1,25 @@ +#include "../lstrings.h" + +#include + +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 index 0000000000..81a562eda8 --- /dev/null +++ b/src/support/tests/regfiles/convert @@ -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 index 0000000000..aeef9c6315 --- /dev/null +++ b/src/support/tests/regfiles/lstrings @@ -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 index 0000000000..bce7764f5c --- /dev/null +++ b/src/support/tests/test_convert @@ -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 index 0000000000..624fdb0e11 --- /dev/null +++ b/src/support/tests/test_lstrings @@ -0,0 +1,7 @@ +#!/bin/bash + +regfile=`cat regfiles/lstrings` +output=`./lstrings` + +test "$regfile" = "$output" +exit $? diff --git a/src/tabular.C b/src/tabular.C index d43d6b5892..f07b3e48c2 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -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(tmp); return true; } diff --git a/src/tex2lyx/ChangeLog b/src/tex2lyx/ChangeLog index 2db09aee4b..a38374eb21 100644 --- a/src/tex2lyx/ChangeLog +++ b/src/tex2lyx/ChangeLog @@ -1,3 +1,9 @@ +2005-01-27 Lars Gullik Bjonnes + + * Spacing (set): take double instead of float + + * tex2lyx.C: convert stuff + 2005-01-11 Jean-Marc Lasgouttes * Spacing.h: remove unused parameters diff --git a/src/tex2lyx/Spacing.h b/src/tex2lyx/Spacing.h index a83ca24756..9d50b27488 100644 --- a/src/tex2lyx/Spacing.h +++ b/src/tex2lyx/Spacing.h @@ -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 &) {} }; diff --git a/src/tex2lyx/tex2lyx.C b/src/tex2lyx/tex2lyx.C index ae440bab13..0b43803621 100644 --- a/src/tex2lyx/tex2lyx.C +++ b/src/tex2lyx/tex2lyx.C @@ -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(opt1); if (nargs > 0 && o2) { // The first argument is optional arguments.push_back(optional); diff --git a/src/text3.C b/src/text3.C index e46b839721..daf8a9ab72 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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(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(s1); string const s2 = token(s, ' ', 2); string const type = s2.empty() ? "newcommand" : s2; cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2)); diff --git a/src/vspace.C b/src/vspace.C index 9313ab09a3..2ed5a50faa 100644 --- a/src/vspace.C +++ b/src/vspace.C @@ -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(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(input), LyXLength::CM)); } } -- 2.39.2