1 #include "ace/Local_Name_Space.h"
3 #include "ace/RW_Process_Mutex.h"
4 #include "ace/SString.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/Truncate.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 ACE_NS_String::~ACE_NS_String ()
12 if (this->delete_rep_
)
13 #if defined (ACE_HAS_ALLOC_HOOKS)
14 ACE_Allocator::instance()->free(this->rep_
);
17 #endif /* ACE_HAS_ALLOC_HOOKS */
21 ACE_NS_String::fast_rep () const
23 ACE_TRACE ("ACE_NS_String::fast_rep");
27 ACE_NS_String::operator ACE_NS_WString () const
29 ACE_TRACE ("ACE_NS_String::operator ACE_NS_WString");
30 return ACE_NS_WString (this->rep_
,
31 (this->len_
/ sizeof (ACE_WCHAR_T
)) - 1);
35 ACE_NS_String::len () const
37 ACE_TRACE ("ACE_NS_String::len");
42 ACE_NS_String::char_rep () const
44 ACE_TRACE ("ACE_NS_String::char_rep");
45 ACE_NS_WString
w_string (this->rep_
,
46 (this->len_
/ sizeof (ACE_WCHAR_T
)) - 1);
47 return w_string
.char_rep ();
50 ACE_NS_String::ACE_NS_String ()
55 ACE_TRACE ("ACE_NS_String::ACE_NS_String");
58 ACE_NS_String::ACE_NS_String (const ACE_NS_WString
&s
)
59 : len_ ((s
.length () + 1) * sizeof (ACE_WCHAR_T
)),
63 ACE_TRACE ("ACE_NS_String::ACE_NS_String");
67 ACE_NS_String::strstr (const ACE_NS_String
&s
) const
69 ACE_TRACE ("ACE_NS_String::strstr");
71 if (this->len_
< s
.len_
)
72 // If they're larger than we are they can't be a substring of us!
74 else if (this->len_
== s
.len_
)
75 // Check if we're equal.
76 return *this == s
? 0 : -1;
79 // They're smaller than we are...
80 const size_t len
= (this->len_
- s
.len_
) / sizeof (ACE_WCHAR_T
);
81 const size_t pat_len
= s
.len_
/ sizeof (ACE_WCHAR_T
) - 1;
83 for (size_t i
= 0; i
<= len
; ++i
)
87 for (j
= 0; j
< pat_len
; ++j
)
88 if (this->rep_
[i
+ j
] != s
.rep_
[j
])
92 // Found a match! Return the index.
93 return ACE_Utils::truncate_cast
<int> (i
);
101 ACE_NS_String::operator == (const ACE_NS_String
&s
) const
103 ACE_TRACE ("ACE_NS_String::operator ==");
104 return this->len_
== s
.len_
105 && ACE_OS::memcmp ((void *) this->rep_
,
106 (void *) s
.rep_
, this->len_
) == 0;
110 ACE_NS_String::operator != (const ACE_NS_String
&s
) const
112 ACE_TRACE ("ACE_NS_String::operator !=");
113 return !this->operator == (s
);
116 ACE_NS_String::ACE_NS_String (ACE_WCHAR_T
*dst
,
117 const ACE_WCHAR_T
*src
,
123 ACE_TRACE ("ACE_NS_String::ACE_NS_String");
124 ACE_OS::memcpy (this->rep_
, src
, bytes
);
128 ACE_NS_String::hash () const
131 (reinterpret_cast<char *> (const_cast<ACE_WCHAR_T
*> (this->rep_
)),
135 ACE_NS_Internal::ACE_NS_Internal ()
141 ACE_NS_Internal::ACE_NS_Internal (ACE_NS_String
&value
, const char *type
)
145 ACE_TRACE ("ACE_NS_Internal::ACE_NS_Internal");
149 ACE_NS_Internal::operator == (const ACE_NS_Internal
&s
) const
151 ACE_TRACE ("ACE_NS_Internal::operator ==");
152 return this->value_
== s
.value_
;
156 ACE_NS_Internal::value ()
158 ACE_TRACE ("ACE_NS_Internal::value");
163 ACE_NS_Internal::type ()
165 ACE_TRACE ("ACE_NS_Internal::type");
169 ACE_END_VERSIONED_NAMESPACE_DECL