* Added missing destructor; fString was leaked. This fixes CIDs 1411-1413.
* Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38421 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
44260788fe
commit
6195b696db
@ -3,10 +3,12 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "DString.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*! \brief Creates a useless, empty string object. */
|
||||
DString::DString()
|
||||
:
|
||||
@ -51,13 +53,19 @@ DString::DString(const char *utf8, uint8 fieldLength)
|
||||
}
|
||||
|
||||
|
||||
DString::~DString()
|
||||
{
|
||||
delete[] fString;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DString::SetTo(const DString &ref)
|
||||
{
|
||||
_Clear();
|
||||
if (ref.Length() > 0) {
|
||||
fString = new(nothrow) uint8[ref.Length()];
|
||||
if (fString) {
|
||||
if (fString != NULL) {
|
||||
fLength = ref.Length();
|
||||
memcpy(fString, ref.String(), fLength);
|
||||
}
|
||||
@ -94,7 +102,7 @@ DString::SetTo(const UdfString &string, uint8 fieldLength)
|
||||
if (destLength < fieldLength - 1)
|
||||
memset(&fString[destLength], 0, fieldLength - 1 - destLength);
|
||||
// Write the string length to the last character in the field
|
||||
fString[fieldLength - 1] = destLength;
|
||||
fString[fieldLength - 1] = destLength;
|
||||
} else {
|
||||
// Empty strings are to contain all zeros
|
||||
memset(fString, 0, fieldLength);
|
||||
@ -120,7 +128,7 @@ void
|
||||
DString::_Clear()
|
||||
{
|
||||
DEBUG_INIT("DString");
|
||||
delete [] fString;
|
||||
delete[] fString;
|
||||
fString = NULL;
|
||||
fLength = 0;
|
||||
}
|
||||
|
@ -2,16 +2,17 @@
|
||||
* Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _D_STRING_H
|
||||
#define _D_STRING_H
|
||||
|
||||
|
||||
#include "UdfDebug.h"
|
||||
|
||||
#include "UdfString.h"
|
||||
|
||||
#include <util/kernel_cpp.h>
|
||||
|
||||
|
||||
/*! \brief Fixed-length d-string class that takes a UdfString as input
|
||||
and provides a properly formatted ECMA-167 d-string of the given
|
||||
field length as ouput.
|
||||
@ -20,23 +21,28 @@
|
||||
*/
|
||||
class DString {
|
||||
public:
|
||||
DString();
|
||||
DString(const DString &ref);
|
||||
DString(const UdfString &string, uint8 fieldLength);
|
||||
DString(const char *utf8, uint8 fieldLength);
|
||||
DString();
|
||||
DString(const DString &ref);
|
||||
DString(const UdfString &string,
|
||||
uint8 fieldLength);
|
||||
DString(const char *utf8, uint8 fieldLength);
|
||||
~DString();
|
||||
|
||||
uint8 Length() const { return fLength; }
|
||||
uint8 Length() const { return fLength; }
|
||||
|
||||
void SetTo(const DString &ref);
|
||||
void SetTo(const UdfString &string, uint8 fieldLength);
|
||||
void SetTo(const char *utf8, uint8 fieldLength);
|
||||
void SetTo(const DString &ref);
|
||||
void SetTo(const UdfString &string, uint8 fieldLength);
|
||||
void SetTo(const char *utf8, uint8 fieldLength);
|
||||
|
||||
const uint8* String() const { return fString; }
|
||||
|
||||
const uint8* String() const { return fString; }
|
||||
private:
|
||||
void _Clear();
|
||||
void _Clear();
|
||||
|
||||
uint8 fLength;
|
||||
uint8 *fString;
|
||||
private:
|
||||
uint8 fLength;
|
||||
uint8 *fString;
|
||||
};
|
||||
|
||||
|
||||
#endif // _D_STRING_H
|
||||
|
Loading…
Reference in New Issue
Block a user