Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / stringviewparam.cxx
blobabb98797b1dca7ce6eccbd543b91915269a2f034
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #undef NDEBUG
12 #include "sal/config.h"
14 #include <string_view>
16 #include "rtl/string.hxx"
17 #include "rtl/ustring.hxx"
18 #include "rtl/ustrbuf.hxx"
19 #include "sal/types.h"
21 void f1a(std::string_view);
22 // expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OString &' with 'std::string_view' [loplugin:stringviewparam]}}
23 char f1b(OString const& s)
25 f1a(s);
26 OString rest;
27 if (s.isEmpty() || s.startsWith("foo", &rest) || s.endsWith("foo"))
29 f1a(std::string_view(s));
31 return s[0];
34 void f2a(std::u16string_view);
35 // expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
36 sal_Unicode f2b(OUString const& s)
38 f2a(s);
39 OUString rest;
40 if (s.isEmpty() || s.startsWith("foo", &rest) || s.endsWith("foo"))
42 f2a(std::u16string_view(s));
44 return s[0];
47 void f3a(OUString const&) {}
48 using F3 = void(OUString const&);
49 F3* f3b() { return f3a; }
51 SAL_DLLPUBLIC_EXPORT void f4(OUString const&) {}
53 template <typename T> void f5(T const&);
54 template <> void f5<OUString>(OUString const&) {}
56 void f6([[maybe_unused]] OUString const&) {}
58 bool f7(
59 // expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
60 const OUString& p1,
61 // expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
62 const OUString& p2)
64 return p1 == p2;
66 // expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
67 bool f8(const OUString& p1, std::u16string_view p2) { return p1 == p2; }
69 struct Converter
71 // expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
72 static bool convertBool(bool& rBool, const OUString& rString)
74 rBool = rString == "true";
75 return rBool || (rString == "false");
79 void f9(std::u16string_view);
80 void f9(OUString const& s) { return f9(std::u16string_view(s)); }
82 struct S10
84 S10(std::u16string_view);
85 S10(OUString const& s)
86 : S10(std::u16string_view(s))
91 // expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
92 void f11(const OUString& f11rString)
94 OUStringBuffer buf;
95 buf.append(f11rString);
98 // expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
99 sal_uInt32 decimalStringToNumber(OUString const& str, sal_Int32 nStart, sal_Int32 nLength)
101 sal_uInt32 result = 0;
102 for (sal_Int32 i = nStart; i < nStart + nLength;)
104 sal_uInt32 c = str.iterateCodePoints(&i);
105 sal_uInt32 value = 0;
106 if (c <= 0x0039)
107 value = c - 0x0030;
108 result = result * 10 + value;
110 return result;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */