Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Unified Diff: net/der/input.cc

Issue 1573243011: Refactor der::Input helper methods into new constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add documentation Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/der/input.cc
diff --git a/net/der/input.cc b/net/der/input.cc
index 5065ccaca93e9bdc3ffc06b5af2eaa332d57f1ae..d81d32dd35d274f8263581780a0c624485cf1acc 100644
--- a/net/der/input.cc
+++ b/net/der/input.cc
@@ -19,6 +19,12 @@ Input::Input() : data_(nullptr), len_(0) {
Input::Input(const uint8_t* data, size_t len) : data_(data), len_(len) {
}
+Input::Input(const base::StringPiece& in)
+ : data_(reinterpret_cast<const uint8_t*>(in.data())), len_(in.length()) {}
+
+Input::Input(const std::string* s)
+ : data_(reinterpret_cast<const uint8_t*>(s->data())), len_(s->size()) {}
eroman 2016/01/13 22:54:00 Could also delegate to stringpiece ctor : Input
nharper 2016/01/13 23:04:47 That looks a little cleaner. Done.
+
bool Input::Equals(const Input& other) const {
if (len_ != other.len_)
return false;
@@ -29,6 +35,10 @@ std::string Input::AsString() const {
return std::string(reinterpret_cast<const char*>(data_), len_);
}
+base::StringPiece Input::AsStringPiece() const {
+ return base::StringPiece(reinterpret_cast<const char*>(data_), len_);
+}
+
bool operator<(const Input& lhs, const Input& rhs) {
return std::lexicographical_compare(
lhs.UnsafeData(), lhs.UnsafeData() + lhs.Length(), rhs.UnsafeData(),

Powered by Google App Engine
This is Rietveld 408576698