1// Copyright 2014 The Android Open Source Project
2//
3// This software is licensed under the terms of the GNU General Public
4// License version 2, as published by the Free Software Foundation, and
5// may be copied, distributed, and modified under those terms.
6//
7// This program is distributed in the hope that it will be useful,
8// but WITHOUT ANY WARRANTY; without even the implied warranty of
9// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10// GNU General Public License for more details.
11
12#include "android/base/StringView.h"
13
14#include <algorithm>
15
16namespace android {
17namespace base {
18
19int StringView::compare(const StringView& other) const {
20    size_t minSize = std::min(mSize, other.size());
21    if (!minSize) return true;
22    int ret = memcmp(mString, other.str(), minSize);
23    if (ret) return ret;
24    if (mSize < other.size()) return -1;
25    if (mSize > other.size()) return +1;
26    return 0;
27}
28
29bool operator==(const StringView& x, const StringView& y) {
30    if (x.size() != y.size()) return false;
31    return !memcmp(x.str(), y.str(), x.size());
32}
33
34}  // namespace base
35}  // namespace android
36