diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-05-18 14:23:15 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-05-18 16:10:41 +0200 |
commit | eca89ece45ede76605a6102c94b3b67e1f8ff5aa (patch) | |
tree | 13973d98d4cbcf324fddec118da696202b9b5cd9 /include | |
parent | 2f9d909a01f90197c3029a446f8aac8135f53f48 (diff) |
Replace rtl_string_getTokenView with o3tl::getToken
...to not needlessly extend the sal ABI.
At least for now, o3tl::getToken has a simpler interface than its
OString::getToken counterpart (driven mainly by how it is used for now): it does
not support a `token` argument, and its `position` argument must not be npos.
To meet the latter requirement, the check for "subpath" in LineParser::readPath
has been reworked slightly.
Change-Id: I4428fe2d9aa03ca83a436fc6493fbc34665a8033
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115742
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/o3tl/string_view.hxx | 24 | ||||
-rw-r--r-- | include/rtl/string.h | 39 | ||||
-rw-r--r-- | include/rtl/string.hxx | 9 |
3 files changed, 24 insertions, 48 deletions
diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx index d343befd0efe..5ebbb0b9f044 100644 --- a/include/o3tl/string_view.hxx +++ b/include/o3tl/string_view.hxx @@ -11,6 +11,8 @@ #include <sal/config.h> +#include <cassert> +#include <cstddef> #include <string_view> #include <rtl/ustring.h> @@ -22,6 +24,28 @@ inline bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2 { return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), s2.data(), s2.size()); }; + +// Similar to OString::getToken, returning the first token of a std::string_view, starting at a +// given position (and if needed, it can be turned into a template to also cover std::u16string_view +// etc., or extended to return the n'th token instead of just the first, or support an initial +// position of npos): +inline std::string_view getToken(std::string_view sv, char delimiter, std::size_t& position) +{ + assert(position <= sv.size()); + auto const n = sv.find(delimiter, position); + std::string_view t; + if (n == std::string_view::npos) + { + t = sv.substr(position); + position = std::string_view::npos; + } + else + { + t = sv.substr(position, n - position); + position = n + 1; + } + return t; +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/rtl/string.h b/include/rtl/string.h index c86468c7f302..d29caf93a718 100644 --- a/include/rtl/string.h +++ b/include/rtl/string.h @@ -1309,45 +1309,6 @@ 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(); -/** @cond INTERNAL */ -/** Create a new string by extracting a single token from another string. - - Starting at index, the 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. - - This function does not handle out-of-memory conditions. - - @param ppViewStr - pointer to the start of the token. - - @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 - */ -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(); -/** @endcond */ - /* ======================================================================= */ /** Supply an ASCII string literal together with its length. diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index 3fc461de0c2c..f80dd7410da7 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -1765,15 +1765,6 @@ public: index = rtl_string_getToken( &pNew, pData, token, cTok, index ); return OString( pNew, SAL_NO_ACQUIRE ); } -#ifdef LIBO_INTERNAL_ONLY - 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. |