11#if RESIP_HAVE_STRING_VIEW
21#ifndef RESIP_DATA_LOCAL_SIZE
22#define RESIP_DATA_LOCAL_SIZE 16
99 mCapacity(LocalAlloc),
131#ifdef DEPRECATED_PREALLOC
185#if RESIP_HAVE_STRING_VIEW
189 Data(
const std::string_view
sv);
216#ifndef RESIP_FIXED_POINT
235 explicit Data(
double value,
243 explicit Data(
bool value);
249 explicit Data(
char c);
318 if (mShareEnum ==
Take)
411#if RESIP_HAVE_STRING_VIEW
420#if RESIP_HAVE_STRING_VIEW
434 operator std::string()
const
458#if RESIP_HAVE_STRING_VIEW
460 operator std::string_view()
const
462 return std::string_view(
c_str(),
size());
625 const char*
c_str()
const;
632#if RESIP_HAVE_STRING_VIEW
818#ifndef RESIP_FIXED_POINT
917 static size_t rawHash(
const unsigned char*
c,
size_t size);
1055 inline void initFromString(
const char*
str,
size_type len);
1068 static bool isHex(
unsigned char c);
1078 char mPreBuffer[LocalAlloc];
1087#ifndef RESIP_USE_STL_STREAMS
1094 friend class ::TestData;
1108inline bool Data::isHex(
unsigned char c)
1118 return ( (left.
size() == right.
size()) &&
1119 (strncasecmp(left.
data(), right.
data(), left.
size()) == 0) );
1130 int res = strncasecmp(left.
data(), right.
data(), minsize);
1149 constexpr char hex[] =
"0123456789ABCDEF";
1156 const unsigned char* p = (
unsigned char*)mBuf;
1157 const unsigned char* e = (
unsigned char*)mBuf + mSize;
1168 str.write((
char*)p, 3);
1171 else if (shouldEscape[*p])
1173 int hi = (*p & 0xF0)>>4;
1174 int low = (*p & 0x0F);
1176 str <<
'%' <<
hex[hi] <<
hex[low];
1203inline bool operator!=(
const Data& lhs,
const std::string& rhs)
noexcept {
return !(lhs == rhs); }
1204inline bool operator>(
const Data& lhs,
const std::string& rhs) {
return rhs < lhs; }
1205inline bool operator<=(
const Data& lhs,
const std::string& rhs) {
return !(rhs < lhs); }
1206inline bool operator>=(
const Data& lhs,
const std::string& rhs) {
return !(lhs < rhs); }
1208inline bool operator==(
const std::string& lhs,
const Data& rhs)
noexcept {
return rhs == lhs; }
1209inline bool operator!=(
const std::string& lhs,
const Data& rhs)
noexcept {
return !(rhs == lhs); }
1210inline bool operator>(
const std::string& lhs,
const Data& rhs) {
return rhs < lhs; }
1211inline bool operator<=(
const std::string& lhs,
const Data& rhs) {
return !(rhs < lhs); }
1212inline bool operator>=(
const std::string& lhs,
const Data& rhs) {
return !(lhs < rhs); }
1214#if RESIP_HAVE_STRING_VIEW
1215inline bool operator!=(
const Data& lhs,
const std::string_view rhs)
noexcept {
return !(lhs == rhs); }
1216inline bool operator>(
const Data& lhs,
const std::string_view rhs) {
return rhs < lhs; }
1217inline bool operator<=(
const Data& lhs,
const std::string_view rhs) {
return !(rhs < lhs); }
1218inline bool operator>=(
const Data& lhs,
const std::string_view rhs) {
return !(lhs < rhs); }
1220inline bool operator==(
const std::string_view lhs,
const Data& rhs)
noexcept {
return rhs == lhs; }
1221inline bool operator!=(
const std::string_view lhs,
const Data& rhs)
noexcept {
return !(rhs == lhs); }
1222inline bool operator>(
const std::string_view lhs,
const Data& rhs) {
return rhs < lhs; }
1223inline bool operator<=(
const std::string_view lhs,
const Data& rhs) {
return !(rhs < lhs); }
1224inline bool operator>=(
const std::string_view lhs,
const Data& rhs) {
return !(lhs < rhs); }
1227#ifndef RESIP_USE_STL_STREAMS
1232 return strm.write(d.mBuf, d.mSize);
1242bool operator==(
const Data& lhs,
const Data& rhs);
1243bool operator==(
const Data& lhs,
const char* rhs);
1244bool operator==(
const Data& lhs,
const std::string& rhs)
noexcept;
1245#if RESIP_HAVE_STRING_VIEW
1246bool operator==(
const Data& lhs,
const std::string_view rhs)
noexcept;
1249bool operator<(
const Data& lhs,
const Data& rhs);
1250bool operator<(
const Data& lhs,
const char* rhs);
1251bool operator<(
const char* lhs,
const Data& rhs);
1252bool operator<(
const Data& lhs,
const std::string& rhs)
noexcept;
1253bool operator<(
const std::string& lhs,
const Data& rhs)
noexcept;
1254#if RESIP_HAVE_STRING_VIEW
1255bool operator<(
const Data& lhs,
const std::string_view rhs)
noexcept;
1256bool operator<(
const std::string_view lhs,
const Data& rhs)
noexcept;
1298 return seed ^ (hash + (size_t)0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2));
#define RESIP_DATA_LOCAL_SIZE
Wraps your platform's implementation of hash_map, hash_multimap, and hash_set.
#define resip_assert(x)
This file needs to work for both C and C++ code.
Implementation of std::streambuf used to back the DataStream, iDataStream, and oDataStream.
static const bool isCharHex[256]
An iostream that operates on an existing Data.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
EncodeStream & escapeToStream(EncodeStream &str, Predicate shouldEscape) const
Performs escaping of this Data according to the indicated Predicate.
Data xmlCharDataDecode() const
Performs in-place XML Character Data un-escaping of a Data.
Data & uppercase()
Converts this Data to uppercase.
Data base64decode() const
Performs RFC 3548 Base 64 decoding of the contents of this data.
friend bool operator<(const Data &lhs, const Data &rhs)
static size_t rawCaseInsensitiveTokenHash(const unsigned char *c, size_t size)
A faster version of rawCaseInsensitiveHash that has the same collision properties if this Data is mad...
static const Data Empty
Constant that represents a zero-length data.
const char * c_str() const
Returns a null-terminated string representing.
Data & operator+=(char c)
Appends a single byte to the Data object.
ShareEnum
The various memory management behaviors.
@ Share
The Data instance will use the buffer in a read-only mode.
@ Borrow
The Data instance is borrowing the memory from the passed in buffer.
@ Take
The Data instance takes complete ownership of the buffer.
Data base64encode(bool useUrlSafe=false) const
Performs RFC 3548 Base 64 encoding of the contents of this data.
static size_t rawKeyedCaseInsensitiveHash(const unsigned char *c, size_t size)
As rawKeyedHash, after normalizing ASCII alphabetic characters to lowercase; consistent with isEqualN...
char & at(size_type p)
Returns the character at the specified position.
Data & operator^=(const Data &rhs)
Performs an in-place exclusive-or of this buffer buffer with the specified buffer.
Data & operator=(const std::string &str)
char & operator[](size_type p)
Returns the character at the specified position.
int replace(const Data &match, const Data &target, int max=INT_MAX)
Replaces up to max occurrences of the bytes match with target.
bool postfixNoCase(const Data &post) const noexcept
const char * end() const noexcept
Returns a pointer to the end of the buffer used by the Data.
static Data fromFile(const Data &filename)
Data charUnencoded() const
Performs RFC 3261 un-escaping of SIP URIs.
friend bool operator==(const Data &lhs, const std::string &rhs) noexcept
unsigned long convertUnsignedLong() const
bool sizeEqualCaseInsensitiveTokenCompare(const Data &rhs) const
char * getBuf(size_type length)
Set size to be exactly {length}, extending buffer if needed.
char operator[](size_type p) const
Returns the character at the specified position.
Data xmlCharDataEncode() const
Performs in-place XML Character Data escaping of a Data.
Data & operator=(const Data &data)
size_t keyedCaseInsensitiveHash() const
Creates a keyed hash based on the contents of this Data, after normalizing ASCII alphabetic character...
uint64_t convertUInt64() const
Takes the contents of the Data and converts them to an unsigned 64-bit integer.
static const PreallocateType Preallocate
used only to disambiguate constructors
std::string toString() const
Convert to a C++ string.
bool prefix(const Data &pre) const noexcept
Returns true if this Data starts with the bytes indicated by the passed-in Data.
Data & append(const char *str, size_type len)
Appends the specified number of bytes to the end of this Data.
Data & duplicate(const Data &other)
Functional equivalent of: *this = Data(buf, length) and Data& copy(const char *buf,...
size_t caseInsensitivehash() const
Creates a 32-bit hash based on the contents of this Data, after normalizing any alphabetic characters...
friend bool operator==(const Data &lhs, const Data &rhs)
friend bool operator<(const char *lhs, const Data &rhs)
Data substr(size_type first, size_type count=Data::npos) const
Copies a portion of this Data into a new Data.
Data & takeBuf(Data &other) noexcept
Take the data from {other}.
bool empty() const noexcept
Checks whether the Data is empty.
Data charEncoded() const
Performs RFC 3261 escaping of SIP URIs.
Data & lowercase()
Converts this Data to lowercase.
Data urlDecoded() const
Performs in-place HTTP URL un-escaping of a Data.
size_type size() const noexcept
Returns the number of bytes in this Data.
EncodeStream & urlEncode(EncodeStream &s) const
Escapes a Data to a stream according to HTTP URL encoding rules.
Data & operator=(const char *str)
Assigns a null-terminated string to the buffer.
static bool init(DataLocalSize< RESIP_DATA_LOCAL_SIZE > arg)
Initializes Data class.
friend std::ostream & operator<<(std::ostream &strm, const Data &d)
EncodeStream & urlDecode(EncodeStream &s) const
Un-escapes a Data to a stream according to HTTP URL encoding rules.
static Data from(const T &x)
Converts from arbitrary other type to Data.
size_type find(const Data &match, size_type start=0) const
Finds a specified sequence of bytes in this Data.
static const size_type npos
Represents an impossible position; returned to indicate failure to find.
static size_t rawKeyedHash(const unsigned char *c, size_t size)
Creates a hash based on the contents of the indicated buffer, using SipHash-1-3 with a key chosen ran...
Data operator+(const Data &rhs) const
Concatenates two Data objects.
Data urlEncoded() const
Performs in-place HTTP URL escaping of a Data.
friend bool operator<(const Data &lhs, const std::string &rhs) noexcept
Data & schemeLowercase()
Converts this Data to lowercase, assuming this Data only consists of scheme characters.
friend bool operator==(const Data &lhs, const char *rhs)
Data trunc(size_type trunc) const
Shortens the size of this Data.
friend bool operator<(const std::string &lhs, const Data &rhs) noexcept
const char * begin() const noexcept
Returns a pointer to the beginning of the buffer used by the Data.
Data & operator+=(const Data &rhs)
Appends a data object to this one.
Data & setBuf(ShareEnum se, const char *str)
Convience function to call setBuf() with a NULL-terminated string.
Data fromHex() const
Returns the binary form of the hexadecimal string in this Data.
size_t caseInsensitiveTokenHash() const
A faster version of caseInsensitiveHash that has the same collision properties if this Data is made u...
size_type truncate(size_type len)
Shortens the size of this Data.
Data & setBuf(ShareEnum se, const char *buf, size_type length)
Set the Data to hold {buf} using share type {se}, which may be any of Share (read-only,...
static size_t rawHash(const unsigned char *c, size_t size)
Creates a 32-bit hash based on the contents of the indicated buffer.
Data & copy(const char *buf, size_type length)
Functional equivalent of: *this = Data(buf, length) but avoids the intermediate allocation and free.
Data hex() const
Returns a hexadecimal representation of the contents of this Data.
size_t hash() const
Creates a 32-bit hash based on the contents of this Data.
double convertDouble() const
Takes the contents of the Data and converts them to a double precision floating point value.
friend bool operator<(const Data &lhs, const char *rhs)
int convertInt() const
Takes the contents of the Data and converts them to an integer.
Data escaped() const
Returns a representation of the contents of the data with any non-printable characters escaped.
bool postfix(const Data &post) const noexcept
Returns true if this Data ends with the bytes indicated by the passed-in Data.
Data & clear()
Clears the contents of this Data.
static std::bitset< 256 > toBitset(const resip::Data &chars)
Creates a bitset reflecting the contents of this data (as a set) ie.
size_t keyedHash() const
Creates a keyed hash based on the contents of this Data.
friend EncodeStream & operator<<(EncodeStream &strm, const Data &d)
Data md5(EncodingType type=HEX) const
Computes the MD5 hash of the current data.
size_t convertSize() const
Takes the contents of the Data and converts them to a size_t.
const char * data() const noexcept
Returns a pointer to the contents of this Data.
bool prefixNoCase(const Data &pre) const noexcept
void reserve(size_type capacity)
Guarantees that the underlying buffer used by the Data is at least the number of bytes specified.
static size_t rawCaseInsensitiveHash(const unsigned char *c, size_t size)
Creates a 32-bit hash based on the contents of the indicated buffer, after normalizing any alphabetic...
Data & truncate2(size_type len)
Shortens the size of this Data so length is at most of {len}.
Data & operator+=(const char *str)
Appends a null-terminated string to the end of the Data object.
bool caseInsensitiveTokenCompare(const Data &rhs) const
Implementation of std::streambuf used to back the MD5Stream.
Provides string-parsing functionality with protection from buffer overflow.
An ostream that operates on an existing Data.
This file is used to handle compatibility fixes/tweaks so reSIProcate can function on multiple platfo...
dcm! – add UnusedChecking(_enum) below;
const _Tp & resipMin(const _Tp &__a, const _Tp &__b)
bool isEqualNoCase(const Data &left, const Data &right)
bool operator<=(const Data &lhs, const Data &rhs)
size_t hashCombine(size_t seed, size_t hash)
Combines the hashes of the parts of a composite key, eg.
bool isLessThanNoCase(const Data &left, const Data &right)
bool operator>=(const Data &lhs, const Data &rhs)
static bool invokeDataInit
unsigned long long uint64_t
bool operator<(const Data &lhs, const Data &rhs)
bool operator>(const Data &lhs, const Data &rhs)
Data operator+(const char *c, const Data &d)
bool isTokenEqualNoCase(const Data &left, const Data &right)
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
bool operator==(const char *lhs, const Data &rhs)
bool operator!=(const Data &lhs, const Data &rhs)
DataLocalSize(size_t) noexcept
Hasher for hash containers keyed by data received from the network, e.g.
size_t operator()(const Data &data) const