1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the OpenBeOS license.
5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //---------------------------------------------------------------------
20 /*! \brief UdfString class that takes as input either a UTF8 string or a
21 CS0 unicode string and then provides access to said string in both
24 For CS0 info, see: ECMA-167 1/7.2.2 (not very helpful), UDF-2.01 2.1.1
29 UdfString(const char *utf8
);
30 UdfString(const char *cs0
, uint32 length
);
32 template <uint32 length
>
33 UdfString(const array
<char, length
> &dString
);
36 void SetTo(const char *utf8
);
37 void SetTo(const char *cs0
, uint32 length
);
38 template <uint32 length
>
39 void SetTo(const array
<char, length
> &dString
);
41 template <uint32 length
>
42 UdfString
& operator=(const array
<char, length
> &dString
);
44 const char *Cs0() const { return fCs0String
; }
45 const char *Utf8() const { return fUtf8String
; }
46 uint32
Cs0Length() const { return fCs0Length
; }
47 uint32
Utf8Length() const { return fUtf8String
? strlen(fUtf8String
) : 0; }
57 /*! \brief Creates a new UdfString object from the given d-string.
59 template <uint32 length
>
60 UdfString::UdfString(const array
<char, length
> &dString
)
64 TRACE(("UdfString::UdfString: dString.length(): %" B_PRIu32
,
69 /*! \brief Assignment from a d-string.
71 The last byte of a d-string specifies the data length of the
74 template <uint32 length
>
76 UdfString::SetTo(const array
<char, length
> &dString
)
78 uint8 dataLength
= dString
.length() == 0
79 ? 0 : reinterpret_cast<const uint8
*>(dString
.data
)[dString
.length() - 1];
81 || dataLength
== 1 /* technically illegal, but... */) {
84 if (dataLength
> dString
.length() - 1)
85 dataLength
= dString
.length() - 1;
86 SetTo(reinterpret_cast<const char *>(dString
.data
), dataLength
);
90 /*! \brief Assignment from a d-string.
92 template <uint32 length
>
94 UdfString::operator=(const array
<char, length
> &dString
)
100 #endif // _UDF_STRING_H