michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsString_h___ michael@0: #define nsString_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #include "nsSubstring.h" michael@0: #include "nsDependentSubstring.h" michael@0: #include "nsReadableUtils.h" michael@0: michael@0: #include michael@0: michael@0: // enable support for the obsolete string API if not explicitly disabled michael@0: #ifndef MOZ_STRING_WITH_OBSOLETE_API michael@0: #define MOZ_STRING_WITH_OBSOLETE_API 1 michael@0: #endif michael@0: michael@0: #if MOZ_STRING_WITH_OBSOLETE_API michael@0: // radix values for ToInteger/AppendInt michael@0: #define kRadix10 (10) michael@0: #define kRadix16 (16) michael@0: #define kAutoDetect (100) michael@0: #define kRadixUnknown (kAutoDetect+1) michael@0: #define IGNORE_CASE (true) michael@0: #endif michael@0: michael@0: michael@0: // declare nsString, et. al. michael@0: #include "string-template-def-unichar.h" michael@0: #include "nsTString.h" michael@0: #include "string-template-undef.h" michael@0: michael@0: // declare nsCString, et. al. michael@0: #include "string-template-def-char.h" michael@0: #include "nsTString.h" michael@0: #include "string-template-undef.h" michael@0: michael@0: static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2"); michael@0: static_assert(sizeof(nsString::char_type) == 2, michael@0: "size of nsString::char_type must be 2"); michael@0: static_assert(nsString::char_type(-1) > nsString::char_type(0), michael@0: "nsString::char_type must be unsigned"); michael@0: static_assert(sizeof(nsCString::char_type) == 1, michael@0: "size of nsCString::char_type must be 1"); michael@0: michael@0: michael@0: /** michael@0: * A helper class that converts a UTF-16 string to ASCII in a lossy manner michael@0: */ michael@0: class NS_LossyConvertUTF16toASCII : public nsAutoCString michael@0: { michael@0: public: michael@0: explicit michael@0: NS_LossyConvertUTF16toASCII( const char16_t* aString ) michael@0: { michael@0: LossyAppendUTF16toASCII(aString, *this); michael@0: } michael@0: michael@0: NS_LossyConvertUTF16toASCII( const char16_t* aString, uint32_t aLength ) michael@0: { michael@0: LossyAppendUTF16toASCII(Substring(aString, aLength), *this); michael@0: } michael@0: michael@0: #ifdef MOZ_USE_CHAR16_WRAPPER michael@0: explicit michael@0: NS_LossyConvertUTF16toASCII( char16ptr_t aString ) michael@0: : NS_LossyConvertUTF16toASCII(static_cast(aString)) {} michael@0: michael@0: NS_LossyConvertUTF16toASCII( char16ptr_t aString, uint32_t aLength ) michael@0: : NS_LossyConvertUTF16toASCII(static_cast(aString), aLength) {} michael@0: #endif michael@0: michael@0: explicit michael@0: NS_LossyConvertUTF16toASCII( const nsAString& aString ) michael@0: { michael@0: LossyAppendUTF16toASCII(aString, *this); michael@0: } michael@0: michael@0: private: michael@0: // NOT TO BE IMPLEMENTED michael@0: NS_LossyConvertUTF16toASCII( char ); michael@0: }; michael@0: michael@0: michael@0: class NS_ConvertASCIItoUTF16 : public nsAutoString michael@0: { michael@0: public: michael@0: explicit michael@0: NS_ConvertASCIItoUTF16( const char* aCString ) michael@0: { michael@0: AppendASCIItoUTF16(aCString, *this); michael@0: } michael@0: michael@0: NS_ConvertASCIItoUTF16( const char* aCString, uint32_t aLength ) michael@0: { michael@0: AppendASCIItoUTF16(Substring(aCString, aLength), *this); michael@0: } michael@0: michael@0: explicit michael@0: NS_ConvertASCIItoUTF16( const nsACString& aCString ) michael@0: { michael@0: AppendASCIItoUTF16(aCString, *this); michael@0: } michael@0: michael@0: private: michael@0: // NOT TO BE IMPLEMENTED michael@0: NS_ConvertASCIItoUTF16( char16_t ); michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * A helper class that converts a UTF-16 string to UTF-8 michael@0: */ michael@0: class NS_ConvertUTF16toUTF8 : public nsAutoCString michael@0: { michael@0: public: michael@0: explicit michael@0: NS_ConvertUTF16toUTF8( const char16_t* aString ) michael@0: { michael@0: AppendUTF16toUTF8(aString, *this); michael@0: } michael@0: michael@0: NS_ConvertUTF16toUTF8( const char16_t* aString, uint32_t aLength ) michael@0: { michael@0: AppendUTF16toUTF8(Substring(aString, aLength), *this); michael@0: } michael@0: michael@0: #ifdef MOZ_USE_CHAR16_WRAPPER michael@0: NS_ConvertUTF16toUTF8( char16ptr_t aString ) : NS_ConvertUTF16toUTF8(static_cast(aString)) {} michael@0: michael@0: NS_ConvertUTF16toUTF8( char16ptr_t aString, uint32_t aLength ) michael@0: : NS_ConvertUTF16toUTF8(static_cast(aString), aLength) {} michael@0: #endif michael@0: michael@0: explicit michael@0: NS_ConvertUTF16toUTF8( const nsAString& aString ) michael@0: { michael@0: AppendUTF16toUTF8(aString, *this); michael@0: } michael@0: michael@0: private: michael@0: // NOT TO BE IMPLEMENTED michael@0: NS_ConvertUTF16toUTF8( char ); michael@0: }; michael@0: michael@0: michael@0: class NS_ConvertUTF8toUTF16 : public nsAutoString michael@0: { michael@0: public: michael@0: explicit michael@0: NS_ConvertUTF8toUTF16( const char* aCString ) michael@0: { michael@0: AppendUTF8toUTF16(aCString, *this); michael@0: } michael@0: michael@0: NS_ConvertUTF8toUTF16( const char* aCString, uint32_t aLength ) michael@0: { michael@0: AppendUTF8toUTF16(Substring(aCString, aLength), *this); michael@0: } michael@0: michael@0: explicit michael@0: NS_ConvertUTF8toUTF16( const nsACString& aCString ) michael@0: { michael@0: AppendUTF8toUTF16(aCString, *this); michael@0: } michael@0: michael@0: private: michael@0: // NOT TO BE IMPLEMENTED michael@0: NS_ConvertUTF8toUTF16( char16_t ); michael@0: }; michael@0: michael@0: michael@0: #ifdef MOZ_USE_CHAR16_WRAPPER michael@0: michael@0: inline char16_t* michael@0: wwc(wchar_t *str) michael@0: { michael@0: return reinterpret_cast(str); michael@0: } michael@0: michael@0: inline wchar_t* michael@0: wwc(char16_t *str) michael@0: { michael@0: return reinterpret_cast(str); michael@0: } michael@0: michael@0: #else michael@0: michael@0: inline char16_t* michael@0: wwc(char16_t *str) michael@0: { michael@0: return str; michael@0: } michael@0: michael@0: #endif michael@0: michael@0: // the following are included/declared for backwards compatibility michael@0: typedef nsAutoString nsVoidableString; michael@0: michael@0: #include "nsDependentString.h" michael@0: #include "nsLiteralString.h" michael@0: #include "nsPromiseFlatString.h" michael@0: michael@0: // need to include these for backwards compatibility michael@0: #include "nsMemory.h" michael@0: #include michael@0: #include michael@0: #include "plhash.h" michael@0: michael@0: #endif // !defined(nsString_h___)