LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
string_view_util.cc
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Apache Software Foundation 2019
7
9
10int
11memcmp(std::string_view const &lhs, std::string_view const &rhs) {
12 int zret = 0;
13 size_t n = rhs.size();
14
15 // Seems a bit ugly but size comparisons must be done anyway to get the memcmp args.
16 if (lhs.size() < rhs.size()) {
17 zret = 1;
18 n = lhs.size();
19 } else if (lhs.size() > rhs.size()) {
20 zret = -1;
21 } else if (lhs.data() == rhs.data()) { // same memory, obviously equal.
22 return 0;
23 }
24
25 int r = ::memcmp(lhs.data(), rhs.data(), n);
26 return r ? r : zret;
27}
28
29int
30strcasecmp(const std::string_view &lhs, const std::string_view &rhs) {
31 int zret = 0;
32 size_t n = rhs.size();
33
34 // Seems a bit ugly but size comparisons must be done anyway to get the @c strncasecmp args.
35 if (lhs.size() < rhs.size()) {
36 zret = 1;
37 n = lhs.size();
38 } else if (lhs.size() > rhs.size()) {
39 zret = -1;
40 } else if (lhs.data() == rhs.data()) { // the same memory, obviously equal.
41 return 0;
42 }
43
44 int r = ::strncasecmp(lhs.data(), rhs.data(), n);
45
46 return r ? r : zret;
47}
int strcasecmp(const std::string_view &lhs, const std::string_view &rhs)
int memcmp(std::string_view const &lhs, std::string_view const &rhs)