aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/util/string_ref.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpp/util/string_ref.cc')
-rw-r--r--src/cpp/util/string_ref.cc66
1 files changed, 1 insertions, 65 deletions
diff --git a/src/cpp/util/string_ref.cc b/src/cpp/util/string_ref.cc
index 66c79a1818..b55019b5f2 100644
--- a/src/cpp/util/string_ref.cc
+++ b/src/cpp/util/string_ref.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,72 +33,8 @@
#include <grpc++/support/string_ref.h>
-#include <string.h>
-
-#include <algorithm>
-#include <iostream>
-
namespace grpc {
const size_t string_ref::npos = size_t(-1);
-string_ref& string_ref::operator=(const string_ref& rhs) {
- data_ = rhs.data_;
- length_ = rhs.length_;
- return *this;
-}
-
-string_ref::string_ref(const char* s) : data_(s), length_(strlen(s)) {}
-
-string_ref string_ref::substr(size_t pos, size_t n) const {
- if (pos > length_) pos = length_;
- if (n > (length_ - pos)) n = length_ - pos;
- return string_ref(data_ + pos, n);
-}
-
-int string_ref::compare(string_ref x) const {
- size_t min_size = length_ < x.length_ ? length_ : x.length_;
- int r = memcmp(data_, x.data_, min_size);
- if (r < 0) return -1;
- if (r > 0) return 1;
- if (length_ < x.length_) return -1;
- if (length_ > x.length_) return 1;
- return 0;
-}
-
-bool string_ref::starts_with(string_ref x) const {
- return length_ >= x.length_ && (memcmp(data_, x.data_, x.length_) == 0);
-}
-
-bool string_ref::ends_with(string_ref x) const {
- return length_ >= x.length_ &&
- (memcmp(data_ + (length_ - x.length_), x.data_, x.length_) == 0);
-}
-
-size_t string_ref::find(string_ref s) const {
- auto it = std::search(cbegin(), cend(), s.cbegin(), s.cend());
- return it == cend() ? npos : std::distance(cbegin(), it);
-}
-
-size_t string_ref::find(char c) const {
- auto it = std::find(cbegin(), cend(), c);
- return it == cend() ? npos : std::distance(cbegin(), it);
-}
-
-bool operator==(string_ref x, string_ref y) { return x.compare(y) == 0; }
-
-bool operator!=(string_ref x, string_ref y) { return x.compare(y) != 0; }
-
-bool operator<(string_ref x, string_ref y) { return x.compare(y) < 0; }
-
-bool operator<=(string_ref x, string_ref y) { return x.compare(y) <= 0; }
-
-bool operator>(string_ref x, string_ref y) { return x.compare(y) > 0; }
-
-bool operator>=(string_ref x, string_ref y) { return x.compare(y) >= 0; }
-
-std::ostream& operator<<(std::ostream& out, const string_ref& string) {
- return out << grpc::string(string.begin(), string.end());
-}
-
} // namespace grpc