2 * Copyright 2004-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
3 * Distributed under the terms of the MIT License.
8 #include "HashString.h"
12 \brief A very simple string class.
16 HashString::HashString()
23 HashString::HashString(const HashString
&string
)
31 HashString::HashString(const char *string
, int32 length
)
35 SetTo(string
, length
);
39 HashString::~HashString()
46 HashString::SetTo(const char *string
, int32 maxLength
)
50 maxLength
= strnlen(string
, maxLength
);
51 else if (maxLength
< 0)
52 maxLength
= strlen(string
);
54 return _SetTo(string
, maxLength
);
70 HashString::Truncate(int32 newLength
)
74 if (newLength
< fLength
) {
75 char *string
= fString
;
77 if (!_SetTo(string
, newLength
)) {
80 fString
[fLength
] = '\0';
88 HashString::GetString() const
97 HashString::operator=(const HashString
&string
)
100 _SetTo(string
.fString
, string
.fLength
);
106 HashString::operator==(const HashString
&string
) const
108 return (fLength
== string
.fLength
109 && (fLength
== 0 || !strcmp(fString
, string
.fString
)));
114 HashString::_SetTo(const char *string
, int32 length
)
118 if (string
&& length
> 0) {
119 fString
= new(std::nothrow
) char[length
+ 1];
121 memcpy(fString
, string
, length
);
122 fString
[length
] = '\0';