| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_ | |
| 6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "base/strings/string_piece.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 class LevelDBSlice { | |
| 17 public: | |
| 18 LevelDBSlice(const char* begin, const char* end) : begin_(begin), end_(end) { | |
| 19 DCHECK_GE(end_, begin_); | |
| 20 } | |
| 21 | |
| 22 explicit LevelDBSlice(const std::vector<char>& v) | |
| 23 : begin_(v.empty() ? NULL : &*v.begin()), end_(begin_ + v.size()) { | |
| 24 DCHECK_GE(end_, begin_); | |
| 25 } | |
| 26 | |
| 27 explicit LevelDBSlice(const std::string& v) | |
| 28 : begin_(v.data()), end_(v.data() + v.size()) { | |
| 29 DCHECK_GE(end_, begin_); | |
| 30 } | |
| 31 | |
| 32 ~LevelDBSlice() {} | |
| 33 | |
| 34 const char* begin() const { return begin_; } | |
| 35 const char* end() const { return end_; } | |
| 36 | |
| 37 base::StringPiece AsStringPiece() const { | |
| 38 return base::StringPiece(begin_, end_ - begin_); | |
| 39 } | |
| 40 | |
| 41 private: | |
| 42 const char* begin_; | |
| 43 const char* end_; | |
| 44 }; | |
| 45 | |
| 46 } // namespace content | |
| 47 | |
| 48 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_SLICE_H_ | |
| OLD | NEW |