15 #ifndef NINJA_STRINGPIECE_H_
16 #define NINJA_STRINGPIECE_H_
31 StringPiece(
const string& str) : str_(str.data()), len_(str.size()) {}
32 StringPiece(
const char* str) : str_(str), len_(strlen(str)) {}
34 StringPiece(
const char* str,
size_t len) : str_(str), len_(len) {}
37 return len_ == other.
len_ && memcmp(str_, other.
str_, len_) == 0;
40 return !(*
this == other);
46 return len_ ? string(str_, len_) : string();
53 #endif // NINJA_STRINGPIECE_H_
bool operator==(const StringPiece &other) const
StringPiece represents a slice of a string whose memory is managed externally.
bool operator!=(const StringPiece &other) const
StringPiece(const string &str)
The constructors intentionally allow for implicit conversions.
string AsString() const
Convert the slice into a full-fledged std::string, copying the data into a new string.
StringPiece(const char *str)
StringPiece(const char *str, size_t len)