diff options
author | Noel Grandin <noel@peralex.com> | 2021-05-14 15:51:38 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-15 11:21:59 +0200 |
commit | 3669d4ec43a6aa2d410d8351d631548db45a5302 (patch) | |
tree | 3d44cc891951b1c8e8ef2719feee2800b263c9b5 /sal | |
parent | 63b897c36afbfb85e0dd45907f76727f7dee494e (diff) |
add OString::getTokenView (tdf#42374 related)
small improvement to PDF import
no need to construct temporary string objects when we are just to
going to convert them into int/double.
So use a view and convert the data through the view.
Change-Id: I824fe88bf17142b48fe6032e10c0f3a111927e96
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115616
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/string.cxx | 10 | ||||
-rw-r--r-- | sal/rtl/strtmpl.hxx | 76 | ||||
-rw-r--r-- | sal/util/sal.map | 8 |
3 files changed, 93 insertions, 1 deletions
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx index 94be8029032a..2eb4654caeb4 100644 --- a/sal/rtl/string.cxx +++ b/sal/rtl/string.cxx @@ -559,6 +559,11 @@ sal_Int32 SAL_CALL rtl_str_toInt32(const char* pStr, sal_Int16 nRadix) SAL_THROW return rtl::str::toInt32(pStr, nRadix); } +sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(const char* pStr, sal_Int16 nRadix, sal_Int32 nStrLength) SAL_THROW_EXTERN_C() +{ + return rtl::str::toInt32_WithLength(pStr, nRadix, nStrLength); +} + sal_Int64 SAL_CALL rtl_str_toInt64(const char* pStr, sal_Int16 nRadix) SAL_THROW_EXTERN_C() { return rtl::str::toInt64(pStr, nRadix); @@ -700,4 +705,9 @@ sal_Int32 SAL_CALL rtl_string_getToken(rtl_String** ppThis, rtl_String* pStr, sa return rtl::str::getToken(ppThis, pStr, nToken, cTok, nIndex); } +sal_Int32 SAL_CALL rtl_string_getTokenView(const char ** ppViewStr , sal_Int32* pViewLength, rtl_String* pStr, sal_Int32 nToken, + char cTok, sal_Int32 nIndex) SAL_THROW_EXTERN_C() +{ + return rtl::str::getTokenView(ppViewStr, pViewLength, pStr, nToken, cTok, nIndex); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx index fdb26fd15cf1..a25e8216d154 100644 --- a/sal/rtl/strtmpl.hxx +++ b/sal/rtl/strtmpl.hxx @@ -914,6 +914,15 @@ sal_Int32 toInt32 ( const IMPL_RTL_STRCODE* pStr, } template <typename IMPL_RTL_STRCODE> +sal_Int32 toInt32_WithLength ( const IMPL_RTL_STRCODE* pStr, + sal_Int16 nRadix, + sal_Int32 nStrLength ) +{ + assert(pStr); + return toInt_WithLength<sal_Int32, sal_uInt32>(pStr, nRadix, nStrLength); +} + +template <typename IMPL_RTL_STRCODE> sal_Int64 toInt64 ( const IMPL_RTL_STRCODE* pStr, sal_Int16 nRadix ) { @@ -1731,6 +1740,73 @@ sal_Int32 getToken ( IMPL_RTL_STRINGDATA** ppThis return -1; } } + + +/* ----------------------------------------------------------------------- */ + +template <typename IMPL_RTL_STRINGDATA> +sal_Int32 getTokenView ( const char ** ppViewStr, + sal_Int32 * pViewLength, + IMPL_RTL_STRINGDATA* pStr, + sal_Int32 nToken, + STRCODE<IMPL_RTL_STRINGDATA> cTok, + sal_Int32 nIndex ) +{ + assert(ppViewStr); + assert(pViewLength); + assert(pStr); + const auto* pCharStr = pStr->buffer; + sal_Int32 nLen = pStr->length-nIndex; + sal_Int32 nTokCount = 0; + + // Set ppThis to an empty string and return -1 if either nToken or nIndex is + // negative: + if (nIndex < 0) + nToken = -1; + + pCharStr += nIndex; + const auto* pOrgCharStr = pCharStr; + const auto* pCharStrStart = pCharStr; + while ( nLen > 0 ) + { + if ( *pCharStr == cTok ) + { + nTokCount++; + + if ( nTokCount == nToken ) + pCharStrStart = pCharStr+1; + else + { + if ( nTokCount > nToken ) + break; + } + } + + pCharStr++; + nLen--; + } + + if ( (nToken < 0) || (nTokCount < nToken) || (pCharStr == pCharStrStart) ) + { + if( (nToken < 0) || (nTokCount < nToken) ) + return -1; + else if( nLen > 0 ) + return nIndex+(pCharStr-pOrgCharStr)+1; + else return -1; + } + else + { + *ppViewStr = pCharStrStart; + *pViewLength = pCharStr-pCharStrStart; + if ( nLen ) + return nIndex+(pCharStr-pOrgCharStr)+1; + else + return -1; + } +} + + + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/util/sal.map b/sal/util/sal.map index 49efb2a436cd..2f74ceb9150e 100644 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -753,7 +753,13 @@ PRIVATE_1.6 { # LibreOffice 6.4 PRIVATE_1.7 { # LibreOffice 7.1 global: rtl_uString_newReplaceAllFromIndexUtf16LUtf16L; -} PRIVATE_1.5; +} PRIVATE_1.6; + +PRIVATE_1.8 { # LibreOffice 7.2 + global: + rtl_string_getTokenView; + rtl_str_toInt32_WithLength; +} PRIVATE_1.7; PRIVATE_textenc.1 { # LibreOffice 3.6 global: |