diff options
author | Noel <noelgrandin@gmail.com> | 2020-12-15 09:38:19 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-12-15 10:50:28 +0100 |
commit | a79e6a7cf1ce3be46e4339a54b013ddaa534dd39 (patch) | |
tree | 3de6cf2d804dfe0e929f999103fa1c2c01b9ec53 /include/sax | |
parent | 15e4427e8fb56a143caa28b8a3120f3761fc77a5 (diff) |
use views to parse rather than allocating OUString
Change-Id: If0a848c64ce8077d1681661873629c83307cf8b2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107736
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/sax')
-rw-r--r-- | include/sax/fastattribs.hxx | 11 | ||||
-rw-r--r-- | include/sax/tools/converter.hxx | 43 |
2 files changed, 53 insertions, 1 deletions
diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx index e00452b0aa14..452280782067 100644 --- a/include/sax/fastattribs.hxx +++ b/include/sax/fastattribs.hxx @@ -27,6 +27,7 @@ #include <cppuhelper/implbase.hxx> #include <sax/saxdllapi.h> +#include <string_view> #include <vector> namespace com::sun::star::xml::sax { class XFastTokenHandler; } @@ -171,6 +172,11 @@ public: assert(mnIdx < mrList.maAttributeTokens.size()); return rtl_str_toDouble(mrList.getFastAttributeValue(mnIdx)); } + bool toBoolean() const + { + assert(mnIdx < mrList.maAttributeTokens.size()); + return rtl_str_toBoolean(mrList.getFastAttributeValue(mnIdx)); + } OUString toString() const { assert(mnIdx < mrList.maAttributeTokens.size()); @@ -188,6 +194,11 @@ public: assert(mnIdx < mrList.maAttributeTokens.size()); return mrList.AttributeValueLength(mnIdx); } + std::string_view toView() const + { + assert(mnIdx < mrList.maAttributeTokens.size()); + return std::string_view(mrList.getFastAttributeValue(mnIdx), mrList.AttributeValueLength(mnIdx)); + } bool isString(const char *str) const { assert(mnIdx < mrList.maAttributeTokens.size()); diff --git a/include/sax/tools/converter.hxx b/include/sax/tools/converter.hxx index 6d2347ef289d..07c2fb3207b1 100644 --- a/include/sax/tools/converter.hxx +++ b/include/sax/tools/converter.hxx @@ -64,6 +64,13 @@ public: sal_Int32 nMin = SAL_MIN_INT32, sal_Int32 nMax = SAL_MAX_INT32 ); + /** convert string to measure using optional min and max values*/ + static bool convertMeasure( sal_Int32& rValue, + std::string_view rString, + sal_Int16 nTargetUnit = css::util::MeasureUnit::MM_100TH, + sal_Int32 nMin = SAL_MIN_INT32, + sal_Int32 nMax = SAL_MAX_INT32 ); + /** convert measure to string */ static void convertMeasure( OUStringBuffer& rBuffer, sal_Int32 nMeasure, @@ -74,6 +81,10 @@ public: static bool convertBool( bool& rBool, std::u16string_view rString ); + /** convert string to boolean */ + static bool convertBool( bool& rBool, + std::string_view rString ); + /** convert boolean to string */ static void convertBool( OUStringBuffer& rBuffer, bool bValue ); @@ -82,14 +93,22 @@ public: static bool convertPercent( sal_Int32& rValue, std::u16string_view rString ); + /** convert string to percent */ + static bool convertPercent( sal_Int32& rValue, + std::string_view rString ); + /** convert percent to string */ static void convertPercent( OUStringBuffer& rBuffer, sal_Int32 nValue ); - /** convert string to pixel measure unite */ + /** convert string to pixel measure unit */ static bool convertMeasurePx( sal_Int32& rValue, std::u16string_view rString ); + /** convert string to pixel measure unit */ + static bool convertMeasurePx( sal_Int32& rValue, + std::string_view rString ); + /** convert pixel measure unit to string */ static void convertMeasurePx( OUStringBuffer& rBuffer, sal_Int32 nValue ); @@ -97,6 +116,8 @@ public: /** convert string to rgb color */ static bool convertColor( sal_Int32& rColor, std::u16string_view rValue ); + static bool convertColor( sal_Int32& rColor, + std::string_view rValue ); static bool convertColor( ::Color& rColor, std::u16string_view rValue ) { @@ -120,11 +141,23 @@ public: sal_Int32 nMax = SAL_MAX_INT32 ); /** convert string to number with optional min and max values */ + static bool convertNumber( sal_Int32& rValue, + std::string_view aString, + sal_Int32 nMin = SAL_MIN_INT32, + sal_Int32 nMax = SAL_MAX_INT32 ); + + /** convert string to number with optional min and max values */ static bool convertNumber64(sal_Int64& rValue, std::u16string_view aString, sal_Int64 nMin = SAL_MIN_INT64, sal_Int64 nMax = SAL_MAX_INT64); + /** convert string to number with optional min and max values */ + static bool convertNumber64(sal_Int64& rValue, + std::string_view aString, + sal_Int64 nMin = SAL_MIN_INT64, + sal_Int64 nMax = SAL_MAX_INT64); + /** convert double number to string (using ::rtl::math) and DO convert from source unit to target unit */ static void convertDouble( OUStringBuffer& rBuffer, @@ -146,6 +179,9 @@ public: /** convert string to double number (using ::rtl::math) without unit conversion */ static bool convertDouble(double& rValue, std::u16string_view rString); + /** convert string to double number (using ::rtl::math) without unit conversion */ + static bool convertDouble(double& rValue, std::string_view rString); + /** convert number, 10th of degrees with range [0..3600] to SVG angle */ static void convertAngle(OUStringBuffer& rBuffer, sal_Int16 nAngle, SvtSaveOptions::ODFSaneDefaultVersion nVersion); @@ -154,6 +190,10 @@ public: static bool convertAngle(sal_Int16& rAngle, std::u16string_view rString, bool isWrongOOo10thDegAngle); + /** convert SVG angle to number, 10th of degrees with range [0..3600] */ + static bool convertAngle(sal_Int16& rAngle, std::string_view rString, + bool isWrongOOo10thDegAngle); + /** convert double to XMLSchema-2 "duration" string; negative durations allowed */ static void convertDuration(OUStringBuffer& rBuffer, const double fTime); @@ -209,6 +249,7 @@ public: static double GetConversionFactor(OUStringBuffer& rUnit, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit); static sal_Int16 GetUnitFromString(std::u16string_view rString, sal_Int16 nDefaultUnit); + static sal_Int16 GetUnitFromString(std::string_view rString, sal_Int16 nDefaultUnit); /** convert an Any to string (typesafe) */ static bool convertAny(OUStringBuffer& rsValue, |