[Libreoffice-commits] core.git: include/o3tl include/rtl sal/rtl sal/util sdext/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Tue May 18 14:11:23 UTC 2021
include/o3tl/string_view.hxx | 24 ++++++++++
include/rtl/string.h | 39 -----------------
include/rtl/string.hxx | 9 ---
sal/rtl/string.cxx | 5 --
sal/rtl/strtmpl.hxx | 66 -----------------------------
sal/util/sal.map | 5 --
sdext/source/pdfimport/wrapper/wrapper.cxx | 38 ++++++++--------
7 files changed, 44 insertions(+), 142 deletions(-)
New commits:
commit eca89ece45ede76605a6102c94b3b67e1f8ff5aa
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue May 18 14:23:15 2021 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue May 18 16:10:41 2021 +0200
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 at redhat.com>
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.
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index ec6b95718b3c..94be8029032a 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -700,9 +700,4 @@ 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 855516cec1d4..094a1cc1f2ab 100644
--- a/sal/rtl/strtmpl.hxx
+++ b/sal/rtl/strtmpl.hxx
@@ -1732,72 +1732,6 @@ sal_Int32 getToken ( IMPL_RTL_STRINGDATA** ppThis
}
}
-
-/* ----------------------------------------------------------------------- */
-
-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 bc6e90ec488e..49efb2a436cd 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -755,11 +755,6 @@ PRIVATE_1.7 { # LibreOffice 7.1
rtl_uString_newReplaceAllFromIndexUtf16LUtf16L;
} PRIVATE_1.5;
-PRIVATE_1.8 { # LibreOffice 7.2
- global:
- rtl_string_getTokenView;
-} PRIVATE_1.7;
-
PRIVATE_textenc.1 { # LibreOffice 3.6
global:
_ZN3sal6detail7textenc20convertCharToUnicode*;
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx
index 9bd803d0348f..78fb9cd0b331 100644
--- a/sdext/source/pdfimport/wrapper/wrapper.cxx
+++ b/sdext/source/pdfimport/wrapper/wrapper.cxx
@@ -24,6 +24,7 @@
#include <pdfihelper.hxx>
#include <wrapper.hxx>
+#include <o3tl/string_view.hxx>
#include <osl/file.h>
#include <osl/file.hxx>
#include <osl/thread.h>
@@ -58,6 +59,7 @@
#include <vcl/font.hxx>
#include <vcl/virdev.hxx>
+#include <cstddef>
#include <memory>
#include <string_view>
#include <unordered_map>
@@ -181,7 +183,7 @@ class LineParser {
uno::Sequence<beans::PropertyValue> readImageImpl();
public:
- sal_Int32 m_nCharIndex = 0;
+ std::size_t m_nCharIndex = 0;
LineParser(Parser & parser, OString const & line): m_parser(parser), m_aLine(line) {}
@@ -254,8 +256,8 @@ OString lcl_unescapeLineFeeds(std::string_view i_rStr)
std::string_view LineParser::readNextToken()
{
- OSL_PRECOND(m_nCharIndex!=-1,"insufficient input");
- return m_aLine.getTokenView(0,' ',m_nCharIndex);
+ OSL_PRECOND(m_nCharIndex!=std::string_view::npos,"insufficient input");
+ return o3tl::getToken(m_aLine,' ',m_nCharIndex);
}
void LineParser::readInt32( sal_Int32& o_Value )
@@ -322,7 +324,7 @@ uno::Reference<rendering::XPolyPolygon2D> LineParser::readPath()
OSL_PRECOND(false, "broken path");
basegfx::B2DPolyPolygon aResult;
- while( m_nCharIndex != -1 )
+ while( m_nCharIndex != std::string_view::npos )
{
basegfx::B2DPolygon aSubPath;
@@ -331,11 +333,14 @@ uno::Reference<rendering::XPolyPolygon2D> LineParser::readPath()
aSubPath.setClosed( nClosedFlag != 0 );
sal_Int32 nContiguousControlPoints(0);
- sal_Int32 nDummy=m_nCharIndex;
- std::string_view aCurrToken( m_aLine.getTokenView(0,' ',nDummy) );
- while( m_nCharIndex != -1 && aCurrToken != aSubPathMarker )
+ while( m_nCharIndex != std::string_view::npos )
{
+ std::size_t nDummy=m_nCharIndex;
+ if (o3tl::getToken(m_aLine,' ',nDummy) == aSubPathMarker) {
+ break;
+ }
+
sal_Int32 nCurveFlag;
double nX, nY;
readDouble( nX );
@@ -363,14 +368,10 @@ uno::Reference<rendering::XPolyPolygon2D> LineParser::readPath()
nContiguousControlPoints=0;
}
-
- // one token look-ahead (new subpath or more points?
- nDummy=m_nCharIndex;
- aCurrToken = m_aLine.getTokenView(0,' ',nDummy);
}
aResult.append( aSubPath );
- if( m_nCharIndex != -1 )
+ if( m_nCharIndex != std::string_view::npos )
readNextToken();
}
@@ -396,11 +397,11 @@ void LineParser::readChar()
OString aChars;
- if (m_nCharIndex != -1)
+ if (m_nCharIndex != std::string_view::npos)
aChars = lcl_unescapeLineFeeds( m_aLine.subView( m_nCharIndex ) );
// chars gobble up rest of line
- m_nCharIndex = -1;
+ m_nCharIndex = std::string_view::npos;
m_parser.m_pSink->drawGlyphs(OStringToOUString(aChars, RTL_TEXTENCODING_UTF8),
aRect, aUnoMatrix, fontSize);
@@ -421,7 +422,7 @@ void LineParser::readLineCap()
void LineParser::readLineDash()
{
- if( m_nCharIndex == -1 )
+ if( m_nCharIndex == std::string_view::npos )
{
m_parser.m_pSink->setLineDash( uno::Sequence<double>(), 0.0 );
return;
@@ -613,7 +614,7 @@ void LineParser::readFont()
aFontName = lcl_unescapeLineFeeds( m_aLine.subView( m_nCharIndex ) );
// name gobbles up rest of line
- m_nCharIndex = -1;
+ m_nCharIndex = std::string_view::npos;
Parser::FontMapType::const_iterator pFont( m_parser.m_aFontMap.find(nFontID) );
if( pFont != m_parser.m_aFontMap.end() )
@@ -793,7 +794,7 @@ void LineParser::readLink()
m_aLine.subView(m_nCharIndex) ),
RTL_TEXTENCODING_UTF8 ) );
// name gobbles up rest of line
- m_nCharIndex = -1;
+ m_nCharIndex = std::string_view::npos;
}
void LineParser::readMaskedImage()
@@ -907,7 +908,8 @@ void Parser::parseLine( const OString& rLine )
}
// all consumed?
- SAL_WARN_IF(lp.m_nCharIndex!=-1, "sdext.pdfimport", "leftover scanner input");
+ SAL_WARN_IF(
+ lp.m_nCharIndex!=std::string_view::npos, "sdext.pdfimport", "leftover scanner input");
}
} // namespace
More information about the Libreoffice-commits
mailing list