* 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.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "DString.h"
|
#include "DString.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Creates a useless, empty string object. */
|
/*! \brief Creates a useless, empty string object. */
|
||||||
DString::DString()
|
DString::DString()
|
||||||
:
|
:
|
||||||
@ -51,13 +53,19 @@ DString::DString(const char *utf8, uint8 fieldLength)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DString::~DString()
|
||||||
|
{
|
||||||
|
delete[] fString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DString::SetTo(const DString &ref)
|
DString::SetTo(const DString &ref)
|
||||||
{
|
{
|
||||||
_Clear();
|
_Clear();
|
||||||
if (ref.Length() > 0) {
|
if (ref.Length() > 0) {
|
||||||
fString = new(nothrow) uint8[ref.Length()];
|
fString = new(nothrow) uint8[ref.Length()];
|
||||||
if (fString) {
|
if (fString != NULL) {
|
||||||
fLength = ref.Length();
|
fLength = ref.Length();
|
||||||
memcpy(fString, ref.String(), fLength);
|
memcpy(fString, ref.String(), fLength);
|
||||||
}
|
}
|
||||||
@ -94,7 +102,7 @@ DString::SetTo(const UdfString &string, uint8 fieldLength)
|
|||||||
if (destLength < fieldLength - 1)
|
if (destLength < fieldLength - 1)
|
||||||
memset(&fString[destLength], 0, fieldLength - 1 - destLength);
|
memset(&fString[destLength], 0, fieldLength - 1 - destLength);
|
||||||
// Write the string length to the last character in the field
|
// Write the string length to the last character in the field
|
||||||
fString[fieldLength - 1] = destLength;
|
fString[fieldLength - 1] = destLength;
|
||||||
} else {
|
} else {
|
||||||
// Empty strings are to contain all zeros
|
// Empty strings are to contain all zeros
|
||||||
memset(fString, 0, fieldLength);
|
memset(fString, 0, fieldLength);
|
||||||
@ -120,7 +128,7 @@ void
|
|||||||
DString::_Clear()
|
DString::_Clear()
|
||||||
{
|
{
|
||||||
DEBUG_INIT("DString");
|
DEBUG_INIT("DString");
|
||||||
delete [] fString;
|
delete[] fString;
|
||||||
fString = NULL;
|
fString = NULL;
|
||||||
fLength = 0;
|
fLength = 0;
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,17 @@
|
|||||||
* Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net.
|
* Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _D_STRING_H
|
#ifndef _D_STRING_H
|
||||||
#define _D_STRING_H
|
#define _D_STRING_H
|
||||||
|
|
||||||
|
|
||||||
#include "UdfDebug.h"
|
#include "UdfDebug.h"
|
||||||
|
|
||||||
#include "UdfString.h"
|
#include "UdfString.h"
|
||||||
|
|
||||||
#include <util/kernel_cpp.h>
|
#include <util/kernel_cpp.h>
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Fixed-length d-string class that takes a UdfString as input
|
/*! \brief Fixed-length d-string class that takes a UdfString as input
|
||||||
and provides a properly formatted ECMA-167 d-string of the given
|
and provides a properly formatted ECMA-167 d-string of the given
|
||||||
field length as ouput.
|
field length as ouput.
|
||||||
@ -20,23 +21,28 @@
|
|||||||
*/
|
*/
|
||||||
class DString {
|
class DString {
|
||||||
public:
|
public:
|
||||||
DString();
|
DString();
|
||||||
DString(const DString &ref);
|
DString(const DString &ref);
|
||||||
DString(const UdfString &string, uint8 fieldLength);
|
DString(const UdfString &string,
|
||||||
DString(const char *utf8, uint8 fieldLength);
|
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 DString &ref);
|
||||||
void SetTo(const UdfString &string, uint8 fieldLength);
|
void SetTo(const UdfString &string, uint8 fieldLength);
|
||||||
void SetTo(const char *utf8, uint8 fieldLength);
|
void SetTo(const char *utf8, uint8 fieldLength);
|
||||||
|
|
||||||
|
const uint8* String() const { return fString; }
|
||||||
|
|
||||||
const uint8* String() const { return fString; }
|
|
||||||
private:
|
private:
|
||||||
void _Clear();
|
void _Clear();
|
||||||
|
|
||||||
uint8 fLength;
|
private:
|
||||||
uint8 *fString;
|
uint8 fLength;
|
||||||
|
uint8 *fString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // _D_STRING_H
|
#endif // _D_STRING_H
|
||||||
|
Loading…
Reference in New Issue
Block a user