* Clean up

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26882 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Salvatore Benedetto 2008-08-08 23:27:23 +00:00
parent b328324d19
commit d9409b5cda
2 changed files with 64 additions and 57 deletions

View File

@ -1,47 +1,56 @@
/*
* Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net.
* Distributed under the terms of the MIT License.
*/
#include "DString.h"
#include <string.h>
using namespace Udf;
/*! \brief Creates a useless, empty string object.
*/
/*! \brief Creates a useless, empty string object. */
DString::DString()
: fString(NULL)
, fLength(0)
:
fLength(0),
fString(NULL)
{
}
/*! \brief Create a new DString object that is a copy of \a ref.
*/
/*! \brief Create a new DString object that is a copy of \a ref. */
DString::DString(const DString &ref)
: fString(NULL)
, fLength(0)
:
fLength(0),
fString(NULL)
{
SetTo(ref);
}
/*! \brief Creates a new DString \a fieldLength bytes long that contains
at most the first \c (fieldLength-1) bytes of \a string.Cs0().
*/
DString::DString(const Udf::String &string, uint8 fieldLength)
: fString(NULL)
, fLength(0)
*/
DString::DString(const UdfString &string, uint8 fieldLength)
:
fLength(0),
fString(NULL)
{
SetTo(string, fieldLength);
}
/*! \brief Creates a new DString \a fieldLength bytes long that contains
at most the first \c (fieldLength-1) bytes of the Cs0 representation
of the NULL-terminated UTF8 string \a utf8.
*/
*/
DString::DString(const char *utf8, uint8 fieldLength)
: fString(NULL)
, fLength(0)
:
fLength(0),
fString(NULL)
{
SetTo(utf8, fieldLength);
}
void
DString::SetTo(const DString &ref)
{
@ -55,11 +64,12 @@ DString::SetTo(const DString &ref)
}
}
/*! \brief Sets the DString be \a fieldLength bytes long and contain
at most the first \c (fieldLength-1) bytes of \a string.Cs0().
*/
*/
void
DString::SetTo(const Udf::String &string, uint8 fieldLength)
DString::SetTo(const UdfString &string, uint8 fieldLength)
{
_Clear();
if (fieldLength > 0) {
@ -70,44 +80,46 @@ DString::SetTo(const Udf::String &string, uint8 fieldLength)
// Figure out how many bytes to copy
uint32 sourceLength = string.Cs0Length();
if (sourceLength > 0) {
uint8 destLength = sourceLength > uint8(fieldLength-1)
? uint8(fieldLength-1)
: uint8(sourceLength);
uint8 destLength = sourceLength > uint8(fieldLength - 1)
? uint8(fieldLength - 1) : uint8(sourceLength);
// If the source string is 16-bit unicode, make sure any dangling
// half-character at the end of the string is not copied
if (string.Cs0()[1] == '\x10' && destLength > 0 && destLength % 2 == 0)
if (string.Cs0()[1] == '\x10' && destLength > 0
&& destLength % 2 == 0)
destLength--;
// Copy
memcpy(fString, string.Cs0(), destLength);
// Zero any characters between the end of the string and
// the terminating string length character
if (destLength < fieldLength-1)
memset(&fString[destLength], 0, fieldLength-1-destLength);
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);
}
}
}
}
}
/*! \brief Sets the DString be \a fieldLength bytes long and contain
at most the first \c (fieldLength-1) bytes of the Cs0 representation
of the NULL-terminated UTF8 string \a utf8.
*/
*/
void
DString::SetTo(const char *utf8, uint8 fieldLength)
{
Udf::String string(utf8);
UdfString string(utf8);
SetTo(string, fieldLength);
}
void
DString::_Clear()
{
DEBUG_INIT("DString");
DEBUG_INIT("DString");
delete [] fString;
fString = NULL;
fLength = 0;

View File

@ -1,47 +1,42 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
//---------------------------------------------------------------------
/*
* Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net.
* Distributed under the terms of the MIT License.
*/
#ifndef _D_STRING_H
#define _D_STRING_H
#include "kernel_cpp.h"
#include "UdfString.h"
#include "UdfDebug.h"
namespace Udf {
#include "UdfString.h"
/*! \brief Fixed-length d-string class that takes a Udf::String as input
#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.
For d-string info, see: ECMA-167 1/7.2.12, UDF-2.50 2.1.3
*/
class DString {
public:
DString();
DString(const DString &ref);
DString(const Udf::String &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);
void SetTo(const DString &ref);
void SetTo(const Udf::String &string, uint8 fieldLength);
void SetTo(const char *utf8, uint8 fieldLength);
uint8 Length() const { return fLength; }
const uint8* String() const { return fString; }
uint8 Length() const { return fLength; }
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; }
private:
void _Clear();
void _Clear();
uint8 *fString;
uint8 fLength;
uint8 fLength;
uint8 *fString;
};
}; // namespace UDF
#endif // _D_STRING_H