- Set up new from-Ut8 constructors.
- Added doxygen to constructors and assignment functions. - Added Utf8() and Cs0() get-string functions (former is mostly functional, latter is in progress). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5588 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#include "CS0String.h"
|
#include "UdfString.h"
|
||||||
|
|
||||||
#include "ByteOrder.h"
|
#include "ByteOrder.h"
|
||||||
|
|
||||||
@@ -30,40 +30,52 @@ Udf::unicode_to_utf8(uint32 c, char **out)
|
|||||||
|
|
||||||
using namespace Udf;
|
using namespace Udf;
|
||||||
|
|
||||||
CS0String::CS0String()
|
/*! \brief Creates an empty string object.
|
||||||
: fUtf8String(NULL)
|
*/
|
||||||
|
String::String()
|
||||||
|
: fCs0String(NULL)
|
||||||
|
, fUtf8String(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CS0String::CS0String(const char *cs0)
|
/*! \brief Creates a new String object from the given Utf8 string.
|
||||||
: fUtf8String(NULL)
|
*/
|
||||||
|
String::String(const char *utf8)
|
||||||
|
: fCs0String(NULL)
|
||||||
|
, fUtf8String(NULL)
|
||||||
{
|
{
|
||||||
SetTo(cs0);
|
SetTo(utf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
CS0String::CS0String(const char *cs0, uint32 length)
|
/*! \brief Creates a new String object from the given Cs0 string.
|
||||||
: fUtf8String(NULL)
|
*/
|
||||||
|
String::String(const char *cs0, uint32 length)
|
||||||
|
: fCs0String(NULL)
|
||||||
|
, fUtf8String(NULL)
|
||||||
{
|
{
|
||||||
SetTo(cs0, length);
|
SetTo(cs0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
CS0String::~CS0String()
|
String::~String()
|
||||||
{
|
{
|
||||||
DEBUG_INIT("CS0String");
|
DEBUG_INIT("String");
|
||||||
|
|
||||||
_Clear();
|
_Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \brief Assignment from a Utf8 string.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
CS0String::SetTo(const char *cs0)
|
String::SetTo(const char *utf8)
|
||||||
{
|
{
|
||||||
SetTo(cs0, strlen(cs0)+1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \brief Assignment from a Cs0 string.
|
||||||
|
*/
|
||||||
void
|
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();
|
_Clear();
|
||||||
|
|
||||||
@@ -123,10 +135,12 @@ CS0String::SetTo(const char *cs0, uint32 length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CS0String::_Clear()
|
String::_Clear()
|
||||||
{
|
{
|
||||||
DEBUG_INIT("CS0String");
|
DEBUG_INIT("String");
|
||||||
|
|
||||||
|
delete [] fCs0String;
|
||||||
|
fCs0String = NULL;
|
||||||
delete [] fUtf8String;
|
delete [] fUtf8String;
|
||||||
fUtf8String = NULL;
|
fUtf8String = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
|
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _UDF_CS0_STRING_H
|
#ifndef _UDF_STRING_H
|
||||||
#define _UDF_CS0_STRING_H
|
#define _UDF_STRING_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -17,58 +17,75 @@
|
|||||||
|
|
||||||
namespace Udf {
|
namespace Udf {
|
||||||
|
|
||||||
/*! \brief String class that takes as input CS0 unicode strings,
|
/*! \brief String class that takes as input either a UTF8 string or a
|
||||||
which it converts to UTF8 upon construction.
|
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
|
For CS0 info, see: ECMA-167 1/7.2.2 (not very helpful), UDF-2.01 2.1.1
|
||||||
*/
|
*/
|
||||||
class CS0String {
|
class String {
|
||||||
public:
|
public:
|
||||||
CS0String();
|
String();
|
||||||
CS0String(const char *cs0);
|
String(const char *utf8);
|
||||||
CS0String(const char *cs0, uint32 length);
|
String(const char *cs0, uint32 length);
|
||||||
template <uint32 length>
|
template <uint32 length>
|
||||||
CS0String(const array<char, length> &cs0);
|
String(const array<char, length> &cs0);
|
||||||
~CS0String();
|
~String();
|
||||||
|
|
||||||
void SetTo(const char *cs0);
|
void SetTo(const char *utf8);
|
||||||
void SetTo(const char *cs0, uint32 length);
|
void SetTo(const char *cs0, uint32 length);
|
||||||
template <uint32 length>
|
template <uint32 length>
|
||||||
void SetTo(const array<char, length> &cs0);
|
void SetTo(const array<char, length> &cs0);
|
||||||
|
|
||||||
template <uint32 length>
|
template <uint32 length>
|
||||||
CS0String& operator=(const array<char, length> &cs0);
|
String& operator=(const array<char, length> &cs0);
|
||||||
|
|
||||||
const char* String() const { return fUtf8String; }
|
// const char* Cs0() const { return fCs0String; }
|
||||||
uint32 Length() const { return fUtf8String ? strlen(fUtf8String) : 0; }
|
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:
|
private:
|
||||||
void _Clear();
|
void _Clear();
|
||||||
|
|
||||||
|
static const char * const kTempCs0String = "\x08Ih8Unicode";
|
||||||
|
static const uint32 kTempCs0Length = 12;
|
||||||
|
|
||||||
|
char *fCs0String;
|
||||||
|
uint32 fCs0Length;
|
||||||
char *fUtf8String;
|
char *fUtf8String;
|
||||||
};
|
};
|
||||||
|
|
||||||
void unicode_to_utf8(uint32 c, char **out);
|
void unicode_to_utf8(uint32 c, char **out);
|
||||||
|
|
||||||
|
/*! \brief Creates a new String object from the given Cs0 string.
|
||||||
|
*/
|
||||||
template <uint32 length>
|
template <uint32 length>
|
||||||
CS0String::CS0String(const array<char, length> &cs0)
|
String::String(const array<char, length> &cs0)
|
||||||
: fUtf8String(NULL)
|
: fCs0String(NULL)
|
||||||
|
, fUtf8String(NULL)
|
||||||
{
|
{
|
||||||
DEBUG_INIT("CS0String");
|
DEBUG_INIT_ETC("String", ("cs0.length(): %ld", cs0.length()));
|
||||||
|
|
||||||
SetTo(cs0);
|
SetTo(cs0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \brief Assignment from a Cs0 string.
|
||||||
|
*/
|
||||||
template <uint32 length>
|
template <uint32 length>
|
||||||
void
|
void
|
||||||
CS0String::SetTo(const array<char, length> &cs0)
|
String::SetTo(const array<char, length> &cs0)
|
||||||
{
|
{
|
||||||
SetTo(reinterpret_cast<const char*>(cs0.data), length);
|
SetTo(reinterpret_cast<const char*>(cs0.data), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \brief Assignment from a Cs0 string.
|
||||||
|
*/
|
||||||
template <uint32 length>
|
template <uint32 length>
|
||||||
CS0String&
|
String&
|
||||||
CS0String::operator=(const array<char, length> &cs0)
|
String::operator=(const array<char, length> &cs0)
|
||||||
{
|
{
|
||||||
SetTo(cs0);
|
SetTo(cs0);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -79,4 +96,4 @@ CS0String::operator=(const array<char, length> &cs0)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _UDF_CS0_STRING_H
|
#endif // _UDF_STRING_H
|
||||||
|
|||||||
Reference in New Issue
Block a user