00001 //----------------------------------------------------------------------------- 00002 // Project : SDK Core 00003 // Version : 1.0 00004 // 00005 // Category : Helpers 00006 // Filename : ustring.h 00007 // Created by : Steinberg, 12/2005 00008 // Modified : $Date: 2008/01/09 12:51:43 $ 00009 // Description : UTF-16 String class 00010 // 00011 //----------------------------------------------------------------------------- 00012 // LICENSE 00013 // © 2008, Steinberg Media Technologies GmbH, All Rights Reserved 00014 //----------------------------------------------------------------------------- 00015 // This Software Development Kit may not be distributed in parts or its entirety 00016 // without prior written agreement by Steinberg Media Technologies GmbH. 00017 // This SDK must not be used to re-engineer or manipulate any technology used 00018 // in any Steinberg or Third-party application or software module, 00019 // unless permitted by law. 00020 // Neither the name of the Steinberg Media Technologies nor the names of its 00021 // contributors may be used to endorse or promote products derived from this 00022 // software without specific prior written permission. 00023 // 00024 // THIS SDK IS PROVIDED BY STEINBERG MEDIA TECHNOLOGIES GMBH "AS IS" AND 00025 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00027 // IN NO EVENT SHALL STEINBERG MEDIA TECHNOLOGIES GMBH BE LIABLE FOR ANY DIRECT, 00028 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00031 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00032 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00033 // OF THE POSSIBILITY OF SUCH DAMAGE. 00034 //----------------------------------------------------------------------------- 00035 00036 #ifndef __ustring__ 00037 #define __ustring__ 00038 00039 #include "ftypes.h" 00040 00041 //------------------------------------------------------------------------ 00042 namespace Steinberg { 00043 00044 //------------------------------------------------------------------------ 00046 //------------------------------------------------------------------------ 00047 class UString 00048 { 00049 public: 00050 //------------------------------------------------------------------------ 00051 UString (char16* buffer, int32 size) 00052 : thisBuffer (buffer), 00053 thisSize (size) 00054 {} 00055 00056 int32 getSize () const { return thisSize; } 00057 operator const char16* () const { return thisBuffer; } 00058 00060 int32 getLength () const; 00061 00063 UString& assign (const char16* src, int32 srcSize = -1); 00064 00066 UString& append (const char16* src, int32 srcSize = -1); 00067 00069 const UString& copyTo (char16* dst, int32 dstSize) const; 00070 00072 UString& fromAscii (const char* src, int32 srcSize = -1); 00073 00075 const UString& toAscii (char* dst, int32 dstSize) const; 00076 00078 bool scanInt (int64& value) const; 00079 00081 bool printInt (int64 value); 00082 00084 bool scanFloat (double& value) const; 00085 00087 bool printFloat (double value); 00088 //------------------------------------------------------------------------ 00089 protected: 00090 char16* thisBuffer; 00091 int32 thisSize; 00092 }; 00093 00094 //------------------------------------------------------------------------ 00096 //------------------------------------------------------------------------ 00097 template<int32 maxSize> 00098 class UStringBuffer: public UString 00099 { 00100 public: 00101 //------------------------------------------------------------------------ 00102 UStringBuffer () 00103 : UString (data, maxSize) 00104 { data[0] = 0; } 00105 00107 UStringBuffer (const char16* src, int32 srcSize = -1) 00108 : UString (data, maxSize) 00109 { data[0] = 0; if (src) assign (src, srcSize); } 00110 00112 UStringBuffer (const char* src, int32 srcSize = -1) 00113 : UString (data, maxSize) 00114 { data[0] = 0; if (src) fromAscii (src, srcSize); } 00115 //------------------------------------------------------------------------ 00116 protected: 00117 char16 data[maxSize]; 00118 }; 00119 00120 //------------------------------------------------------------------------ 00121 typedef UStringBuffer<128> UString128; 00122 typedef UStringBuffer<256> UString256; 00123 00124 //------------------------------------------------------------------------ 00125 #define USTRING(asciiString) Steinberg::UString256 (asciiString) 00126 #define USTRINGSIZE(var) (sizeof (var) / sizeof (char16)) 00127 00128 //------------------------------------------------------------------------ 00129 } // namespace Steinberg 00130 00131 #endif