summaryrefslogtreecommitdiff
path: root/sal/rtl/ustring.cxx
AgeCommit message (Collapse)Author
2023-12-11Step 3 of removing cargo-cult pragma pack around rtl_[u]StringStephan Bergmann
see 8ae3ae4bf75fdd0aaa132c956d9da029baa3adc6 "Step 1 of removing cargo-cult pragma pack around rtl_[u]String" Change-Id: If6c2ea0ab2e7e61cdbc880d7b27d2af7f816e66d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158568 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2023-09-24Drop some newly obsolete __clang_major__ version checksStephan Bergmann
...after 6ef2d358ac053ce0f6de9cf0f8f25e8bae66d441 "Adapt Clang and GCC minimum version checks" Change-Id: Ib25fbb76211d1bda1d230de771f207960e645421 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157204 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2023-09-19tdf#146619 Remove unused includes from sal/ [cpp files]Gabor Kelemen
Change-Id: I11a54c1ddf73c16ce46a0d1c375bf43157870db7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155856 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
2023-05-06update loplugin:stringview* for o3tl::iterateCodePointsNoel Grandin
And change o3tl::iterateCodePoints to use sal_Int32 for its second param, to integrate better with places where the parameter comes from an UNO API, which cannot use std::size_t Change-Id: I7b9dd2c9bc7f48e6c4a912f039f1b5dae7beae69 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151421 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-05-06Simplify rtl_(u)string_newReplace implementationMike Kaganski
and unify with *ToAscii(Lower/Upper)Case Change-Id: I06999b4f5f34abc8da2860b7f9e279608edb40dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151381 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2023-05-04Provide std::u16string_view based o3tl::iterateCodePointsStephan Bergmann
...as requested in the comments of <https://gerrit.libreoffice.org/c/core/+/151303> "a11y: Fix returning unpaired surrogates when retrieving characters" (incl. the additional preAdjustIndex parameter). The type of the indexUtf16 parameter obviously needed to be adapted to std::u16string_view's std::size_t. But there is no obvious best choice for the type of the incrementCodePoints parameter (int? std::ssize_t?), so lets leave it as sal_Int32. For simplicity of avoiding a Library_o3tl, and to allow o3tl::iterateCodePoints to be used in the implementation of rtl_uString_iterateCodePoints now, o3tl::iterateCodePoints is provided as an inline function defined in the include file. Change-Id: I8280ca11d2a943bd2b7150a266807b358f321a72 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151366 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-12-13Fix the "Found char > 127" warning to check the correct charactersMike Kaganski
Change-Id: Ia4a713c8a5ddda11e9802cbc317dde9ff48b8fd3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144026 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-03-21Move implementation of doubleToString to sal/rtl/strtmpl.hxxMike Kaganski
... to reduce inter-relations between compilation units, and drop *StringTraits from sal/rtl/math.cxx. Change-Id: I0d7544dead03651dc71ec923cab10580f15cf49a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131895 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-03-21Reorganize the code a bit to drop some detail::* helper functionsMike Kaganski
Change-Id: Iee7402f5de7287678e1691b48b6493d3131ef7ee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131883 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-03-03Deduplicate some char replacement functionsMike Kaganski
Change-Id: Ie65224066941dbab89abb6fc91e6cbfbc45bf201 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130901 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins
2022-03-02Unify normal/shortened, null-terminated/with-length comparisonsMike Kaganski
Change-Id: Ie154efd1e0d9b49601200ac896d5d5dd0422d504 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130832 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-03-02Drop useless indirection and unused templateMike Kaganski
Change-Id: Icbcf56c30c9d901a4436f56a1648a7c8e7504848 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130817 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-28Deduplicate string buffer codeMike Kaganski
Change-Id: Ia23974ad3a827c84bb1a5d633a953625aea2576a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130663 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-27Unify creation of character string copyMike Kaganski
Change-Id: Ifef89cfd98771f247a308fab58da410a7079ecfc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130632 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-27Deduplicate newToAscii*CaseMike Kaganski
Change-Id: I55f4f43375037ad4247f592bc981d8718c12de68 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130631 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-27Deduplicate more comparison functionsMike Kaganski
Change-Id: I93aba36b7cde268e358bd96b55183533ddc70b16 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130603 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-25Deduplicate rtl_uString_newReplaceFirst*Mike Kaganski
Change-Id: I6e09fd8e8acc06290423c1c44cc0c175b0c47e0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130547 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-25Make an -fsanitize=undefined workaround conditionalStephan Bergmann
...that had been introduced with b5cb4935c268f12e63b61e035b455b0a59e67aa2 "Work around undef conversion of large double to float" but should no longer be necessary with <https://github.com/llvm/llvm-project/commit/9e52c43090f8cd980167bbd2719878ae36bcf6b5> "Treat the range of representable values of floating-point types as [-inf, +inf] not as [-max, +max]" added towards Clang 9. Thanks to Mike Kaganski for pointing me at this old code and at Richard Smith's comment at <https://cplusplusmusings.wordpress.com/2013/03/26/testing-libc-with-fsanitizeundefined/>. Change-Id: I8ecf115fcf6b1ebf621cb4567f8d31ac9b10ef1c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130531 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-02-25Don't invent another strlenMike Kaganski
Change-Id: I7f7b7029ac03b1f06f4d9c2612b9b008b033baea Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130538 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-25Use some rtl functionsMike Kaganski
Change-Id: I12fe2f5fe447e2bc6567e3d0375f1671e781697e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130515 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-25Deduplicate some comparison functionsMike Kaganski
Change-Id: Iffeb4323c99649d45387981ec583fdcff207ec4e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130512 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-24Deduplicate rtl_*String_newConcat*LMike Kaganski
Change-Id: I9712cd8a2798fe5493dffd557e68239d9db3b7aa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130501 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-24Deduplicate rtl_*str_valueOf{Float,Double}Mike Kaganski
Change-Id: Ie3254fbf6178f4e623fd8209b58e9f19d2c46d2c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130480 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-24Deduplicate valueOf*Int*Mike Kaganski
Change-Id: Ib9da148c371f52ee8da2848581bb8a024f97de96 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130479 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-22Deduplicate newReplaceMike Kaganski
Optimize some places for single character case for that Change-Id: I99b2abd2fd3c89a98ed1d84f7b70ed4def83da2d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130371 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-17Deduplicate some codeMike Kaganski
Change-Id: Ib05624739cce31b08fc409f238d447ed8d99bad9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130016 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-16Related: tdf#147421: optimize O(U)String's replaceAll*Mike Kaganski
... and underlying low-level C functions. Change-Id: I78c2dd75e272e6d3cdd2cfae007ca0a0ec1635e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129942 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2022-02-16De-duplicate some codeMike Kaganski
Change-Id: I355fd800e09cef0776408375bd4d6053048d7eb8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129943 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2021-11-23O[U]String::replaceAt overloads that take string_viewNoel Grandin
which results in lots of nice string_view improvements picked up by the plugins Change-Id: Ib0ec3887816b3d4436d003b739d9814f83e244b2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125657 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-09-17Drop this unneeded indirectionMike Kaganski
Change-Id: I6b40642c7574a1863658854d206ed849517dbd0f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122130 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2021-04-23Step 1 of removing cargo-cult pragma pack around rtl_[u]StringStephan Bergmann
Following up on f62cb40bdfaf41cf8e989640f9be79f652f30914 "Remove dubious #pragma pack" and 9eba8aa38db3a0dc2f7dfaf24a003c16418aef18 "Remove dubious #pragma pack" for O[U]StringLiteral, which argued that the pragma pack around rtl_[u]String are useless cargo cult (paraphrasing): "All struct member types involved (oslInterlockedCount aka sal_Int32, sal_Int32 itself, sal_Unicode, and char) have size <= 4 resp. < 8, so the member alignment ("on a boundary that's either a multiple of [the pragma pack value], or a multiple of the size of the member, whichever is smaller", according to <https://docs.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-160>) is not affected. And neither are alignof(rtl_String) and alignof(rtl_uString) affected, which would remain e.g. 4 on x86-64." (Curiously, the pragma pack value had always been 8 for rtl_String but 4 for rtl_uString, ever since at least 9399c662f36c385b0c705eb34e636a9aec450282 "initial import".) The plan is as follows: In step 1, add temporary static_asserts that state the current alignof/sizeof values; keep this for a while to see that all relevant Windows builds actually agree on these status-quo values. In step 2, remove the pragma pack cargo cult; keep the static_asserts for a while to see that the removal has no impact on any of the relevant Windows builds. Finally, in step 3, remove the temporary static_asserts again. Change-Id: I8059ac300cc5b517db4a575f0eaba48678966537 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114540 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2021-02-08Remove unneeded breaksAndrea Gelmini
Extending this: https://gerrit.libreoffice.org/c/core/+/110512 Change-Id: I1c5bfcddeb0f5619dc848bbf02408cf166bebc8e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110521 Tested-by: Jenkins Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2021-01-10Replace strtmpl.cxx with actual C++ templates in strtmpl.hxxMike Kaganski
This has at least better IDE support, with easier lookup for function implementations. Change-Id: I0e4cfe40df036efa796c057852bd5cb4421507f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108931 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2020-11-21Relax non-null requirement for some rtl_uString_* functionsStephan Bergmann
...that take a pointer and a length, and where it should be OK that the pointer is null if the length is zero. Those rtl_uString_* functions are targets of OUString member functions that take std::[u16]string_view arguments, and 19926ed35ebb623fc896942b1f232b83edf1fc1e "loplugin:stringview: Flag empty string converted to string view" (which changed some call sites to pass in default- constructed std::[u16]string_view, for which data() returns null) revealed that those rtl_uString_* functions were not prepared for such input. (The guardings of memcpy are necessary because memcpy still requires its pointer arguments to be non-null, even if the corresponding length is zero.) The new sal/qa/rtl/strings/test_strings_defaultstringview.cxx systematically tests all O[U]String[Buffer] member functions taking std::[u16]string_view arguments. It revealed one further issue in IMPL_RTL_STRNAME(compare_WithLength), where UBSan reported a nullptr-with-nonzero-offset > sal/rtl/strtmpl.cxx:149:9: runtime error: applying non-zero offset 18446744073709551614 to null pointer Also, rtl_uString_newReplaceFirstUtf16LUtf16L was found to lack a check for its `from` argument to be non-null. Change-Id: I6a7a712570f7d1e8d52097208c8a43a5a24797af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106295 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-10-05loplugin:reducevarscope in salNoel
Change-Id: I2ce95de07b8e0952a1e778e65940b30597396aa6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103949 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-09-04Make many OUString functions take std::u16string_view parametersStephan Bergmann
...instead of having individual overloads for OUString, OUStringLiteral, and literal char16_t const[N]. (The variants taking OUString are still needed for !LIBO_INTERNAL_ONLY, though. The variants taking ASCII-only literal char const[N] are also left in place.) This nicely reduces the number of needed overloads. std::u16string_view allows to pass as arguments: * OUString * OUStringLiteral * OUStringChar (with the necessary conversion added now) * OUStringNumber * u"..." char16_t string literals * u"..."sv std::u16string_view literals * std::u16string, plain char16_t*, and more A notable exceptions is OUStringConcat, which now needs to be wrapped in OUString(...), see the handful of places that needed to be adapted. One caveat is the treatment of embedded NUL characters, as std::u16string_view(u"x\0y") constructs a view of size 1, while only u"x\0y"sv constructs a view of size 3 (which matches the old behavior of overloads for literal char16_t const[N] via the ConstCharArrayDetector<>::TypeUtf16 machinery). See the new checkEmbeddedNul in sal/qa/rtl/strings/test_oustring_stringliterals.cxx. The functions that have been changed are generally those that: * already take a string of determined length, so that using std::u16string_view, which is always constructed with a determined length, is no pessimization (e.g., there are operator == overloads taking plain pointers, which do not need to determine the string length upfront); * could not benefit from the fact that the passed-in argument is an OUString (e.g., the corresponding operator = overload can reuse the passed-in OUString's rtl_uString pData member); * do not run into overload resolution ambiguity issues, like the comparison operators would do. One inconsistency that showed up is that while the original replaceAll(OUString const &, OUString const &, sal_Int32 fromIndex = 0) overload takes an optional third fromIndex argument, the existing replaceAll overloads taking OUStringLiteral and literal char16_t const[N] arguments did not. Fixing that required a new (LIBO_INTERNAL_ONLY) rtl_uString_newReplaceAllFromIndexUtf16LUtf16L (with test code in sal/qa/rtl/strings/test_strings_replace.cxx). Another issue was posed by test code in sal/qa/rtl/strings/test_oustring_stringliterals.cxx that used the RTL_STRING_UNITTEST-only OUString(Except*CharArrayDetector) ctors to verify that certain function calls should not compile (and would compile under RTL_STRING_UNITTEST by taking those Except*CharArrayDetector converted to OUString as arguments). Those problematic "should fail to compile" tests have been converted into a new CompilerTest_sal_rtl_oustring. Change-Id: Id72e8c4cc338258cadad00ddc6ea5b9da2e1f780 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102020 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-08-11loplugin:flattenNoel Grandin
Change-Id: I6560756eb63856a22b43e3e65a7b7843cd2d5376 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100447 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2020-07-02Upcoming improved loplugin:staticanonymous -> redundantstatic: salStephan Bergmann
Change-Id: I022f5ed37d25f2c8a8870033bab32ff59d4d8da6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97648 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-04-15loplugin:buriedassign in salNoel Grandin
Change-Id: I5a7bc9378ceacb9116c03e3a9fc01c5675c40908 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92243 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-12-19sal_Char->char in remotebridges..saxNoel Grandin
Change-Id: I6d32942960a5e997f16eb1301c45495661cd4cea Reviewed-on: https://gerrit.libreoffice.org/85514 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-11-17Extend loplugin:external to warn about enumsStephan Bergmann
To mitigate the dangers of silently breaking ADL when moving enums into unnamed namespaces (see the commit message of 206b5b2661be37efdff3c6aedb6f248c4636be79 "New loplugin:external"), note all functions that are affected. (The plan is to extend loplugin:external further to also warn about classes and class templates, and the code to identify affected functions already takes that into account, so some parts of that code are not actually relevant for enums.) But it appears that none of the functions that are actually affected by the changes in this commit relied on being found through ADL, so no adaptions were necessary for them. (clang::DeclContext::collectAllContexts is non-const, which recursively means that External's Visit... functions must take non-const Decl*. Which required compilerplugins/clang/sharedvisitor/analyzer.cxx to be generalized to support such Visit... functions with non-const Decl* parameters.) Change-Id: Ia215291402bf850d43defdab3cff4db5b270d1bd Reviewed-on: https://gerrit.libreoffice.org/83001 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2018-11-11Fix typoAndrea Gelmini
Change-Id: Id2478ac637140b604cb0f7e3aa4267f02aa859c4 Reviewed-on: https://gerrit.libreoffice.org/63255 Reviewed-by: Julien Nabet <serval2412@yahoo.fr> Tested-by: Jenkins
2018-02-02sal: MSVC: pragma warning: make more specific, remove obsoleteMike Kaganski
Change-Id: Ib7ad23257a966447d627b4f73698d9298790f759 Reviewed-on: https://gerrit.libreoffice.org/49042 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2018-01-15convert a<b?a:b to std::min(a,b)Noel Grandin
with something like git grep -nP '(.*)\s*<\s*(.*)\s*\?\s*\g1\s*:\s*\g2' -- *.?xx Change-Id: Id5078b35961847feb78a66204fdb7598ee63fd23 Note: we also convert a>b?b:a Reviewed-on: https://gerrit.libreoffice.org/47736 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2018-01-12More loplugin:cstylecast: salStephan Bergmann
auto-rewrite with <https://gerrit.libreoffice.org/#/c/47798/> "Enable loplugin:cstylecast for some more cases" plus solenv/clang-format/reformat-formatted-files Change-Id: I7d89b011464ba5d2dd12e04d5fc9f65cb4daebde
2017-12-15sal: add pre-initialization scheme for allocations.Michael Meeks
This saves several megabytes of dirtied pages for each LOK client of Online. Change-Id: I425a2e7896879f0a64d71fcc0655e9e1fa1256aa
2017-10-23loplugin:includeform: salStephan Bergmann
Change-Id: I539ca8b9dee5edc5fc2282a2b9b0ffd78bad8b11
2017-07-17RTL_UNICODETOTEXT_INFO_{DEST|SCR}BUFFERTOSMALL should use TOO, not TOChris Sherlock
I have kept the old mispelled constant for backwards compatibility Change-Id: I128a2eec76d00cc5ef058cd6a0c35a7474d2411e Reviewed-on: https://gerrit.libreoffice.org/39995 Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com> Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
2017-07-06loplugin unnecessaryparan improvementsNoel Grandin
Change-Id: I73e945d6ec53537a0da45f6b6291018c7f251a7e Reviewed-on: https://gerrit.libreoffice.org/39587 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-06-07sal: use thread safe local static in getInternMutexJochen Nitschke
Change-Id: Iac7ca87e05228f3a2a187646496869a8b1bff602 Reviewed-on: https://gerrit.libreoffice.org/38436 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>