1 /*
2 * Copyright 2021 Google LLC.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "include/core/SkStringView.h"
8
9 #include <algorithm>
10
11 namespace skstd {
12
operator ==(string_view left,string_view right)13 bool operator==(string_view left, string_view right) {
14 if (left.length() != right.length()) {
15 return false;
16 }
17 return !string_view::traits_type::compare(left.data(), right.data(), left.length());
18 }
19
operator !=(string_view left,string_view right)20 bool operator!=(string_view left, string_view right) {
21 return !(left == right);
22 }
23
operator <(string_view left,string_view right)24 bool operator<(string_view left, string_view right) {
25 int result = string_view::traits_type::compare(left.data(), right.data(),
26 std::min(left.length(), right.length()));
27 if (!result) {
28 result = left.length() - right.length();
29 }
30 return result < 0;
31 }
32
operator <=(string_view left,string_view right)33 bool operator<=(string_view left, string_view right) {
34 return !(left > right);
35 }
36
operator >(string_view left,string_view right)37 bool operator>(string_view left, string_view right) {
38 return right < left;
39 }
40
operator >=(string_view left,string_view right)41 bool operator>=(string_view left, string_view right) {
42 return !(left < right);
43 }
44
45 } // namespace skstd
46