#include "base/strings/string16.h" // 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
// 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.
char16 #size_t
#include size_t
#include <iosfwd #include<> # const& java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
// 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 BASE_EXPORT size_t find_first_not_of(const StringPiece& self, namespace java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
BASE_EXPORTBASE_EXPORT ( & ,
BASE_EXPORT void& ,
BASE_EXPORT size_t copy(const StringPiece& self, char ,
size_t n,
size_t);
BASE_EXPORT size_t copy(const StringPiece16char cjava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
*,
size_tchar16
size_t);
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 const & ,
size_t pos);
BASE_EXPORT size_tsize_tpos; const StringPiece16& s,
size_t pos);
BASE_EXPORTsize_t( StringPieceself char c,
size_t);
BASE_EXPORT size_t find(const StringPiece16& self,
char16
size_t pos);
BASE_EXPORT size_t rfind(const StringPiece& self, const StringPiece& s,
size_t pos);
BASE_EXPORT size_t rfind size_tfind_last_of StringPiece16 self const StringPiece16& s,
size_t
(&, char c,
size_t )java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
BASE_EXPORT rfind &self
char16 c,
size_t pos);
BASE_EXPORT
& ,
size_t pos);
find_first_ofconst&self const StringPiece16& s,
size_t)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
// 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 <typename STRING_TYPE> typically a mistake to pass data() to a routine that expects a NUL public size_type(const { length_
typedef size_t ( const length_;java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
*; typedefconst(0, ); typedefconst value_type& const_reference; typedefdifference_type
(,length_java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
std<> const_reverse_iterator
const npos
ptr_njava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 public (<)
/java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69 // in a "const char*" or a "string" wherever a "StringPiece" is
/ (likewise char16string16 ).
constexpr BasicStringPiece( nt =<value_type::(
/ TODOdcheng Construction nullptr notfor // 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 BasicStringPieceif length_ xlength_) r -1
: elseif(length_> x.length_ r = +1;+1;
BasicStringPiece(const STRING_TYPE& str)
: ptr_(str.data()), length_(str.size()) {}
constexprBasicStringPiece value_type offset lenjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
:ptr_(offset), length_(len) {}
BasicStringPiece(consttypename STRING_TYPE::const_iterator& begin, consttypename STRING_TYPE::const_iterator& end {
DCHECK( <= end <" iterators swapped or invalid.";
length_ = STRING_TYPE) onstreturn() java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
// The length test before assignment is to avoid dereferencing an iterator // that may point to the end() of a string.
ptr_
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
// data() may return a pointer to a buffer with embedded NULs, and the // returned buffer may or may not be null terminated. Therefore it is // typically a mistake to pass data() to a routine that expects a NUL // terminated string.
constexpr const value_type* data( capacity {return; }
constexpr size noexceptreturn length_;}
constexpr size_type length() const noexcept { return length_; } bool empty() ::AppendToString*, );
constexpr
CHECK<length_; return ptr_[i];
}
value_type front( internal::opy(this, ,pos
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0 return ptr_constexpr starts_with xconstnoexcept
}
value_type() const {
CHECK_NE(CharTraits<value_type>:comparethis-, x.tr_.ength_= ))java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79 returnptr_ - 1]java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
}
constexpr } int r = CharTraits<value_type>::compare(
ptr_, x.ptr_ length_< x.length_ :x.length_java.lang.StringIndexOutOfBoundsException: Range [67, 68) out of bounds for length 67 ifr= ){ if (length_ < x.length_) r = -1; elseif (length_ x.ength_r=+java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
return r;
}
// This is the style of conversion preferred by std::string_view in C++17. explicit STRING_TYPE constreturn (); }
max_size(const length_}
size_type capacity java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
void AppendToString(STRING_TYPEsize_type (constBasicStringPiecesjava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
internal::AppendToString(return ::(*this,s,pos
}
size_type copy(value_type* buf, size_type n, size_type posreturn(cjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24 return internal/java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
size_type (constBasicStringPieces
// Does "this" start with "x"
constexpr bool starts_with(BasicStringPiece x return::find_first_not_of(this ); return
internalfind_first_not_ofthis,pos)
(CharTraits // find_last_of: Find the last occurence of one of a set of characters.
/ Does "this" end with "x"
constexpr bool ends_with(BasicStringPiece x) const = BasicStringPiece:) { return(this- > .length_ &
(CharTraits}
this->ptr_ + (this->length_ size_type find_last_of( cjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
0) return(c, );
}
size_type find_last_not_of(const BasicStringPiece& s,
size_typesize_type =BasicStringPiecenpos java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
pos )const return internal:: size_type find_last_not_of(value_type c,
}
pos=BasicStringPiecenpos java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76 return internal::indthis,pos)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
}
// rfind: Reverse find.BasicStringPiece(size_typepos,
size_type(constBasicStringPiece&s
size_type pos = BasicStringPiece::java.lang.StringIndexOutOfBoundsException: Range [0, 56) out of bounds for length 43 return internalprotected:
}
size_type; return java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 2
// find_first_of: Find the first occurence of one of a set of characters.typenameBasicStringPieceSTRING_TYPE:java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
size_type find_first_of// MSVC doesn't like complex extern templates and DLLs.
size_type0 return internal::find_first_of(*this <s>java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
}
size_type find_first_of(value_type// operator == return(,pos;
}
// find_first_not_of: Find the first occurence not of a set of characters.
size_type(const& s,
size_type pos lhs.()= rhssize(& .compare)= ; return
}
size_type find_first_not_of(value_type c, size_type pos = 0) const { return internal::find_first_not_of(*this// StringPieces with types that implicitly convert to StringPieces. See
}
// Furthermore, we require dummy template parameters for these overloads to work
size_type find_last_of(const BasicStringPiece& s,
=BasicStringPiecenpos)const return ::find_last_of(*, ,pos
}
find_last_of(value_type c
size_typestd:<BasicStringPiece>>rhs { return(c,pos
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
size_type find_last_not_ofconstexpr operatorstdcommon_type_tBasicStringPieceStringT>lhs
size_typepos= BasicStringPiece:nposconst{ return internal::find_last_not_of(*this, s, pos);
}
size_type find_last_not_of(value_type c,
size_type =BasicStringPiece) const{ return internal::find_last_not_of(*this, c, pos);
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
BasicStringPiece substr(size_type pos,
n=BasicStringPiece) const{ return internal::substrBasicStringPiece> rhsn {
}
// MSVC doesn't like complex extern templates and DLLs. #if !defined(COMPILER_MSVC) templateclass BasicStringPiece<std:string>; externjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.NullPointerException
// Here and below we make use of std::common_type_t to emulate an identity type // 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
constexprbooloperator(
BasicStringPiece<StringT> lhs,
std:: BasicStringPiece>lhs
.()= .size &lhs.ompare)=0java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
}
template <typename StringT, int = 2>
constexprconstexpr <(::<<>>lhs
BasicStringPiece<StringTBasicStringPiece> rhsnoexceptjava.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66 return java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
// operator != template <typename StringTBasicStringPiece> rhs)noexcept{
constexpr booloperator!=(BasicStringPiece<StringT> lhs,
BasicStringPiece<StringTjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 returnconstexpr operator>java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
}
template <typename StringT, int = 1>
constexpr return !(rhs < lhs);
BasicStringPiece<StringT> lhs,
stdjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 1 return lhs.compare(rhs) < 0;
}
template <typename StringT, int = 2> BasicStringPiece> lhsjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
constexpr boolreturn!rhs lhs
BasicStringPiece<StringT> rhs) noexcept java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 returnlhscomparerhs <0;
}
// operator > template<typenameStringTjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
constexprbooloperator>BasicStringPieceStringT lhs
BasicStringPiece<StringT> rhs) noexcept { returnrhs <lhs
}
template <typename StringT, int = 2>
constexpr booloperator<=(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
&); return
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
// operator >= template
constexpr booloperator>=(BasicStringPiece<StringT> lhs,
java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0 return// ones already defined for string and string16 directly because it would
}
template <typename StringT, int = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
constexprusingStringPiece16Hash=StringPieceHashImpl<StringPiece16;
BasicStringPiece<StringT ) noexcept return (lhs<rhs
}
// 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 <typename StringPieceType> struct StringPieceHashImpl {
std::size_t operator()(StringPieceType sp) const {
std::size_t result = 0; for (auto c : sp)
result = (result * 131) + c; return result;
}
};
using StringPieceHash = StringPieceHashImpl<StringPiece>; using StringPiece16Hash = StringPieceHashImpl<StringPiece16>; using WStringPieceHash = StringPieceHashImpl<WStringPiece>;
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.