summaryrefslogtreecommitdiffstats
path: root/include/rtl
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2021-05-14 15:51:38 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-15 11:21:59 +0200
commit3669d4ec43a6aa2d410d8351d631548db45a5302 (patch)
tree3d44cc891951b1c8e8ef2719feee2800b263c9b5 /include/rtl
parentUse less memory for ScMatrix::Collect (diff)
downloadcore-3669d4ec43a6aa2d410d8351d631548db45a5302.tar.gz
core-3669d4ec43a6aa2d410d8351d631548db45a5302.zip
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 'include/rtl')
-rw-r--r--include/rtl/string.h78
-rw-r--r--include/rtl/string.hxx9
2 files changed, 87 insertions, 0 deletions
diff --git a/include/rtl/string.h b/include/rtl/string.h
index bfbb45057fd9..c0f724245d9e 100644
--- a/include/rtl/string.h
+++ b/include/rtl/string.h
@@ -747,6 +747,31 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL rtl_str_toBoolean(
SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32(
const char * str, sal_Int16 radix ) SAL_THROW_EXTERN_C();
+/** Interpret a string as an integer.
+
+ This function cannot be used for language-specific conversion. The string
+ must be null-terminated.
+
+ @param str
+ a null-terminated string.
+
+ @param radix
+ the radix. Must be between RTL_STR_MIN_RADIX (2) and RTL_STR_MAX_RADIX
+ (36), inclusive.
+
+ @param len
+ the length of the character array.
+
+ @return
+ the integer value represented by the string, or 0 if the string does not
+ represent an integer.
+
+ @since LibreOffice 7.2
+ @internal
+ */
+SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_toInt32_WithLength(
+ const char * str, sal_Int16 radix, sal_Int32 nStrLength ) SAL_THROW_EXTERN_C();
+
/** Interpret a string as an unsigned integer.
This function cannot be used for language-specific conversion. The string
@@ -1309,6 +1334,59 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_newTrim(
SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getToken(
rtl_String ** newStr , rtl_String * str, sal_Int32 token, char cTok, sal_Int32 idx ) SAL_THROW_EXTERN_C();
+/** Create a new string by extracting a single token from another string.
+
+ Starting at index, the token's next token is searched for. If there is no
+ such token, the result is an empty string. Otherwise, all characters from
+ the start of that token and up to, but not including the next occurrence
+ of cTok make up the resulting token. The return value is the position of
+ the next token, or -1 if no more tokens follow.
+
+ Example code could look like
+ rtl_String * pToken = NULL;
+ sal_Int32 nIndex = 0;
+ do
+ {
+ ...
+ nIndex = rtl_string_getToken(&pToken, pStr, 0, ';', nIndex);
+ ...
+ }
+ while (nIndex >= 0);
+
+ The new string does not necessarily have a reference count of 1, so it
+ must not be modified without checking the reference count. This function
+ does not handle out-of-memory conditions.
+
+ @param ppViewStr
+ pointer to the start of the token. The pointed-to data must be null or a valid
+ string. If either token or index is negative, nullptr is stored in
+ newStr (and -1 is returned).
+
+ @param pViewLength
+ length of the token.
+
+ @param str
+ a valid string.
+
+ @param token
+ the number of the token to return, starting at index.
+
+ @param cTok
+ the character that separates the tokens.
+
+ @param idx
+ the position at which searching for the token starts. Must not be greater
+ than the length of str.
+
+ @return
+ the index of the next token, or -1 if no more tokens follow.
+
+ @since LibreOffice 7.2
+ @internal
+ */
+SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_string_getTokenView(
+ const char ** ppViewStr , sal_Int32* pViewLength, rtl_String * str, sal_Int32 token, char cTok, sal_Int32 idx ) SAL_THROW_EXTERN_C();
+
/* ======================================================================= */
/** Supply an ASCII string literal together with its length.
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index f80dd7410da7..c16519fa14df 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1765,6 +1765,15 @@ public:
index = rtl_string_getToken( &pNew, pData, token, cTok, index );
return OString( pNew, SAL_NO_ACQUIRE );
}
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+ std::string_view getTokenView( sal_Int32 token, char cTok, sal_Int32& index ) const
+ {
+ const char* pViewData = nullptr;
+ sal_Int32 nViewLength = 0;
+ index = rtl_string_getTokenView( &pViewData, &nViewLength, pData, token, cTok, index );
+ return std::string_view(pViewData, nViewLength);
+ }
+#endif
/**
Returns a token from the string.