1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <sal/config.h>
13 #include <string_view>
15 #include <rtl/strbuf.hxx>
16 #include <rtl/string.hxx>
17 #include <rtl/ustrbuf.hxx>
18 #include <rtl/ustring.hxx>
19 #include <sal/log.hxx>
23 void f1(bool, const OString
& s
);
26 void f1(bool, const OString
& s
);
31 // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString constructor [loplugin:unnecessarygetstr]}}
33 // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString constructor [loplugin:unnecessarygetstr]}}
34 foo
.f1(true, s
.getStr());
35 // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString constructor [loplugin:unnecessarygetstr]}}
36 foo
.f1(true, OString::boolean(true).getStr());
37 // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString constructor [loplugin:unnecessarygetstr]}}
38 foo
.f1(true, OString::number(12).getStr());
43 = "xx" + OUString(aVal
.getStr(), aVal
.getLength(), RTL_TEXTENCODING_ASCII_US
);
50 // call to param that takes string_view
51 void f2(bool, std::string_view
);
52 void f2(bool, std::u16string_view
);
55 void f2(bool, std::string_view
);
56 void f2(bool, std::u16string_view
);
58 void testOString(Foo2
& foo
)
61 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
63 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
64 foo
.f2(true, s
.getStr());
65 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
66 foo
.f2(true, OString::boolean(true).getStr());
67 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
68 foo
.f2(true, OString::number(12).getStr());
70 void testOUString(Foo2
& foo
)
73 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
75 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
76 foo
.f2(true, s
.getStr());
77 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
78 foo
.f2(true, OUString::boolean(true).getStr());
79 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
80 foo
.f2(true, OUString::number(12).getStr());
86 // call to param that takes string_view
87 void f2(bool, std::string_view
);
90 void f2(bool, std::string_view
);
95 // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
97 // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
98 foo
.f2(true, s
.c_str());
107 // expected-error@+1 {{unnecessary call to 'c_str' when passing to OUString::createFromAscii [loplugin:unnecessarygetstr]}}
108 OUString::createFromAscii(s
.c_str());
114 void test(std::string v
, OString o
)
116 // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
117 std::string_view
s1(v
.c_str());
118 // expected-error@+1 {{unnecessary call to 'getStr' when passing to string constructor [loplugin:unnecessarygetstr]}}
119 std::string
s2(o
.getStr());
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */