diff --git a/src/add-ons/kernel/file_systems/udf/UdfString.cpp b/src/add-ons/kernel/file_systems/udf/UdfString.cpp index ec622cb8d4..834f90e619 100644 --- a/src/add-ons/kernel/file_systems/udf/UdfString.cpp +++ b/src/add-ons/kernel/file_systems/udf/UdfString.cpp @@ -1,4 +1,4 @@ -#include "CS0String.h" +#include "UdfString.h" #include "ByteOrder.h" @@ -30,40 +30,52 @@ Udf::unicode_to_utf8(uint32 c, char **out) using namespace Udf; -CS0String::CS0String() - : fUtf8String(NULL) +/*! \brief Creates an empty string object. +*/ +String::String() + : fCs0String(NULL) + , fUtf8String(NULL) { } -CS0String::CS0String(const char *cs0) - : fUtf8String(NULL) +/*! \brief Creates a new String object from the given Utf8 string. +*/ +String::String(const char *utf8) + : fCs0String(NULL) + , fUtf8String(NULL) { - SetTo(cs0); + SetTo(utf8); } -CS0String::CS0String(const char *cs0, uint32 length) - : fUtf8String(NULL) +/*! \brief Creates a new String object from the given Cs0 string. +*/ +String::String(const char *cs0, uint32 length) + : fCs0String(NULL) + , fUtf8String(NULL) { SetTo(cs0, length); } -CS0String::~CS0String() +String::~String() { - DEBUG_INIT("CS0String"); + DEBUG_INIT("String"); _Clear(); } +/*! \brief Assignment from a Utf8 string. +*/ void -CS0String::SetTo(const char *cs0) +String::SetTo(const char *utf8) { - SetTo(cs0, strlen(cs0)+1); } +/*! \brief Assignment from a Cs0 string. +*/ void -CS0String::SetTo(const char *cs0, uint32 length) +String::SetTo(const char *cs0, uint32 length) { - DEBUG_INIT("CS0String"); + DEBUG_INIT_ETC("String", ("cs0: %p, length: %ld", cs0, length)); _Clear(); @@ -123,10 +135,12 @@ CS0String::SetTo(const char *cs0, uint32 length) } void -CS0String::_Clear() +String::_Clear() { - DEBUG_INIT("CS0String"); + DEBUG_INIT("String"); + delete [] fCs0String; + fCs0String = NULL; delete [] fUtf8String; fUtf8String = NULL; } diff --git a/src/add-ons/kernel/file_systems/udf/UdfString.h b/src/add-ons/kernel/file_systems/udf/UdfString.h index 8113e94757..38d76f1731 100644 --- a/src/add-ons/kernel/file_systems/udf/UdfString.h +++ b/src/add-ons/kernel/file_systems/udf/UdfString.h @@ -5,8 +5,8 @@ // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net //--------------------------------------------------------------------- -#ifndef _UDF_CS0_STRING_H -#define _UDF_CS0_STRING_H +#ifndef _UDF_STRING_H +#define _UDF_STRING_H #include @@ -17,58 +17,75 @@ namespace Udf { -/*! \brief String class that takes as input CS0 unicode strings, - which it converts to UTF8 upon construction. +/*! \brief String class that takes as input either a UTF8 string or a + CS0 unicode string and then provides access to said string in both + formats. For CS0 info, see: ECMA-167 1/7.2.2 (not very helpful), UDF-2.01 2.1.1 */ -class CS0String { +class String { public: - CS0String(); - CS0String(const char *cs0); - CS0String(const char *cs0, uint32 length); + String(); + String(const char *utf8); + String(const char *cs0, uint32 length); template - CS0String(const array &cs0); - ~CS0String(); + String(const array &cs0); + ~String(); - void SetTo(const char *cs0); + void SetTo(const char *utf8); void SetTo(const char *cs0, uint32 length); template void SetTo(const array &cs0); template - CS0String& operator=(const array &cs0); + String& operator=(const array &cs0); - const char* String() const { return fUtf8String; } - uint32 Length() const { return fUtf8String ? strlen(fUtf8String) : 0; } +// const char* Cs0() const { return fCs0String; } + const char* Cs0() const { return kTempCs0String; } + const char* Utf8() const { return fUtf8String; } +// uint32 Cs0Length() const { return fCs0Length; } + uint32 Cs0Length() const { return kTempCs0Length; } + uint32 Utf8Length() const { return fUtf8String ? strlen(fUtf8String) : 0; } private: void _Clear(); + static const char * const kTempCs0String = "\x08Ih8Unicode"; + static const uint32 kTempCs0Length = 12; + + char *fCs0String; + uint32 fCs0Length; char *fUtf8String; }; void unicode_to_utf8(uint32 c, char **out); +/*! \brief Creates a new String object from the given Cs0 string. +*/ template -CS0String::CS0String(const array &cs0) - : fUtf8String(NULL) +String::String(const array &cs0) + : fCs0String(NULL) + , fUtf8String(NULL) { - DEBUG_INIT("CS0String"); + DEBUG_INIT_ETC("String", ("cs0.length(): %ld", cs0.length())); SetTo(cs0); } +/*! \brief Assignment from a Cs0 string. +*/ template void -CS0String::SetTo(const array &cs0) +String::SetTo(const array &cs0) { SetTo(reinterpret_cast(cs0.data), length); } +/*! \brief Assignment from a Cs0 string. +*/ template -CS0String& -CS0String::operator=(const array &cs0) +String& +String::operator=(const array &cs0) { SetTo(cs0); return *this; @@ -79,4 +96,4 @@ CS0String::operator=(const array &cs0) -#endif // _UDF_CS0_STRING_H +#endif // _UDF_STRING_H