- Actually set Cs0 length in Cs0 SetTo() now.
- Updated constructors/SetTo()s that take array<char> params to expect d-strings instead of Cs0 strings. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6088 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
3bfc8fdd89
commit
8c32c26731
@ -226,6 +226,8 @@ String::SetTo(const char *cs0, uint32 length)
|
||||
DEBUG_INIT_ETC("String", ("cs0: %p, length: %ld", cs0, length));
|
||||
|
||||
_Clear();
|
||||
if (length == 0)
|
||||
return;
|
||||
if (!cs0) {
|
||||
PRINT(("passed NULL cs0 string\n"));
|
||||
return;
|
||||
@ -235,6 +237,7 @@ String::SetTo(const char *cs0, uint32 length)
|
||||
fCs0String = new(nothrow) char[length];
|
||||
if (fCs0String) {
|
||||
memcpy(fCs0String, cs0, length);
|
||||
fCs0Length = length;
|
||||
} else {
|
||||
PRINT(("new fCs0String[%ld] allocation failed\n", length));
|
||||
return;
|
||||
|
@ -29,16 +29,16 @@ public:
|
||||
String(const char *utf8);
|
||||
String(const char *cs0, uint32 length);
|
||||
template <uint32 length>
|
||||
String(const array<char, length> &cs0);
|
||||
String(const array<char, length> &dString);
|
||||
~String();
|
||||
|
||||
void SetTo(const char *utf8);
|
||||
void SetTo(const char *cs0, uint32 length);
|
||||
template <uint32 length>
|
||||
void SetTo(const array<char, length> &cs0);
|
||||
void SetTo(const array<char, length> &dString);
|
||||
|
||||
template <uint32 length>
|
||||
String& operator=(const array<char, length> &cs0);
|
||||
String& operator=(const array<char, length> &dString);
|
||||
|
||||
const char* Cs0() const { return fCs0String; }
|
||||
const char* Utf8() const { return fUtf8String; }
|
||||
@ -53,34 +53,48 @@ private:
|
||||
char *fUtf8String;
|
||||
};
|
||||
|
||||
/*! \brief Creates a new String object from the given Cs0 string.
|
||||
/*! \brief Creates a new String object from the given d-string.
|
||||
*/
|
||||
template <uint32 length>
|
||||
String::String(const array<char, length> &cs0)
|
||||
String::String(const array<char, length> &dString)
|
||||
: fCs0String(NULL)
|
||||
, fUtf8String(NULL)
|
||||
{
|
||||
DEBUG_INIT_ETC("String", ("cs0.length(): %ld", cs0.length()));
|
||||
|
||||
SetTo(cs0);
|
||||
DEBUG_INIT_ETC("String", ("dString.length(): %ld", dString.length()));
|
||||
|
||||
SetTo(dString);
|
||||
}
|
||||
|
||||
/*! \brief Assignment from a Cs0 string.
|
||||
/*! \brief Assignment from a d-string.
|
||||
|
||||
The last byte of a d-string specifies the data length of the
|
||||
enclosed Cs0 string.
|
||||
*/
|
||||
template <uint32 length>
|
||||
void
|
||||
String::SetTo(const array<char, length> &cs0)
|
||||
String::SetTo(const array<char, length> &dString)
|
||||
{
|
||||
SetTo(reinterpret_cast<const char*>(cs0.data), length);
|
||||
uint8 dataLength = dString.length() == 0
|
||||
? 0
|
||||
: reinterpret_cast<const uint8*>(dString.data)[dString.length()-1];
|
||||
if (dataLength == 0
|
||||
|| dataLength == 1 /* technically illegal, but... */)
|
||||
{
|
||||
SetTo(NULL);
|
||||
} else {
|
||||
if (dataLength > dString.length()-1)
|
||||
dataLength = dString.length()-1;
|
||||
SetTo(reinterpret_cast<const char*>(dString.data), dataLength);
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Assignment from a Cs0 string.
|
||||
/*! \brief Assignment from a d-string.
|
||||
*/
|
||||
template <uint32 length>
|
||||
String&
|
||||
String::operator=(const array<char, length> &cs0)
|
||||
String::operator=(const array<char, length> &dString)
|
||||
{
|
||||
SetTo(cs0);
|
||||
SetTo(dString);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user