diff options
author | Andrzej Hunt <andrzej@ahunt.org> | 2015-05-12 20:16:27 +0100 |
---|---|---|
committer | Andrzej Hunt <andrzej@ahunt.org> | 2015-10-20 18:18:34 +0200 |
commit | 9f7e3784b5d2d4e9a6c8cdda5aca7bf1e92b72af (patch) | |
tree | be5edba6ec7d36b0927a2da49feab78fbc104153 | |
parent | 611220c4a41967170e0cc760fbe16eb67425180a (diff) |
Store original input string for UtUnit
String->UtUnit isn't necessarily reversible, hence we should
store the original input too in case it is needed by the user.
Change-Id: I8794a1544a9c996da574ee753d95b44f067e819f
-rw-r--r-- | sc/source/core/units/utunit.cxx | 3 | ||||
-rw-r--r-- | sc/source/core/units/utunit.hxx | 31 |
2 files changed, 29 insertions, 5 deletions
diff --git a/sc/source/core/units/utunit.cxx b/sc/source/core/units/utunit.cxx index f539502eeaaf..63e7e73c268f 100644 --- a/sc/source/core/units/utunit.cxx +++ b/sc/source/core/units/utunit.cxx @@ -18,7 +18,8 @@ bool UtUnit::createUnit(const OUString& rUnitString, UtUnit& rUnitOut, const boo // simplest just to do this during conversion: OString sUnitStringUTF8 = OUStringToOString(rUnitString.trim(), RTL_TEXTENCODING_UTF8); - UtUnit pParsedUnit(ut_parse(pUTSystem.get(), sUnitStringUTF8.getStr(), UT_UTF8)); + UtUnit pParsedUnit(ut_parse(pUTSystem.get(), sUnitStringUTF8.getStr(), UT_UTF8), + rUnitString); if (pParsedUnit.isValid()) { rUnitOut = pParsedUnit; diff --git a/sc/source/core/units/utunit.hxx b/sc/source/core/units/utunit.hxx index b039c74d78fb..6f82b0542d2c 100644 --- a/sc/source/core/units/utunit.hxx +++ b/sc/source/core/units/utunit.hxx @@ -12,6 +12,7 @@ #include <rtl/ustring.hxx> +#include <boost/optional.hpp> #include <boost/shared_ptr.hpp> #include <udunits2.h> @@ -38,12 +39,26 @@ class UtUnit { private: ::boost::shared_ptr< ut_unit > mpUnit; + /** + * The original input string used in createUnit. + * We can't necessarily convert a ut_unit back into the + * original representation (e.g. cm gets formatted as 0.01m + * by default), hence we should store the original string + * as may need to display it to the user again. + * + * There is no input string for units that are created when manipulating + * other units (i.e. multiplication/division of other UtUnits). + */ + boost::optional< OUString > msInputString; + static void freeUt(ut_unit* pUnit) { ut_free(pUnit); } - UtUnit(ut_unit* pUnit): - mpUnit(pUnit, &freeUt) + UtUnit(ut_unit* pUnit, + const boost::optional< OUString > rInputString = boost::optional< OUString >()) + : mpUnit(pUnit, &freeUt) + , msInputString(rInputString) {} void reset(ut_unit* pUnit) { @@ -55,6 +70,9 @@ private: } public: + /** + * return false if we try to create in invalid unit. + */ static bool createUnit(const OUString& rUnitString, UtUnit& rUnitOut, const boost::shared_ptr< ut_system >& pUTSystem); /* @@ -63,10 +81,15 @@ public: */ UtUnit() {}; - UtUnit(const UtUnit& rUnit): - mpUnit(rUnit.mpUnit) + UtUnit(const UtUnit& rUnit) + : mpUnit(rUnit.mpUnit) + , msInputString(rUnit.msInputString) {} + boost::optional< OUString > getInputString() const { + return msInputString; + } + OUString getString() const; bool isValid() const { |