include/sax/fastattribs.hxx        |   28 +++++++++++++++----------
 oox/source/drawingml/textfield.cxx |    6 ++---
 sax/source/tools/fastattribs.cxx   |   40 +++++--------------------------------
 3 files changed, 26 insertions(+), 48 deletions(-)

New commits:
commit 0fceacdb62b40d5d7b739064fd5bee7f28368c60
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Jan 16 13:29:19 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Jan 17 08:54:39 2023 +0000

    Simplify FastAttributeList
    
    Change-Id: Id89edb25e35527e8603c32e44fb2940721aeda58
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145562
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 15fe7346ade34f09f9be016ff847421ce0fa56f4)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145580
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx
index 22512bd5a929..2dc7c3d72420 100644
--- a/include/sax/fastattribs.hxx
+++ b/include/sax/fastattribs.hxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/util/XCloneable.hpp>
 
 #include <cppuhelper/implbase.hxx>
+#include <o3tl/string_view.hxx>
 #include <rtl/math.h>
 #include <sax/saxdllapi.h>
 
@@ -105,9 +106,18 @@ public:
     bool getAsInteger( sal_Int32 nToken, sal_Int32 &rInt) const;
     bool getAsDouble( sal_Int32 nToken, double &rDouble) const;
     bool getAsView( sal_Int32 nToken, std::string_view& rPos ) const;
-    sal_Int32 getAsIntegerByIndex( sal_Int32 nTokenIndex ) const;
-    std::string_view getAsViewByIndex( sal_Int32 nTokenIndex ) const;
-    OUString getValueByIndex( sal_Int32 nTokenIndex ) const;
+    sal_Int32 getAsIntegerByIndex( sal_Int32 nTokenIndex ) const
+    {
+        return o3tl::toInt32(getAsViewByIndex(nTokenIndex));
+    }
+    std::string_view getAsViewByIndex( sal_Int32 nTokenIndex ) const
+    {
+        return std::string_view(getFastAttributeValue(nTokenIndex), 
AttributeValueLength(nTokenIndex));
+    }
+    OUString getValueByIndex( sal_Int32 nTokenIndex ) const
+    {
+        return OStringToOUString(getAsViewByIndex(nTokenIndex), 
RTL_TEXTENCODING_UTF8);
+    }
 
     // XFastAttributeList
     virtual sal_Bool SAL_CALL hasAttribute( ::sal_Int32 Token ) override;
@@ -168,14 +178,12 @@ public:
         sal_Int32 toInt32() const
         {
             assert(mnIdx < mrList.maAttributeTokens.size());
-            return rtl_str_toInt32(mrList.getFastAttributeValue(mnIdx), 10);
+            return mrList.getAsIntegerByIndex(mnIdx);
         }
         double toDouble() const
         {
             assert(mnIdx < mrList.maAttributeTokens.size());
-            const char* pStr = mrList.getFastAttributeValue(mnIdx);
-            sal_Int32 nLen = mrList.AttributeValueLength(mnIdx);
-            return rtl_math_stringToDouble(pStr, pStr + nLen, '.', 0, nullptr, 
nullptr);
+            return o3tl::toDouble(mrList.getAsViewByIndex(mnIdx));
         }
         bool toBoolean() const
         {
@@ -185,9 +193,7 @@ public:
         OUString toString() const
         {
             assert(mnIdx < mrList.maAttributeTokens.size());
-            return OUString(mrList.getFastAttributeValue(mnIdx),
-                            mrList.AttributeValueLength(mnIdx),
-                            RTL_TEXTENCODING_UTF8);
+            return mrList.getValueByIndex(mnIdx);
         }
         const char* toCString() const
         {
@@ -202,7 +208,7 @@ public:
         std::string_view toView() const
         {
             assert(mnIdx < mrList.maAttributeTokens.size());
-            return std::string_view(mrList.getFastAttributeValue(mnIdx), 
mrList.AttributeValueLength(mnIdx));
+            return mrList.getAsViewByIndex(mnIdx);
         }
         bool isString(const char *str) const
         {
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index d020e18de18c..27d7e57f8ad5 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -210,33 +210,19 @@ bool FastAttributeList::getAsInteger( sal_Int32 nToken, 
sal_Int32 &rInt) const
     for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == nToken)
         {
-            sal_Int64 nVal = rtl_str_toInt64_WithLength( 
getFastAttributeValue(i), 10, AttributeValueLength(i) );
-            if (nVal < SAL_MIN_INT32 || nVal > SAL_MAX_INT32) {
-                nVal = 0;
-            }
-            rInt = nVal;
+            rInt = getAsIntegerByIndex(i);
             return true;
         }
     return false;
 }
 
-sal_Int32 FastAttributeList::getAsIntegerByIndex( sal_Int32 nTokenIndex ) const
-{
-    sal_Int64 n = rtl_str_toInt64_WithLength( 
getFastAttributeValue(nTokenIndex), 10, AttributeValueLength(nTokenIndex) );
-    if (n < SAL_MIN_INT32 || n > SAL_MAX_INT32) {
-        n = 0;
-    }
-    return n;
-}
-
 bool FastAttributeList::getAsDouble( sal_Int32 nToken, double &rDouble) const
 {
     rDouble = 0.0;
     for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == nToken)
         {
-            auto const p = getFastAttributeValue(i);
-            rDouble = rtl_math_stringToDouble( p,  p + 
AttributeValueLength(i), '.', 0, nullptr, nullptr );
+            rDouble = o3tl::toDouble(getAsViewByIndex(i));
             return true;
         }
     return false;
@@ -249,41 +235,27 @@ bool FastAttributeList::getAsView( sal_Int32 nToken, 
std::string_view& rPos ) co
         if (maAttributeTokens[i] != nToken)
             continue;
 
-        sal_Int32 nOffset = maAttributeValues[i];
-        size_t nValueLen = maAttributeValues[i + 1] - maAttributeValues[i] - 1;
-        rPos = { mpChunk + nOffset, nValueLen };
+        rPos = getAsViewByIndex(i);
         return true;
     }
 
     return false;
 }
 
