/* -*- C++ -*- */ // $Id$ #include "ace/Malloc_Base.h" // Default constructor. template ACE_INLINE ACE_String_Base::ACE_String_Base (ACE_Allocator *alloc) : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), rep_ (&ACE_String_Base::NULL_String_), release_ (0) { ACE_TRACE ("ACE_String_Base::ACE_String_Base"); } // Constructor that actually copies memory. template ACE_INLINE ACE_String_Base::ACE_String_Base (const CHAR *s, ACE_Allocator *alloc, int release) : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), rep_ (0), release_ (0) { ACE_TRACE ("ACE_String_Base::ACE_String_Base"); size_t length; if (s != 0) length = ACE_OS::strlen (s); else length = 0; this->set (s, length, release); } template ACE_INLINE ACE_String_Base::ACE_String_Base (CHAR c, ACE_Allocator *alloc) : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), rep_ (0), release_ (0) { ACE_TRACE ("ACE_String_Base::ACE_String_Base"); this->set (&c, 1, 1); } // Constructor that actually copies memory. template ACE_INLINE ACE_String_Base::ACE_String_Base (const CHAR *s, size_t len, ACE_Allocator *alloc, int release) : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), rep_ (0), release_ (0) { ACE_TRACE ("ACE_String_Base::ACE_String_Base"); this->set (s, len, release); } // Copy constructor. template ACE_INLINE ACE_String_Base::ACE_String_Base (const ACE_String_Base &s) : allocator_ (s.allocator_ ? s.allocator_ : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), rep_ (0), release_ (0) { ACE_TRACE ("ACE_String_Base::ACE_String_Base"); this->set (s.rep_, s.len_, 1); } template ACE_INLINE ACE_String_Base::ACE_String_Base (size_t len, CHAR c, ACE_Allocator *alloc) : allocator_ (alloc ? alloc : ACE_Allocator::instance ()), len_ (0), buf_len_ (0), rep_ (0), release_ (0) { ACE_TRACE ("ACE_String_Base::ACE_String_Base"); this->resize (len, c); } template ACE_INLINE ACE_String_Base::~ACE_String_Base (void) { ACE_TRACE ("ACE_String_Base::~ACE_String_Base"); this->set (0, 0, 0); } template ACE_INLINE void ACE_String_Base::dump (void) const { ACE_TRACE ("ACE_String_Base::dump"); } // Assignment operator (does copy memory). template ACE_INLINE ACE_String_Base & ACE_String_Base::operator= (const ACE_String_Base &s) { ACE_TRACE ("ACE_String_Base::operator="); // Check for identify. if (this != &s) this->set (s.rep_, s.len_, 1); return *this; } template ACE_INLINE void ACE_String_Base::set (const CHAR *s, int release) { size_t length; if (s != 0) length = ACE_OS::strlen (s); else length = 0; this->set (s, length, release); } template ACE_INLINE size_t ACE_String_Base::length (void) const { ACE_TRACE ("ACE_String_Base::length"); return this->len_; } template ACE_INLINE void ACE_String_Base::clear (int release) { this->set(0, 0, release); } template ACE_INLINE ACE_String_Base ACE_String_Base::substr (size_t offset, ssize_t length) const { return this->substring (offset, length); } // Return the character in the string. template ACE_INLINE const CHAR & ACE_String_Base::operator[] (size_t slot) const { ACE_TRACE ("ACE_String_Base::operator[]"); return this->rep_[slot]; } // Return the character in the string by reference. template ACE_INLINE CHAR & ACE_String_Base::operator[] (size_t slot) { ACE_TRACE ("ACE_String_Base::operator[]"); return this->rep_[slot]; } // Get a copy of the underlying representation. template ACE_INLINE CHAR * ACE_String_Base::rep (void) const { ACE_TRACE ("ACE_String_Base::rep"); CHAR *new_string; ACE_NEW_RETURN (new_string, CHAR[this->len_ + 1], 0); ACE_OS::strsncpy (new_string, this->rep_, this->len_+1); return new_string; } template ACE_INLINE const CHAR * ACE_String_Base::fast_rep (void) const { return this->rep_; } template ACE_INLINE const CHAR * ACE_String_Base::c_str (void) const { return this->rep_; } // Comparison operator. template ACE_INLINE int ACE_String_Base::operator== (const ACE_String_Base &s) const { ACE_TRACE ("ACE_String_Base::operator=="); return this->len_ == s.len_ && ACE_OS::strncmp (this->rep_, s.rep_, this->len_) == 0; } // Less than comparison operator. template ACE_INLINE int ACE_String_Base::operator < (const ACE_String_Base &s) const { ACE_TRACE ("ACE_String_Base::operator <"); return (this->rep_ && s.rep_) ? ACE_OS::strcmp (this->rep_, s.rep_) < 0 : ((s.rep_) ? 1 : 0 ); } // Greater than comparison operator. template ACE_INLINE int ACE_String_Base::operator > (const ACE_String_Base &s) const { ACE_TRACE ("ACE_String_Base::operator >"); return (this->rep_ && s.rep_) ? ACE_OS::strcmp (this->rep_, s.rep_) > 0 : ((this->rep_) ? 1 : 0 ); } // Comparison operator. template ACE_INLINE int ACE_String_Base::operator!= (const ACE_String_Base &s) const { ACE_TRACE ("ACE_String_Base::operator!="); return !(*this == s); } template ACE_INLINE int ACE_String_Base::compare (const ACE_String_Base &s) const { ACE_TRACE ("ACE_String_Base::compare"); // We can't just pass both strings to strcmp, since they are not // guaranteed to be null-terminated. // Pick smaller of the two lengths and perform the comparison. int smaller_length = (this->len_ < s.len_) ? this->len_ : s.len_; int result = ACE_OS::strncmp (this->rep_, s.rep_, smaller_length); if (result != 0 || s.len_ == this->len_) return result; else // we need to differentiate based on length if (this->len_ > s.len_) return (this->rep_[smaller_length] - '\0'); else return ('\0' - s.rep_[smaller_length]); } template ACE_INLINE int ACE_String_Base::find (const CHAR *s, int pos) const { CHAR *substr = this->rep_ + pos; size_t len = ACE_OS::strlen (s); CHAR *pointer = ACE_OS::strnstr (substr, s, len); if (pointer == 0) return ACE_String_Base::npos; else return pointer - this->rep_; } template ACE_INLINE int ACE_String_Base::find (CHAR c, int pos) const { CHAR *substr = this->rep_ + pos; CHAR *pointer = ACE_OS::strnchr (substr, c, this->len_ - pos); if (pointer == 0) return ACE_String_Base::npos; else return pointer - this->rep_; } template ACE_INLINE int ACE_String_Base::find (const ACE_String_Base &str, int pos) const { return this->find (str.rep_, pos); } template ACE_INLINE int ACE_String_Base::strstr (const ACE_String_Base &s) const { ACE_TRACE ("ACE_String_Base::strstr"); return this->find (s.rep_); } template ACE_INLINE int ACE_String_Base::rfind (CHAR c, int pos) const { if (pos == ACE_String_Base::npos) pos = this->len_; for (int i = pos - 1; i >= 0; i--) if (this->rep_[i] == c) return i; return ACE_String_Base::npos; } template ACE_INLINE u_long ACE_String_Base::hash (void) const { return ACE::hash_pjw ( (ACE_reinterpret_cast (char *, ACE_const_cast (CHAR *, this->rep_))), this->len_ * sizeof (CHAR)); } template ACE_INLINE ACE_String_Base operator+ (const ACE_String_Base &s, const ACE_String_Base &t) { ACE_String_Base temp (s); temp += t; return temp; } template ACE_INLINE ACE_String_Base operator+ (const CHAR *s, const ACE_String_Base &t) { ACE_String_Base temp (s); temp += t; return temp; } template ACE_INLINE ACE_String_Base operator+ (const ACE_String_Base &s, const CHAR *t) { ACE_String_Base temp (s); temp += t; return temp; }