37 static const size_type
npos { std::string::npos };
63 size_type n = strlen(s);
138 UChar &
operator[](size_type pos) {
if (pos >= length_)
throw EOctetString_OutOfRange();
return data_[pos]; }
139 cUChar &
operator[](size_type pos)
const {
if (pos >= length_)
throw EOctetString_OutOfRange();
return data_[pos]; }
184 return append(ostr.data_, ostr.length_);
192 if (subpos >= ostr.length_)
193 throw EOctetString_OutOfRange();
195 return append(&ostr.data_[subpos], sublen);
201 return append(reinterpret_cast<cpUChar>(s), strlen(s));
208 return append(reinterpret_cast<cpUChar>(s), n);
214 if (length_ + 1 > capacity_)
216 size_type newCapacity = capacity_;
217 while (newCapacity < length_ + 1)
221 data_[length_++] = c;
229 if (length_ + n > capacity_)
231 size_type newCapacity = capacity_;
232 while (newCapacity < length_ + n)
236 memcpy(&data_[length_], data, n);
245 if (length_ + n > capacity_)
247 size_type newCapacity = capacity_;
248 while (newCapacity < length_ + n)
252 memset(&data_[length_], c, n);
261 if (capacity_ < ostr.capacity_)
262 alloc(ostr.capacity_);
263 length_ = ostr.length_;
264 memcpy(data_, ostr.data_, length_);
273 if (subpos >= ostr.length_)
274 throw EOctetString_OutOfRange();
276 size_type len = std::min(ostr.length_ - subpos, sublen);
280 memcpy(data_, &ostr.data_[subpos], length_);
287 size_type len = strlen(s);
291 memcpy(data_, s, length_);
299 return assign(reinterpret_cast<cpUChar>(s), n);
309 memcpy(data_, data, length_);
320 memset(data_, c, length_);
329 capacity_ = ostr.capacity_;
330 length_ = ostr.length_;
335 ostr.data_ =
nullptr;
342 UChar &
at(size_type pos)
345 throw EOctetString_OutOfRange();
350 cUChar &
at(size_type pos)
const 353 throw EOctetString_OutOfRange();
360 return data_[length_ - 1];
365 return data_[length_ - 1];
374 memset(data_, 0, length_);
388 return compare(0, length_, ostr.data_, ostr.length_);
402 return compare(pos, len, ostr.data_, ostr.length_);
416 Int
compare(size_type pos, size_type len,
const EOctetString &ostr, size_type subpos, size_type sublen)
const 418 if (subpos >= ostr.length_)
419 throw EOctetString_OutOfRange();
420 return compare(pos, len, &ostr.data_[subpos], std::min(ostr.length_ - subpos, sublen));
432 return compare(0, length_, reinterpret_cast<cpUChar>(s), strlen(s));
445 return compare(0, length_, data, n);
457 Int
compare(size_type pos, size_type len, cpStr s)
const 459 return compare(pos, len, reinterpret_cast<cpUChar>(s), strlen(s));
472 Int
compare(size_type pos, size_type len, cpStr s, size_type n)
const 474 return compare(pos, len, reinterpret_cast<cpUChar>(s), n);
487 Int
compare(size_type pos, size_type len, cpUChar
data, size_type n)
const 490 throw EOctetString_OutOfRange();
492 len = std::min(len, length_ - pos);
494 Int result = memcmp(&data_[pos], data, len);
497 return len < length_ ? -1 : len > length_ ? 1 : 0;
505 size_type
copy(pUChar dst, size_type len, size_type pos = 0)
const 508 throw EOctetString_OutOfRange();
509 len = std::min(length_ - pos, len);
510 memcpy(dst, &data_[pos], len);
516 cpUChar
data()
const {
return data_; }
519 Bool
empty()
const {
return length_ == 0; }
530 throw EOctetString_OutOfRange();
533 len = std::min(length_ - pos, len);
536 size_type erase_start = length_ - len;
539 if (erase_start > pos)
541 size_type copy_dst = pos;
542 size_type copy_src = pos + len;
543 for (; copy_src<length_; copy_dst++, copy_src++)
544 data_[copy_dst] = data_[copy_src];
548 std::memset(&data_[erase_start], 0, len);
558 size_type
length()
const {
return length_; }
559 size_type
size()
const {
return length_; }
584 n = std::max(n, length_);
589 pUChar oldData = data_;
596 memcpy(data_, oldData, length_);
607 resize(n, static_cast<UChar>(c));
613 else if (n < length_)
615 memset(&data_[n], c, length_ - n);
631 static const size_type minCapacity_ { 15 };
643 Void alloc(size_type n)
649 data_ =
new UChar[capacity_];
658 typedef std::vector<EOctetString> EOctetStringVec;
662 std::ios_base::fmtflags f(std::cout.flags());
664 output << (idx?
", ":
"") <<
"0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast<UInt>(ostr.
at(idx));
688 #define LOW_NIBBLE(a) (((unsigned char)a) & 0x0f) 691 #define HIGH_NIBBLE(a) ((((unsigned char)a) & 0xf0) >> 4) 693 #define CHAR2TBCD(c) \ 695 c >= '0' && c <= '9' ? c - '0' : \ 698 (c == 'a' || c == 'A') ? 12 : \ 699 (c == 'b' || c == 'B') ? 13 : \ 700 (c == 'c' || c == 'C') ? 14 : 15 \ 755 static cpChar tbcdChars = (cpChar)
"0123456789*#abc";
761 UChar c = (*this)[idx];
763 if (tbcdChars[LOW_NIBBLE(c)])
765 str += tbcdChars[LOW_NIBBLE(c)];
766 if (tbcdChars[HIGH_NIBBLE(c)])
767 str += tbcdChars[HIGH_NIBBLE(c)];
779 return fromString(str.c_str());
795 UChar c = CHAR2TBCD(str[idx++]);
800 c |= CHAR2TBCD(str[idx++]);
826 #endif // __EOSTRING_H EOctetString(const EOctetString &ostr)
Copy constructor.
Definition: eostring.h:80
bool operator>=(cpStr str) const
Greater than or equal to operator.
Definition: eostring.h:178
Void push_back(UChar c)
Definition: eostring.h:576
Represents an TBCD String (Telephony Binary Coded Decimal String) as defined by ITU-T Recommendation ...
Definition: eostring.h:706
#define True
True.
Definition: ebase.h:25
Int compare(cpUChar data, size_type n) const
Compares the supplied buffer to this object.
Definition: eostring.h:443
Represents an OctetString as defined in RFC 6733.
Definition: eostring.h:33
std::size_t operator()(const EOctetString &ostr) const noexcept
Definition: eostring.h:676
Void clear()
Sets the internal buffer to all NULL's and sets the length to zero.
Definition: eostring.h:372
Bool empty() const
Returns whether this object is empty.
Definition: eostring.h:519
EOctetString & operator=(EOctetString &&ostr)
Assignment operator. Performs a move assignment.
Definition: eostring.h:120
bool operator>(cpStr str) const
Greater than operator.
Definition: eostring.h:172
Void reserve(size_type n=0)
Sets the internal buffer size to the specified value and reallocates the buffer if necessary...
Definition: eostring.h:582
DECLARE_ERROR(EOctetString_OutOfRange)
EOctetString & operator=(const EOctetString &ostr)
Assignment operator.
Definition: eostring.h:108
cUChar & operator[](size_type pos) const
Definition: eostring.h:139
Void resize(size_type n, Char c)
Resizes the buffer to the specified and fills the "new" space with the specified value.
Definition: eostring.h:605
ETbcdString(size_t len)
Class constructor.
Definition: eostring.h:730
EOctetString & assign(cpChar s, size_type n)
Assigns the specified value to this object.
Definition: eostring.h:297
ETbcdString & clear()
Clears the TBCD string setting it's length to zero.
Definition: eostring.h:820
EOctetString(cpUChar data, size_type n)
Class constructor.
Definition: eostring.h:70
EOctetString(size_type n)
Class constructor.
Definition: eostring.h:49
Int compare(size_type pos, size_type len, const EOctetString &ostr) const
Compares a subset of the supplied EOctetString to this object.
Definition: eostring.h:400
size_type length() const
Returns the length of the assigned value of this object.
Definition: eostring.h:558
bool operator!=(cpStr str) const
Not equal operator.
Definition: eostring.h:166
EOctetString & assign(EOctetString &&ostr)
Assign the specified value to this object using move semantics.
Definition: eostring.h:325
EOctetString & operator=(UChar c)
Assignment operator.
Definition: eostring.h:117
bool operator<(cpStr str) const
Less than operator.
Definition: eostring.h:169
EOctetString & operator=(cpStr s)
Assignment operator.
Definition: eostring.h:111
Int compare(size_type pos, size_type len, cpStr s, size_type n) const
Compares a NULL terminated string to this object starting at the supplied offset. ...
Definition: eostring.h:472
bool operator!=(const EOctetString &ostr) const
Not equal operator.
Definition: eostring.h:147
ETbcdString & operator=(const ETbcdString &tbcd)
Assignment operator.
Definition: eostring.h:744
bool operator<(const EOctetString &ostr) const
Less than operator.
Definition: eostring.h:150
EOctetString & operator+=(Char c)
Append operator.
Definition: eostring.h:130
EOctetString & operator+=(const EOctetString &ostr)
Append operator.
Definition: eostring.h:124
bool operator<=(cpStr str) const
Less than or equal to operator.
Definition: eostring.h:175
void shrink_to_fit()
reduces the capacity of the buffer to match it's current length.
Definition: eostring.h:622
Int compare(const EOctetString &ostr) const
Compares two EOctetString objects.
Definition: eostring.h:386
bool operator==(cpStr str) const
Equality operator.
Definition: eostring.h:163
ETbcdString()
Default constructor.
Definition: eostring.h:723
EString toString() const
Converts a TBCD string to a printable string.
Definition: eostring.h:753
Void pop_back()
Removes the last byte.
Definition: eostring.h:563
bool operator<=(const EOctetString &ostr) const
Less than or equal to operator.
Definition: eostring.h:156
EOctetString(const EOctetString &ostr, size_type pos, size_type len=npos)
Class constructor. Initializes this EOctetString from a subset of another EOctetString object...
Definition: eostring.h:93
size_type size() const
Definition: eostring.h:559
size_t length() const
Returns the length of the TBCD string.
Definition: eostring.h:816
EOctetString & append(cpUChar data, size_type n)
Appends to this object.
Definition: eostring.h:227
Defines base class for exceptions and declaration helper macros.
Void push_back(Char c)
Appends the specified value to the end of the octet string.
Definition: eostring.h:575
UChar & operator[](size_type pos)
Array index operator. Returns a reference to the specified array member.
Definition: eostring.h:138
cUChar & at(size_type pos) const
Returns a constant reference to the data at the specified offset.
Definition: eostring.h:350
Hash calculation functions for strings and byte arrays.
friend std::ostream & operator<<(std::ostream &output, const EOctetString &ostr)
Insertion oeprator for serialization.
bool operator==(const EOctetString &ostr) const
Equality operator.
Definition: eostring.h:144
ETbcdString & fromString(const std::string &str)
Converts the printable string to a TBCD string.
Definition: eostring.h:777
EOctetString & append(cpStr s)
Appends to this object.
Definition: eostring.h:199
EOctetString()
Default constructor.
Definition: eostring.h:40
cUChar & back() const
Returns a constant reference to the element at the end of the buffer.
Definition: eostring.h:363
static const size_type npos
Definition: eostring.h:37
EOctetString & append(cUChar c)
Appends to this object.
Definition: eostring.h:212
Int compare(cpStr s) const
Compares the supplied NULL terminated string to this object.
Definition: eostring.h:430
EOctetString & append(const EOctetString &ostr)
Appends to this object.
Definition: eostring.h:182
EOctetString & operator=(Char c)
Assignment operator.
Definition: eostring.h:114
EOctetString & assign(const EOctetString &ostr)
Assigns the specified value to this object.
Definition: eostring.h:259
EOctetString & operator+=(cpStr s)
Append operator.
Definition: eostring.h:127
EOctetString & assign(cpStr s)
Assigns the specified value to this object.
Definition: eostring.h:285
EOctetString & append(cpStr s, size_type n)
Appends to this object.
Definition: eostring.h:206
cpUChar data() const
Returns a pointer to the internal data buffer.
Definition: eostring.h:516
bool operator>(const EOctetString &ostr) const
Greater than operator.
Definition: eostring.h:153
Int compare(size_type pos, size_type len, cpStr s) const
Compares a NULL terminated string to this object starting at the supplied offset. ...
Definition: eostring.h:457
Void resize(size_type n, UChar c=0)
Definition: eostring.h:609
size_type capacity() const
Returns the size of the currently allocated internal buffer.
Definition: eostring.h:369
Int compare(size_type pos, size_type len, cpUChar data, size_type n) const
Compares buffer to this object starting at the supplied offset.
Definition: eostring.h:487
Int compare(size_type pos, size_type len, const EOctetString &ostr, size_type subpos, size_type sublen) const
Compares a subset of the supplied EOctetString to this object.
Definition: eostring.h:416
EOctetString & operator+=(UChar c)
Append operator.
Definition: eostring.h:133
EOctetString & assign(size_type n, UChar c)
Assigns the specified value to this object.
Definition: eostring.h:315
EOctetString(cpStr s)
Class constructor.
Definition: eostring.h:58
static size_t getHash(cChar val, size_t seed=0xc70f6907UL)
Calculates a 64-bit murmur hash for the value.
Definition: ehash.h:273
bool operator>=(const EOctetString &ostr) const
Greater than or equal to operator.
Definition: eostring.h:159
UChar & at(size_type pos)
Returns a reference to the data at the specified offset.
Definition: eostring.h:342
EOctetString & assign(cpUChar data, size_type n)
Assigns the specified value to this object.
Definition: eostring.h:304
size_type copy(pUChar dst, size_type len, size_type pos=0) const
Copies data from this object to the supplied buffer.
Definition: eostring.h:505
ETbcdString & fromString(cpStr str)
Definition: eostring.h:781
String class.
Definition: estring.h:31
~EOctetString()
Class destructor.
Definition: eostring.h:101
size_t size_type
Definition: eostring.h:36
EOctetString & append(const EOctetString &ostr, size_type subpos, size_type sublen)
Appends to this object.
Definition: eostring.h:190
ETbcdString(const ETbcdString &tbcd)
Copy constructor.
Definition: eostring.h:737
EOctetString & append(size_type n, UChar c)
Appends to this object.
Definition: eostring.h:243
UChar & back()
Returns a reference to the element at the end of the buffer.
Definition: eostring.h:358
EOctetString & assign(const EOctetString &ostr, size_type subpos, size_type sublen)
Assigns the specified value to this object.
Definition: eostring.h:271
EOctetString & erase(size_type pos=0, size_type len=npos)
Erases the specified number of bytes. Supports erasing bytes from the middle of the octet string...
Definition: eostring.h:526