-std::string_view FastAttributeList::getAsViewByIndex( sal_Int32 nTokenIndex ) 
const
-{
-    sal_Int32 nOffset = maAttributeValues[nTokenIndex];
-    size_t nValueLen = maAttributeValues[nTokenIndex + 1] - 
maAttributeValues[nTokenIndex] - 1;
-    return { mpChunk + nOffset, nValueLen };
-}
-
 OUString FastAttributeList::getValue( ::sal_Int32 Token )
 {
     for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == Token)
-            return OUString( getFastAttributeValue(i), 
AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
+            return getValueByIndex(i);
 
     throw SAXException("FastAttributeList::getValue: unknown token " + 
OUString::number(Token), nullptr, Any());
 }
 
-OUString FastAttributeList::getValueByIndex( ::sal_Int32 nTokenIndex ) const
-{
-    return OUString( getFastAttributeValue(nTokenIndex), 
AttributeValueLength(nTokenIndex), RTL_TEXTENCODING_UTF8 );
-}
-
 OUString FastAttributeList::getOptionalValue( ::sal_Int32 Token )
 {
     for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
         if (maAttributeTokens[i] == Token)
-            return OUString( getFastAttributeValue(i), 
AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
+            return getValueByIndex(i);
 
     return OUString();
 }
@@ -305,7 +277,7 @@ Sequence< FastAttribute > 
FastAttributeList::getFastAttributes(  )
     for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i)
     {
         pAttr->Token = maAttributeTokens[i];
-        pAttr->Value = OUString( getFastAttributeValue(i), 
AttributeValueLength(i), RTL_TEXTENCODING_UTF8 );
+        pAttr->Value = getValueByIndex(i);
         pAttr++;
     }
     return aSeq;
commit 42f1eff68d625ed4a7c7836489927325517df9e6
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Jan 16 09:29:14 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Jan 17 08:54:28 2023 +0000

    Use o3tl::toInt32 in oox/source/drawingml/textfield.cxx
    
    rtl_ustr_toInt32 was incorrectly used, relying on null-terminated
    content of string views.
    
    Change-Id: Ia3e4bb04a029149e5945274f592252704c34f3eb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145549
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit e5b86ec34da98d92a749885a06e9093c0f64af80)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145579
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/oox/source/drawingml/textfield.cxx 
b/oox/source/drawingml/textfield.cxx
index 2640aa52ce12..ce38159c5e99 100644
--- a/oox/source/drawingml/textfield.cxx
+++ b/oox/source/drawingml/textfield.cxx
@@ -121,7 +121,7 @@ void lclCreateTextFields( std::vector< Reference< 
XTextField > > & aFields,
     }
     else if ( o3tl::starts_with(sType, u"file") )
     {
-        int idx = rtl_ustr_toInt32(sType.data() + 4, 10);
+        int idx = o3tl::toInt32(sType.substr(4));
         xIface = xFactory->createInstance( 
"com.sun.star.text.TextField.FileName" );
         aFields.emplace_back( xIface, UNO_QUERY );
         Reference< XPropertySet > xProps( xIface, UNO_QUERY_THROW );
@@ -215,7 +215,7 @@ SvxDateFormat 
TextField::getLODateFormat(std::u16string_view rDateTimeType)
     if( aDateTimeNum.empty() ) // "datetime"
         return SvxDateFormat::StdSmall;
 
-    int nDateTimeNum = rtl_ustr_toInt32(aDateTimeNum.data(), 10);
+    int nDateTimeNum = o3tl::toInt32(aDateTimeNum);
 
     switch( nDateTimeNum )
     {
@@ -244,7 +244,7 @@ SvxDateFormat 
TextField::getLODateFormat(std::u16string_view rDateTimeType)
 SvxTimeFormat TextField::getLOTimeFormat(std::u16string_view rDateTimeType)
 {
     auto aDateTimeNum = rDateTimeType.substr(8);
-    int nDateTimeNum = rtl_ustr_toInt32(aDateTimeNum.data(), 10);
+    int nDateTimeNum = o3tl::toInt32(aDateTimeNum);
 
     switch( nDateTimeNum )
     {

Reply via email to