Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../proc/self/root/usr/include
File: pcre_stringpiece.h
// Copyright (c) 2005, Google Inc.
[0] Fix | Delete
// All rights reserved.
[1] Fix | Delete
//
[2] Fix | Delete
// Redistribution and use in source and binary forms, with or without
[3] Fix | Delete
// modification, are permitted provided that the following conditions are
[4] Fix | Delete
// met:
[5] Fix | Delete
//
[6] Fix | Delete
// * Redistributions of source code must retain the above copyright
[7] Fix | Delete
// notice, this list of conditions and the following disclaimer.
[8] Fix | Delete
// * Redistributions in binary form must reproduce the above
[9] Fix | Delete
// copyright notice, this list of conditions and the following disclaimer
[10] Fix | Delete
// in the documentation and/or other materials provided with the
[11] Fix | Delete
// distribution.
[12] Fix | Delete
// * Neither the name of Google Inc. nor the names of its
[13] Fix | Delete
// contributors may be used to endorse or promote products derived from
[14] Fix | Delete
// this software without specific prior written permission.
[15] Fix | Delete
//
[16] Fix | Delete
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
[17] Fix | Delete
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
[18] Fix | Delete
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
[19] Fix | Delete
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
[20] Fix | Delete
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
[21] Fix | Delete
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
[22] Fix | Delete
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
[23] Fix | Delete
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[24] Fix | Delete
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
[25] Fix | Delete
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
[26] Fix | Delete
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[27] Fix | Delete
//
[28] Fix | Delete
// Author: Sanjay Ghemawat
[29] Fix | Delete
//
[30] Fix | Delete
// A string like object that points into another piece of memory.
[31] Fix | Delete
// Useful for providing an interface that allows clients to easily
[32] Fix | Delete
// pass in either a "const char*" or a "string".
[33] Fix | Delete
//
[34] Fix | Delete
// Arghh! I wish C++ literals were automatically of type "string".
[35] Fix | Delete
[36] Fix | Delete
#ifndef _PCRE_STRINGPIECE_H
[37] Fix | Delete
#define _PCRE_STRINGPIECE_H
[38] Fix | Delete
[39] Fix | Delete
#include <cstring>
[40] Fix | Delete
#include <string>
[41] Fix | Delete
#include <iosfwd> // for ostream forward-declaration
[42] Fix | Delete
[43] Fix | Delete
#if 0
[44] Fix | Delete
#define HAVE_TYPE_TRAITS
[45] Fix | Delete
#include <type_traits.h>
[46] Fix | Delete
#elif 0
[47] Fix | Delete
#define HAVE_TYPE_TRAITS
[48] Fix | Delete
#include <bits/type_traits.h>
[49] Fix | Delete
#endif
[50] Fix | Delete
[51] Fix | Delete
#include <pcre.h>
[52] Fix | Delete
[53] Fix | Delete
namespace pcrecpp {
[54] Fix | Delete
[55] Fix | Delete
using std::memcmp;
[56] Fix | Delete
using std::strlen;
[57] Fix | Delete
using std::string;
[58] Fix | Delete
[59] Fix | Delete
class PCRECPP_EXP_DEFN StringPiece {
[60] Fix | Delete
private:
[61] Fix | Delete
const char* ptr_;
[62] Fix | Delete
int length_;
[63] Fix | Delete
[64] Fix | Delete
public:
[65] Fix | Delete
// We provide non-explicit singleton constructors so users can pass
[66] Fix | Delete
// in a "const char*" or a "string" wherever a "StringPiece" is
[67] Fix | Delete
// expected.
[68] Fix | Delete
StringPiece()
[69] Fix | Delete
: ptr_(NULL), length_(0) { }
[70] Fix | Delete
StringPiece(const char* str)
[71] Fix | Delete
: ptr_(str), length_(static_cast<int>(strlen(ptr_))) { }
[72] Fix | Delete
StringPiece(const unsigned char* str)
[73] Fix | Delete
: ptr_(reinterpret_cast<const char*>(str)),
[74] Fix | Delete
length_(static_cast<int>(strlen(ptr_))) { }
[75] Fix | Delete
StringPiece(const string& str)
[76] Fix | Delete
: ptr_(str.data()), length_(static_cast<int>(str.size())) { }
[77] Fix | Delete
StringPiece(const char* offset, int len)
[78] Fix | Delete
: ptr_(offset), length_(len) { }
[79] Fix | Delete
[80] Fix | Delete
// data() may return a pointer to a buffer with embedded NULs, and the
[81] Fix | Delete
// returned buffer may or may not be null terminated. Therefore it is
[82] Fix | Delete
// typically a mistake to pass data() to a routine that expects a NUL
[83] Fix | Delete
// terminated string. Use "as_string().c_str()" if you really need to do
[84] Fix | Delete
// this. Or better yet, change your routine so it does not rely on NUL
[85] Fix | Delete
// termination.
[86] Fix | Delete
const char* data() const { return ptr_; }
[87] Fix | Delete
int size() const { return length_; }
[88] Fix | Delete
bool empty() const { return length_ == 0; }
[89] Fix | Delete
[90] Fix | Delete
void clear() { ptr_ = NULL; length_ = 0; }
[91] Fix | Delete
void set(const char* buffer, int len) { ptr_ = buffer; length_ = len; }
[92] Fix | Delete
void set(const char* str) {
[93] Fix | Delete
ptr_ = str;
[94] Fix | Delete
length_ = static_cast<int>(strlen(str));
[95] Fix | Delete
}
[96] Fix | Delete
void set(const void* buffer, int len) {
[97] Fix | Delete
ptr_ = reinterpret_cast<const char*>(buffer);
[98] Fix | Delete
length_ = len;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
char operator[](int i) const { return ptr_[i]; }
[102] Fix | Delete
[103] Fix | Delete
void remove_prefix(int n) {
[104] Fix | Delete
ptr_ += n;
[105] Fix | Delete
length_ -= n;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
void remove_suffix(int n) {
[109] Fix | Delete
length_ -= n;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
bool operator==(const StringPiece& x) const {
[113] Fix | Delete
return ((length_ == x.length_) &&
[114] Fix | Delete
(memcmp(ptr_, x.ptr_, length_) == 0));
[115] Fix | Delete
}
[116] Fix | Delete
bool operator!=(const StringPiece& x) const {
[117] Fix | Delete
return !(*this == x);
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
#define STRINGPIECE_BINARY_PREDICATE(cmp,auxcmp) \
[121] Fix | Delete
bool operator cmp (const StringPiece& x) const { \
[122] Fix | Delete
int r = memcmp(ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_); \
[123] Fix | Delete
return ((r auxcmp 0) || ((r == 0) && (length_ cmp x.length_))); \
[124] Fix | Delete
}
[125] Fix | Delete
STRINGPIECE_BINARY_PREDICATE(<, <);
[126] Fix | Delete
STRINGPIECE_BINARY_PREDICATE(<=, <);
[127] Fix | Delete
STRINGPIECE_BINARY_PREDICATE(>=, >);
[128] Fix | Delete
STRINGPIECE_BINARY_PREDICATE(>, >);
[129] Fix | Delete
#undef STRINGPIECE_BINARY_PREDICATE
[130] Fix | Delete
[131] Fix | Delete
int compare(const StringPiece& x) const {
[132] Fix | Delete
int r = memcmp(ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_);
[133] Fix | Delete
if (r == 0) {
[134] Fix | Delete
if (length_ < x.length_) r = -1;
[135] Fix | Delete
else if (length_ > x.length_) r = +1;
[136] Fix | Delete
}
[137] Fix | Delete
return r;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
string as_string() const {
[141] Fix | Delete
return string(data(), size());
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
void CopyToString(string* target) const {
[145] Fix | Delete
target->assign(ptr_, length_);
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
// Does "this" start with "x"
[149] Fix | Delete
bool starts_with(const StringPiece& x) const {
[150] Fix | Delete
return ((length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0));
[151] Fix | Delete
}
[152] Fix | Delete
};
[153] Fix | Delete
[154] Fix | Delete
} // namespace pcrecpp
[155] Fix | Delete
[156] Fix | Delete
// ------------------------------------------------------------------
[157] Fix | Delete
// Functions used to create STL containers that use StringPiece
[158] Fix | Delete
// Remember that a StringPiece's lifetime had better be less than
[159] Fix | Delete
// that of the underlying string or char*. If it is not, then you
[160] Fix | Delete
// cannot safely store a StringPiece into an STL container
[161] Fix | Delete
// ------------------------------------------------------------------
[162] Fix | Delete
[163] Fix | Delete
#ifdef HAVE_TYPE_TRAITS
[164] Fix | Delete
// This makes vector<StringPiece> really fast for some STL implementations
[165] Fix | Delete
template<> struct __type_traits<pcrecpp::StringPiece> {
[166] Fix | Delete
typedef __true_type has_trivial_default_constructor;
[167] Fix | Delete
typedef __true_type has_trivial_copy_constructor;
[168] Fix | Delete
typedef __true_type has_trivial_assignment_operator;
[169] Fix | Delete
typedef __true_type has_trivial_destructor;
[170] Fix | Delete
typedef __true_type is_POD_type;
[171] Fix | Delete
};
[172] Fix | Delete
#endif
[173] Fix | Delete
[174] Fix | Delete
// allow StringPiece to be logged
[175] Fix | Delete
PCRECPP_EXP_DECL std::ostream& operator<<(std::ostream& o,
[176] Fix | Delete
const pcrecpp::StringPiece& piece);
[177] Fix | Delete
[178] Fix | Delete
#endif /* _PCRE_STRINGPIECE_H */
[179] Fix | Delete
[180] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function