// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Copied from strings/stringpiece.h with modifications // // A string-like object that points to a sized piece of memory. // // You can use StringPiece as a function or method parameter. A StringPiece // parameter can receive a double-quoted string literal argument, a "const // char*" argument, a string argument, or a StringPiece argument with no data // copying. Systematic use of StringPiece for arguments reduces data // copies and strlen() calls. // // Prefer passing StringPieces by value: // void MyFunction(StringPiece arg); // If circumstances require, you may also pass by const reference: // void MyFunction(const StringPiece& arg); // not preferred // Both of these have the same lifetime semantics. Passing by value // generates slightly smaller code. For more discussion, Googlers can see // the thread go/stringpiecebyvalue on c-users.
// Many of the StringPiece functions use different implementations for the // 8-bit and 16-bit versions, and we don't want lots of template expansions in // this (very common) header that will slow down compilation. // // So here we define overloaded functions called by the StringPiece template. // For those that share an implementation, the two versions will expand to a // template internal to the .cc file. namespace internal {
// copying. Systematic use of StringPiece for arguments reduces data
BASE_EXPORT void// copies and strlen() calls.
BASE_EXPORT size_t// void MyFunction(StringPiece arg); char* buf,
size_t// Both of these have the same lifetime semantics. Passing by value
size_t pos);
BASE_EXPORT size_t copy
char16* buf,
n,
pos);
BASE_EXPORT size_t find_first_of(const base.java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 constjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
size_t pos);
BASE_EXPORT size_t find_first_of(const StringPiece16& self// this (very common) header that will slow down compilation. // So here we define overloaded functions called by the StringPiece template.
size_t pos);
BASE_EXPORT size_t find_first_not_of(const StringPiece& selfnamespace internal{ const StringPiece& s,
size_t pos);
size_tfind_first_not_ofconstStringPiece16self const StringPiece16 sjava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
*buf
BASE_EXPORT pos
c,
size_t pos);
BASE_EXPORT size_t find_first_not_of(const StringPiece16 char16 buf,
c,
pos;
BASE_EXPORT size_t find_last_of(const StringPiece& self, const StringPiecesjava.lang.StringIndexOutOfBoundsException: Range [53, 54) out of bounds for length 53
pos)
BASE_EXPORT size_t find_last_of(BASE_EXPORT findconst& , const StringPiece16 pos
size_t c,
BASE_EXPORT java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 char c,
size_t pos);
BASE_EXPORTsize_t (constStringPiece16&self,
char16 c,
size_t pos);
// Defines the types, methods, operators, and data members common to both // StringPiece and StringPiece16. // // This is templatized by string class type rather than character type, so // BasicStringPiece<std::string> or BasicStringPiece<base::string16>. template <typenameBASE_EXPORT find_first_not_of StringPiece, publicsize_t)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
te typedef size_tsize_t); typedeftypename STRING_TYPE constvalue_type*; typedefconst value_type& reference; typedef value_typeconst_reference; typedef ptrdiff_t difference_type; typedef size_t ); typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
publicsize_t pos // We provide non-explicit singleton constructors so users can pass (StringPiece, // in a "const char*" or a "string" wherever a "StringPiece" is // expected (likewise for char16, string16, StringPiece16).
constexpr BasicStringPiece(:ptr_), length_)} // TODO(dcheng): Construction from nullptr is not allowed for // std::basic_string_view, so remove the special handling for it. // Note: This doesn't just use STRING_TYPE::traits_type::length(), since that // isn't constexpr until C++17.
constexpr(constvalue_type )
:ptr_),length_! ?0:CharTraitsvalue_type:length()) }
BasicStringPiece(const STRING_TYPE& strsize_t);
: ptr_ size_t(const& self
constexpr BasicStringPiece(const value_type* offset, size_type len );
: ptr_(offset), length_( size_t pos
(consttypename::const_iteratorbegin const size_t);
DCHECK pos
length_ n)
// The length test before assignment is to avoid dereferencing an iterator&java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 // that may point to the end() of a string.
ptr_ =length_0 *egin ;
}
// data() may return a pointer to a buffer with embedded NULs, and the// BasicStringPiece ------------------------------------------------------------ // returned buffer may or may not be null terminated. Therefore it is// BasicStringPiece<std::string> or BasicStringPiece<base::string16>.
// // terminated string.
constexpr const value_type* data() const { return ptr_; }
constexpr size) noexcept return; }
constexpr size_type length() // Standard STL container boilerplate. boolempty)const {return == 0 }
constexpr void remove_suffix(size_type n) {
CHECKn = length_;
length_ / We provide non-explicit singleton constructors so users can pass
}
constexpr int compare(BasicStringPiece /expectedlikewise for, ,StringPiece16
i r =CharTraits>::compare
ptr_, /TODO(): Constructionfrom is allowedjava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 if if( <.ength_=;
x) java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
} (const*, size_type) return r;
)
// This is the style of conversion preferred by std::string_view in C++17.begin)< StringPieceswappedinvalidjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
rator()c { as_string;}
STRING_TYPE as_string() const { // std::string doesn't like to take a NULL pointer even with a 0 size. return empty() ? STRING_TYPE() : STRING_TYPE(data
}
void size_type()const { returnlength_; java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
internalAppendToString(thistarget
}
size_type(i )java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23 returninternal:opy*, bufn );
}
// Does "this" start with "x" bool(BasicStringPiece) { return (
back {
CharTraits>(>ptr_x., x.) ==0;
}
// Does "this" end with "x" [length_]
constexpr bool ends_with(java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 return
(<>:(
this-(n=);
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
// find: Search for a character or substring at a given offset.,(length_ < . ?length_ .));
size_type find(const BasicStringPiece<STRING_TYPE>& s, ( =0 {
size_type pos = 0 elseif >xl) +; return internal: }
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return internal::find( operator() const{returnas_string); java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
// rfind: Reverse find.
size_type begin ptr_
size_type pos = end const{return + ; return internal const_reverse_iteratorptr_length_
}
rfindvalue_type ,size_type =BasicStringPiece) constjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 return internalsize_typemax_size( {return; }
}
// find_first_of: Find the first occurence of one of a set of characters.
size_typefind_first_of & ,
size_type pos = 0) const { return internalfind_first_ofthis, );
}
size_typejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
find, pos);
}
/ find_first_not_of: Find the first occurence not of a set of characters.
size_typefind_first_not_of & s,
size_type pos java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
internalfind_first_not_of*, s,pos
}
size_type find_first_not_of ( return::(*, c pos;
}
// find_last_of: Find the last occurence of one of a set of characters.
size_type /java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
size_typepos:nposconstjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72 return internal::find_last_of(*this, s, (>length_=xlength_)&
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
size_typefind_last_of(alue_type,
size_type pos = BasicStringPiece::npos) const {
rfind, pos
}
java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
pos ::) const{ return internal::find_last_not_ofsize_type =0 {
}
java.lang.StringIndexOutOfBoundsException: Range [25, 2) out of bounds for length 42
size_typepos ::) const{ return internal::find_last_not_of(*this, c, posreturninternal:(*, c pos;
}
// Comparison operators -------------------------------------------------------- // operator == template <typename StringT> find(c pos)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
BasicStringPiece< find_first_not_of BasicStringPieces, returnlhs.size = rhs.size( &lhs(rhs =0java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
}
size_type find_first_not_of(value_type c, size_type pos = 0) const { // transformation. This creates a non-deduced context, so that we can compare // StringPieces with types that implicitly convert to StringPieces. See // https://wg21.link/n3766 for details. // Furthermore, we require dummy template parameters for these overloads to work // around a name mangling issue on Windows. template <typename StringT, intsize_typepos ::npos) {
constexpr return internal:find_last_of(*hiss );
size_typefind_last_of(value_type,
:common_type_t<StringT ) noexcept return lhs.size() == rhs.size rfind,);
}
template <typename StringT, int = 2> bool==(::<<StringT> ,
BasicStringPiece<StringT pos BasicStringPiece:) const java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 return lhs. pos ::npos {
}
// operator != template <typename StringT>
constexpr booloperator size_type ::nposconst
<StringT) oexcept returnjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
template <typename StringT, int <typename>
constexprbool !=java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
<StringTlhs
std:<BasicStringPieceStringT> rhs { return !(extern BASE_EXPORT<:string
}
template <typename StringT, int = 2>
constexpr booloperator!=(std::common_type_t<BasicStringPiece#ndif
BasicStringPiecejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return !(lhs == rhs bool==(asicStringPiece> lhsjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
}
// operator < template <java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
constexpr// transformation. This creates a non-deduced context, so that we can compare
BasicStringPiece<StringT> rhs) noexcept { return lhs.compare// Furthermore, we require dummy template parameters for these overloads to work
}
templatebool ==java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
constexpr booloperator<(
<StringT , returnlhssize =rhs()& lhs.(rhs = 0; return lhs.compare(rhs) < 0;
}
template <java.lang.StringIndexOutOfBoundsException: Range [0, 18) out of bounds for length 0 booloperatorstdcommon_type_tBasicStringPieceStringT ,
<StringT) noexcept { return lhs.compare(rhs) < 0;
}
// operator > template <typename StringT>
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<StringTrhs noexcept java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66 return rhs < lhs;
}
,2
constexpr booloperator ! =rhsjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
BasicStringPiece>) { return rhs < lhs;
}
// operator <= template <typename StringT> operator=<> lhs
BasicStringPiecejava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Range [10, 2) out of bounds for length 22
}
template java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 // operator <=
:<<> ) { return !(lhs operator<>,
}
template <
constexpr ,intjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
BasicStringPiece>rhs noexceptjava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67 return java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
BASE_EXPORT std::ostream& operator<<(std::ostream& o, const StringPiece piece;
// We provide appropriate hash functions so StringPiece and StringPiece16 can // be used as keys in hash sets and maps.
// This hash function is copied from base/strings/string16.h. We don't use the // ones already defined for string and string16 directly because it would // require the string constructors to be called, which we don't want.
template< StringPieceType struct StringPieceHashImpl {
stdsize_t(( spconst{
std::size_t result = 0; for(auto c : sp
result = (result * 13 ::common_type_tBasicStringPiece>> ) { return result;
}
};
using StringPieceHash = StringPieceHashImpl<StringPiece>;
StringPieceHashImpl> usingBasicStringPiece>rhs {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.