12#ifndef SCRIPTS_INCLUDE__ENGINE_STRING_H
13#define SCRIPTS_INCLUDE__ENGINE_STRING_H
17#include "engine_common.h"
18#include "HashTemplateKeyClass.h"
25 StringClass(
bool hint_temporary);
26 StringClass(
int initial_len = 0,
bool hint_temporary =
false);
27 StringClass(
const StringClass&
string,
bool hint_temporary =
false);
28 StringClass(
const char *
string,
bool hint_temporary =
false);
29 StringClass(
char ch,
bool hint_temporary =
false);
30 StringClass(
const wchar_t *
string,
bool hint_temporary =
false);
32 bool operator ==(
const char* rvalue)
const;
33 bool operator!= (
const char* rvalue)
const;
34 const StringClass& operator=(
const char*
string);
35 const StringClass& operator=(
const StringClass&
string);
36 const StringClass& operator=(
char ch);
37 const StringClass& operator=(
const wchar_t *
string);
39 const StringClass& operator+=(
const char*
string);
40 const StringClass& operator+=(
const StringClass&
string);
41 const StringClass& operator+=(
char ch);
43 friend StringClass operator+ (
const StringClass &string1,
const StringClass &string2);
44 friend StringClass operator+ (
const StringClass &string1,
const char *string2);
45 friend StringClass operator+ (
const char *string1,
const StringClass &string2);
47 bool operator < (
const char *
string)
const;
48 bool operator <= (
const char *
string)
const;
49 bool operator > (
const char *
string)
const;
50 bool operator >= (
const char *
string)
const;
52 const char & operator[] (
int index)
const;
53 char & operator[] (
int index);
54 operator const char * (void)
const;
56 int Compare (
const char *
string)
const;
57 int Compare_No_Case (
const char *
string)
const;
59 int Get_Length (
void)
const;
60 bool Is_Empty (
void)
const;
61 void Erase (
int start_index,
int char_count);
62 SHARED_API
int __cdecl Format(
const char* format,...);
63 SHARED_API
int __cdecl Format_Args(
const char* format,
const va_list& arg_list);
64 char *Get_Buffer (
int new_length);
65 char *Peek_Buffer (
void);
66 const char * Peek_Buffer (
void)
const;
67 SHARED_API
bool Copy_Wide (
const wchar_t *source);
68 SHARED_API
static void Release_Resources();
86 SHARED_API
int Replace(
const char* search,
const char* replace,
bool bCaseSensitive =
true,
int maxCount=-1);
88 void TruncateLeft(uint truncateLength)
90 uint length = Get_Length();
91 if (length <= truncateLength)
96 int newLength = length - truncateLength;
97 memmove(m_Buffer, m_Buffer + truncateLength, newLength + 1);
98 Store_Length(newLength);
102 void TruncateRight(uint truncateLength)
104 uint length = Get_Length();
105 if (length <= truncateLength)
110 int newLength = length - truncateLength;
111 m_Buffer[newLength] =
'\0';
112 Store_Length(newLength);
118 const int length = Get_Length();
121 else if (to < length)
128 void cropFrom(
int from)
130 const int length = Get_Length();
135 memmove(m_Buffer, m_Buffer + from, length - from + 1);
136 Store_Length(length - from);
140 void crop(
int from,
int to)
148 char* iter = m_Buffer;
149 for (; *iter !=
'\0' && *iter <=
' '; iter++);
151 TruncateLeft((
int)(iter - m_Buffer));
156 char* iter = m_Buffer + Get_Length() - 1;
157 for (; *iter !=
'\0' && *iter <=
' '; iter--);
159 TruncateRight((
int)(m_Buffer + Get_Length() - 1 - iter));
168 bool StartsWithI(
const char*
string)
170 return _strnicmp(m_Buffer,
string, strlen(
string)) == 0;
175 int length = Get_Length();
177 return HashTemplateKeyClass<uint>::Get_Hash_Value((uint&)m_Buffer[length - 8]);
181 for (
int i = 0; i < length; i++)
182 hash += m_Buffer[i] + hash * 37;
189 int length = Get_Length();
190 for (
int i = 0; i < length; ++i)
192 if (m_Buffer[i] == c)
return i;
197 int LastIndexOf(
char c)
199 for (
int i = Get_Length() - 1; i >= 0; --i)
201 if (m_Buffer[i] == c)
return i;
216 StringClass AsUpper()
const
218 StringClass result = *
this;
223 StringClass AsLower()
const
225 StringClass result = *
this;
230 static StringClass getFormattedString(
const char* format, ...)
235 va_start(arguments, format);
236 result.Format_Args(format, arguments);
243 typedef struct _HEADER
245 int allocated_length;
251 MAX_TEMP_LEN = 256-
sizeof(_HEADER),
252 MAX_TEMP_BYTES = (MAX_TEMP_LEN *
sizeof (
char)) +
sizeof (HEADER),
254 SHARED_API
void Get_String(
int length,
bool is_temp);
255 char* Allocate_Buffer(
int len);
256 SHARED_API
void Resize(
int new_len);
257 SHARED_API
void Uninitialised_Grow(
int new_len);
258 SHARED_API
void Free_String();
259 void Store_Length(
int length);
260 void Store_Allocated_Length(
int length);
261 HEADER *Get_Header()
const;
262 int Get_Allocated_Length()
const;
263 void Set_Buffer_And_Allocated_Length(
char *buffer,
int length);
265#if (SHARED_EXPORTS) || (EXTERNAL)
266 static char __declspec(thread) TempStrings[MAX_TEMP_STRING][MAX_TEMP_BYTES];
267 static unsigned int __declspec(thread) FreeTempStrings;
270 static char *m_EmptyString;
271 static char m_NullChar;
273 SHARED_API
static REF_DECL(
char *, m_EmptyString);
274 SHARED_API
static REF_DECL(
char, m_NullChar);
278inline const StringClass &StringClass::operator= (
const StringClass &
string)
280 int len =
string.Get_Length();
281 Uninitialised_Grow(len+1);
283 memcpy (m_Buffer,
string.m_Buffer, (len+1) *
sizeof (
char));
287inline const StringClass &StringClass::operator= (
const char *
string)
291 int len = (int)strlen (
string);
292 Uninitialised_Grow (len+1);
294 memcpy (m_Buffer,
string, (len + 1) *
sizeof (
char));
299inline const StringClass &StringClass::operator= (
const wchar_t *
string)
308inline const StringClass &StringClass::operator= (
char ch)
310 Uninitialised_Grow (2);
312 m_Buffer[1] = m_NullChar;
317inline StringClass::StringClass (
bool hint_temporary) : m_Buffer (m_EmptyString)
319 Get_String (MAX_TEMP_LEN, hint_temporary);
320 m_Buffer[0] = m_NullChar;
324inline StringClass::StringClass (
int initial_len,
bool hint_temporary) : m_Buffer (m_EmptyString)
326 Get_String (initial_len, hint_temporary);
327 m_Buffer[0] = m_NullChar;
330inline StringClass::StringClass (
char ch,
bool hint_temporary) : m_Buffer (m_EmptyString)
332 Get_String (2, hint_temporary);
336inline StringClass::StringClass (
const StringClass &
string,
bool hint_temporary) : m_Buffer (m_EmptyString)
338 if (hint_temporary || (
string.Get_Length()>0))
340 Get_String (
string.Get_Length()+1, hint_temporary);
345inline StringClass::StringClass (
const char *
string,
bool hint_temporary) : m_Buffer (m_EmptyString)
347 int len=
string ? (int)strlen(
string) : 0;
348 if (hint_temporary || len>0)
350 Get_String (len+1, hint_temporary);
355inline StringClass::StringClass (
const wchar_t *
string,
bool hint_temporary) : m_Buffer (m_EmptyString)
357 int len =
string ? (int)wcslen (
string) : 0;
358 if (hint_temporary || len > 0)
360 Get_String (len + 1, hint_temporary);
365inline StringClass::~StringClass (
void)
370inline bool StringClass::Is_Empty (
void)
const
372 return (m_Buffer[0] == m_NullChar);
375inline int StringClass::Compare (
const char *
string)
const
377 return strcmp (m_Buffer,
string);
380inline int StringClass::Compare_No_Case (
const char *
string)
const
382 return _stricmp (m_Buffer,
string);
385inline const char &StringClass::operator[] (
int index)
const
387 return m_Buffer[index];
390inline char &StringClass::operator[] (
int index)
392 return m_Buffer[index];
395inline StringClass::operator
const char * (void)
const
400inline bool StringClass::operator== (
const char *rvalue)
const
402 return (Compare (rvalue) == 0);
405inline bool StringClass::operator!= (
const char *rvalue)
const
407 return (Compare (rvalue) != 0);
410inline bool StringClass::operator < (
const char *
string)
const
412 return (strcmp (m_Buffer,
string) < 0);
415inline bool StringClass::operator <= (
const char *
string)
const
417 return (strcmp (m_Buffer,
string) <= 0);
420inline bool StringClass::operator > (
const char *
string)
const
422 return (strcmp (m_Buffer,
string) > 0);
425inline bool StringClass::operator >= (
const char *
string)
const
427 return (strcmp (m_Buffer,
string) >= 0);
430inline void StringClass::Erase (
int start_index,
int char_count)
432 int len = Get_Length ();
433 if (start_index < len)
435 if (start_index + char_count > len)
437 char_count = len - start_index;
439 memmove ( &m_Buffer[start_index], &m_Buffer[start_index + char_count], (len - (start_index + char_count) + 1) *
sizeof (
char));
440 Store_Length( len - char_count );
444inline const StringClass &StringClass::operator+= (
const char *
string)
446 int cur_len = Get_Length ();
447 int src_len = (int)strlen (
string);
448 int new_len = cur_len + src_len;
449 Resize (new_len + 1);
450 Store_Length (new_len);
451 memcpy (&m_Buffer[cur_len],
string, (src_len + 1) *
sizeof (
char));
455inline const StringClass &StringClass::operator+= (
char ch)
457 int cur_len = Get_Length ();
458 Resize (cur_len + 2);
459 m_Buffer[cur_len] = ch;
460 m_Buffer[cur_len + 1] = m_NullChar;
461 if (ch != m_NullChar)
463 Store_Length (cur_len + 1);
468inline char *StringClass::Get_Buffer (
int new_length)
470 Uninitialised_Grow (new_length);
474inline char *StringClass::Peek_Buffer (
void)
479inline const char *StringClass::Peek_Buffer (
void)
const
484inline const StringClass &StringClass::operator+= (
const StringClass &
string)
486 int src_len =
string.Get_Length();
489 int cur_len = Get_Length ();
490 int new_len = cur_len + src_len;
491 Resize (new_len + 1);
492 Store_Length (new_len);
493 memcpy (&m_Buffer[cur_len], (
const char *)
string, (src_len + 1) *
sizeof (
char));
498inline StringClass operator+ (
const StringClass &string1,
const StringClass &string2)
500 StringClass new_string(string1,
true);
501 new_string += string2;
505inline StringClass operator+ (
const char *string1,
const StringClass &string2)
507 StringClass new_string(string1,
true);
508 new_string += string2;
512inline StringClass operator+ (
const StringClass &string1,
const char *string2)
514 StringClass new_string(string1,
true);
515 StringClass new_string2(string2,
true);
516 new_string += new_string2;
520inline int StringClass::Get_Allocated_Length (
void)
const
522 int allocated_length = 0;
523 if (m_Buffer != m_EmptyString)
525 HEADER *header = Get_Header ();
526 allocated_length = header->allocated_length;
528 return allocated_length;
531inline int StringClass::Get_Length (
void)
const
534 if (m_Buffer != m_EmptyString)
536 HEADER *header = Get_Header ();
537 length = header->length;
540 length = (int)strlen (m_Buffer);
541 ((StringClass *)
this)->Store_Length (length);
547inline void StringClass::Set_Buffer_And_Allocated_Length (
char *buffer,
int length)
551 if (m_Buffer != m_EmptyString)
553 Store_Allocated_Length (length);
558inline char *StringClass::Allocate_Buffer (
int length)
560 char *buffer =
new char[(
sizeof (char) * length) +
sizeof (StringClass::_HEADER)];
561 HEADER *header =
reinterpret_cast<HEADER *
>(buffer);
563 header->allocated_length = length;
564 return reinterpret_cast<char *
>(buffer +
sizeof (StringClass::_HEADER));
567inline StringClass::HEADER *StringClass::Get_Header (
void)
const
569 return reinterpret_cast<HEADER *
>(((
char *)m_Buffer) -
sizeof (StringClass::_HEADER));
572inline void StringClass::Store_Allocated_Length (
int allocated_length)
574 if (m_Buffer != m_EmptyString)
576 HEADER *header = Get_Header ();
577 header->allocated_length = allocated_length;
581inline void StringClass::Store_Length (
int length)
583 if (m_Buffer != m_EmptyString)
585 HEADER *header = Get_Header();
586 header->length = length;
590class WideStringClass {
592 WideStringClass (
int initial_len = 0,
bool hint_temporary =
false);
593 WideStringClass (
const WideStringClass &
string,
bool hint_temporary =
false);
594 WideStringClass (
const wchar_t *
string,
bool hint_temporary =
false);
595 WideStringClass (
wchar_t ch,
bool hint_temporary =
false);
596 WideStringClass (
const char *
string,
bool hint_temporary =
false);
597 ~WideStringClass (
void);
598 bool operator== (
const wchar_t *rvalue)
const;
599 bool operator!= (
const wchar_t *rvalue)
const;
600 const WideStringClass &operator= (
const WideStringClass &
string);
601 const WideStringClass &operator= (
const wchar_t *
string);
602 const WideStringClass &operator= (
wchar_t ch);
603 const WideStringClass &operator= (
const char *
string);
605 const WideStringClass &operator+= (
const WideStringClass &
string);
606 const WideStringClass &operator+= (
const wchar_t *
string);
607 const WideStringClass &operator+= (
wchar_t ch);
609 friend WideStringClass operator+ (
const WideStringClass &string1,
const WideStringClass &string2);
610 friend WideStringClass operator+ (
const wchar_t *string1,
const WideStringClass &string2);
611 friend WideStringClass operator+ (
const WideStringClass &string1,
const wchar_t *string2);
613 bool operator < (
const wchar_t *
string)
const;
614 bool operator <= (
const wchar_t *
string)
const;
615 bool operator > (
const wchar_t *
string)
const;
616 bool operator >= (
const wchar_t *
string)
const;
618 wchar_t operator[] (
int index)
const;
619 wchar_t& operator[] (
int index);
620 operator const wchar_t * (void)
const;
622 int Compare (
const wchar_t *
string)
const;
623 int Compare_No_Case (
const wchar_t *
string)
const;
624 int Get_Length (
void)
const;
625 bool Is_Empty (
void)
const;
626 void Erase (
int start_index,
int char_count);
627 SHARED_API
int _cdecl Format (
const wchar_t *format, ...);
628 SHARED_API
int _cdecl Format_Args (
const wchar_t *format,
const va_list & arg_list );
629 SHARED_API
bool Convert_From (
const char *text);
630 bool Convert_To (StringClass &
string);
631 bool Convert_To (StringClass &
string)
const;
632 SHARED_API
bool Is_ANSI(
void);
633 wchar_t * Get_Buffer (
int new_length);
634 wchar_t * Peek_Buffer (
void);
635 const wchar_t* Peek_Buffer()
const;
636 SHARED_API
static void Release_Resources (
void);
638 void TruncateLeft(uint truncateLength)
640 uint length = Get_Length();
641 if (length <= truncateLength)
646 int newLength = length - truncateLength;
647 memmove(m_Buffer, m_Buffer + truncateLength, (newLength + 1)*2);
648 Store_Length(newLength);
651 void TruncateRight(uint truncateLength)
653 uint length = Get_Length();
654 if (length <= truncateLength)
658 int newLength = length - truncateLength;
659 m_Buffer[newLength] = L
'\0';
660 Store_Length(newLength);
666 wchar_t* iter = m_Buffer;
667 for (; *iter != L
'\0' && *iter <= L
' '; iter++);
668 TruncateLeft((
int)(iter - m_Buffer));
673 wchar_t* iter = m_Buffer + Get_Length() - 1;
674 for (; *iter != L
'\0' && *iter <= L
' '; iter--);
675 TruncateRight((
int)(m_Buffer + Get_Length() - 1 - iter));
684 static WideStringClass getFormattedString(
const wchar_t* format, ...)
687 WideStringClass result;
689 va_start(arguments, format);
690 result.Format_Args(format, arguments);
696 SHARED_API WideStringClass Substring(
int start,
int length)
const;
697 SHARED_API
void RemoveSubstring(
int start,
int length);
698 SHARED_API
void ReplaceSubstring(
int start,
int length,
const WideStringClass& substring);
701 typedef struct _HEADER
703 int allocated_length;
710 MAX_TEMP_BYTES = (MAX_TEMP_LEN *
sizeof (wchar_t)) +
sizeof (HEADER),
712 SHARED_API
void Get_String(
int length,
bool is_temp);
713 wchar_t * Allocate_Buffer (
int length);
714 SHARED_API
void Resize (
int size);
715 SHARED_API
void Uninitialised_Grow (
int length);
716 SHARED_API
void Free_String();
717 void Store_Length(
int length);
718 void Store_Allocated_Length(
int length);
719 HEADER *Get_Header()
const;
720 int Get_Allocated_Length()
const;
721 void Set_Buffer_And_Allocated_Length(
wchar_t *buffer,
int length);
723#if (SHARED_EXPORTS || EXTERNAL)
724 static char __declspec(thread) TempStrings[MAX_TEMP_STRING][MAX_TEMP_BYTES];
725 static unsigned int __declspec(thread) FreeTempStrings;
728 static wchar_t *m_EmptyString;
729 static wchar_t m_NullChar;
731 SHARED_API
static REF_DECL(
wchar_t *, m_EmptyString);
732 SHARED_API
static REF_DECL(
wchar_t, m_NullChar);
736inline WideStringClass::WideStringClass (
int initial_len,
bool hint_temporary) : m_Buffer (m_EmptyString)
738 Get_String (initial_len, hint_temporary);
739 m_Buffer[0] = m_NullChar;
742inline WideStringClass::WideStringClass (
wchar_t ch,
bool hint_temporary) : m_Buffer (m_EmptyString)
744 Get_String (2, hint_temporary);
748inline WideStringClass::WideStringClass (
const WideStringClass &
string,
bool hint_temporary) : m_Buffer (m_EmptyString)
750 if (hint_temporary || (
string.Get_Length()>1))
752 Get_String(
string.Get_Length()+1, hint_temporary);
757inline WideStringClass::WideStringClass (
const wchar_t *
string,
bool hint_temporary) : m_Buffer (m_EmptyString)
759 int len=
string ? (int)wcslen(
string) : 0;
760 if (hint_temporary || len>0)
762 Get_String (len+1, hint_temporary);
768inline WideStringClass::WideStringClass (
const char *
string,
bool hint_temporary) : m_Buffer (m_EmptyString)
770 if (hint_temporary || (
string && strlen(
string)>0))
772 Get_String ((
int)strlen(
string) + 1, hint_temporary);
777inline WideStringClass::~WideStringClass (
void)
782inline bool WideStringClass::Is_Empty (
void)
const
784 return (m_Buffer[0] == m_NullChar);
787inline int WideStringClass::Compare (
const wchar_t *
string)
const
791 return wcscmp (m_Buffer,
string);
796inline int WideStringClass::Compare_No_Case (
const wchar_t *
string)
const
800 return _wcsicmp (m_Buffer,
string);
805inline wchar_t WideStringClass::operator[] (
int index)
const
807 return m_Buffer[index];
810inline wchar_t& WideStringClass::operator[] (
int index)
812 return m_Buffer[index];
815inline WideStringClass::operator
const wchar_t * (void)
const
820inline bool WideStringClass::operator== (
const wchar_t *rvalue)
const
822 return (Compare (rvalue) == 0);
825inline bool WideStringClass::operator!= (
const wchar_t *rvalue)
const
827 return (Compare (rvalue) != 0);
830inline const WideStringClass & WideStringClass::operator= (
const WideStringClass &
string)
832 return operator= ((
const wchar_t *)
string);
835inline bool WideStringClass::operator < (
const wchar_t *
string)
const
839 return (wcscmp (m_Buffer,
string) < 0);
844inline bool WideStringClass::operator <= (
const wchar_t *
string)
const
848 return (wcscmp (m_Buffer,
string) <= 0);
853inline bool WideStringClass::operator > (
const wchar_t *
string)
const
857 return (wcscmp (m_Buffer,
string) > 0);
862inline bool WideStringClass::operator >= (
const wchar_t *
string)
const
866 return (wcscmp (m_Buffer,
string) >= 0);
871inline void WideStringClass::Erase (
int start_index,
int char_count)
873 int len = Get_Length ();
874 if (start_index < len)
876 if (start_index + char_count > len)
878 char_count = len - start_index;
880 memmove (&m_Buffer[start_index],&m_Buffer[start_index + char_count],(len - (start_index + char_count) + 1) *
sizeof (
wchar_t));
881 Store_Length( (
int)wcslen(m_Buffer) );
885inline const WideStringClass & WideStringClass::operator= (
const wchar_t *
string)
889 int len = (int)wcslen (
string);
890 Uninitialised_Grow (len + 1);
892 memcpy (m_Buffer,
string, (len + 1) *
sizeof (
wchar_t));
897inline const WideStringClass &WideStringClass::operator= (
const char *
string)
899 Convert_From(
string);
903inline const WideStringClass &WideStringClass::operator= (
wchar_t ch)
905 Uninitialised_Grow (2);
907 m_Buffer[1] = m_NullChar;
912inline const WideStringClass &WideStringClass::operator+= (
const wchar_t *
string)
916 int cur_len = Get_Length ();
917 int src_len = (int)wcslen (
string);
918 int new_len = cur_len + src_len;
919 Resize (new_len + 1);
920 Store_Length (new_len);
921 memcpy (&m_Buffer[cur_len],
string, (src_len + 1) *
sizeof (
wchar_t));
926inline const WideStringClass &WideStringClass::operator+= (
wchar_t ch)
928 int cur_len = Get_Length ();
929 Resize (cur_len + 2);
930 m_Buffer[cur_len] = ch;
931 m_Buffer[cur_len + 1] = m_NullChar;
932 if (ch != m_NullChar)
934 Store_Length (cur_len + 1);
939inline wchar_t *WideStringClass::Get_Buffer (
int new_length)
941 Uninitialised_Grow (new_length);
945inline wchar_t *WideStringClass::Peek_Buffer (
void)
950inline const wchar_t* WideStringClass::Peek_Buffer()
const
955inline const WideStringClass &WideStringClass::operator+= (
const WideStringClass &
string)
957 int src_len =
string.Get_Length();
960 int cur_len = Get_Length ();
961 int new_len = cur_len + src_len;
962 Resize (new_len + 1);
963 Store_Length (new_len);
964 memcpy (&m_Buffer[cur_len], (
const wchar_t *)
string, (src_len + 1) *
sizeof (
wchar_t));
969inline WideStringClass operator+ (
const WideStringClass &string1,
const WideStringClass &string2)
971 WideStringClass new_string(string1,
true);
972 new_string += string2;
976inline WideStringClass operator+ (
const wchar_t *string1,
const WideStringClass &string2)
978 WideStringClass new_string(string1,
true);
979 new_string += string2;
983inline WideStringClass operator+ (
const WideStringClass &string1,
const wchar_t *string2)
985 WideStringClass new_string(string1,
true);
986 new_string += string2;
990inline int WideStringClass::Get_Allocated_Length (
void)
const
992 int allocated_length = 0;
993 if (m_Buffer != m_EmptyString)
995 HEADER *header = Get_Header ();
996 allocated_length = header->allocated_length;
998 return allocated_length;
1001inline int WideStringClass::Get_Length (
void)
const
1004 if (m_Buffer != m_EmptyString)
1006 HEADER *header = Get_Header ();
1007 length = header->length;
1010 length = (int)wcslen (m_Buffer);
1011 ((WideStringClass *)
this)->Store_Length (length);
1017inline void WideStringClass::Set_Buffer_And_Allocated_Length (
wchar_t *buffer,
int length)
1021 if (m_Buffer != m_EmptyString)
1023 Store_Allocated_Length (length);
1028inline wchar_t * WideStringClass::Allocate_Buffer (
int length)
1030 char *buffer =
new char[(
sizeof (wchar_t) * length) +
sizeof (WideStringClass::_HEADER)];
1031 HEADER *header =
reinterpret_cast<HEADER *
>(buffer);
1033 header->allocated_length = length;
1034 return reinterpret_cast<wchar_t *
>(buffer +
sizeof (WideStringClass::_HEADER));
1037inline WideStringClass::HEADER * WideStringClass::Get_Header (
void)
const
1039 return reinterpret_cast<HEADER *
>(((
char *)m_Buffer) -
sizeof (WideStringClass::_HEADER));
1042inline void WideStringClass::Store_Allocated_Length (
int allocated_length)
1044 if (m_Buffer != m_EmptyString)
1046 HEADER *header = Get_Header ();
1047 header->allocated_length = allocated_length;
1051inline void WideStringClass::Store_Length (
int length)
1053 if (m_Buffer != m_EmptyString)
1055 HEADER *header = Get_Header ();
1056 header->length = length;
1060inline bool WideStringClass::Convert_To (StringClass &
string)
1062 return (
string.Copy_Wide (m_Buffer));
1065inline bool WideStringClass::Convert_To (StringClass &
string)
const
1067 return (
string.Copy_Wide (m_Buffer));
1070struct hash_istring:
public std::unary_function<const char*, size_t>
1072 size_t operator()(
const char* str)
const
1075 unsigned long hash = 5381;
1076 while (
int c = tolower(*str++)) hash = hash * 33 + c;
1080 size_t operator()(
const StringClass& str)
const
1082 return (*
this)(str.Peek_Buffer());
1086struct equals_istring:
public std::binary_function<const char*, const char*, bool>
1088 bool operator()(
const char* a,
const char* b)
const
1090 return _stricmp(a, b) == 0;
1093 size_t operator()(
const StringClass& a,
const StringClass& b)
const
1095 return _stricmp(a.Peek_Buffer(), b.Peek_Buffer()) == 0;
1098 size_t operator()(
const StringClass& a,
const char* b)
const
1100 return _stricmp(a.Peek_Buffer(), b) == 0;
1103 size_t operator()(
const char* a,
const StringClass& b)
const
1105 return _stricmp(a, b.Peek_Buffer()) == 0;
1111 size_t operator()(
const char* str)
const
1114 unsigned long hash = 5381;
1115 while (
int c = *str++) hash = hash * 33 + c;
1119 size_t operator()(
const StringClass& str)
const
1121 return (*
this)(str.Peek_Buffer());
1127 bool operator()(
const char* a,
const char* b)
const
1129 return strcmp(a, b) == 0;
1132 size_t operator()(
const StringClass& a,
const StringClass& b)
const
1134 return strcmp(a.Peek_Buffer(), b.Peek_Buffer()) == 0;
1137 size_t operator()(
const StringClass& a,
const char* b)
const
1139 return strcmp(a.Peek_Buffer(), b) == 0;
1142 size_t operator()(
const char* a,
const StringClass& b)
const
1144 return strcmp(a, b.Peek_Buffer()) == 0;
1148SCRIPTS_API
const wchar_t *CharToWideChar(
const char *str);
1149SCRIPTS_API
const char *WideCharToChar(
const wchar_t *wcs);
1150SCRIPTS_API
char *newstr(
const char *str);
1151SCRIPTS_API
wchar_t *newwcs(
const wchar_t *str);
1152SCRIPTS_API
char *strtrim(
char *);
1153SCRIPTS_API
char* strrtrim(
char *);
1154SCRIPTS_API
const char *stristr(
const char *str,
const char *substr);
1155SCRIPTS_API
const wchar_t *wcsistr(
const wchar_t *str,
const wchar_t *substr);