Bug 904985, part 2: Use char16_t for NS_LITERAL_STRING, r=glandium, dbaron.

This commit is contained in:
Joshua Cranmer
2013-09-17 22:43:12 -05:00
parent 42084349d1
commit b01f076a0c
9 changed files with 20 additions and 165 deletions

View File

@@ -16,6 +16,7 @@
#define nsStringAPI_h__
#include "mozilla/Attributes.h"
#include "mozilla/Char16.h"
#include "nsXPCOMStrings.h"
#include "nsISupportsImpl.h"
@@ -1073,31 +1074,15 @@ private:
/**
* literal strings
*
* NOTE: HAVE_CPP_2BYTE_WCHAR_T may be automatically defined for some platforms
* in nscore.h. On other platforms, it may be defined in xpcom-config.h.
* Under GCC, this define should only be set if compiling with -fshort-wchar.
*/
static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2");
static_assert(char16_t(-1) > char16_t(0), "char16_t must be unsigned");
#if defined(HAVE_CPP_CHAR16_T) || defined(HAVE_CPP_2BYTE_WCHAR_T)
#if defined(HAVE_CPP_CHAR16_T)
static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2");
#define NS_LL(s) u##s
#else
static_assert(sizeof(wchar_t) == 2, "size of wchar_t must be 2");
#define NS_LL(s) L##s
#endif
#define NS_MULTILINE_LITERAL_STRING(s) nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
#define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
typedef nsDependentString nsLiteralString;
#else
#define NS_LL(s) s
#define NS_MULTILINE_LITERAL_STRING(s) NS_ConvertASCIItoUTF16(s, uint32_t(sizeof(s)-1))
#define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(s, uint32_t(sizeof(s)-1))
#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const NS_ConvertASCIItoUTF16 n(s, uint32_t(sizeof(s)-1))
typedef NS_ConvertASCIItoUTF16 nsLiteralString;
#endif
#define NS_LL(s) MOZ_UTF16(s)
#define NS_MULTILINE_LITERAL_STRING(s) nsDependentString(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
#define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const nsDependentString n(reinterpret_cast<const nsAString::char_type*>(s), uint32_t((sizeof(s)/2)-1))
typedef nsDependentString nsLiteralString;
/* Check that PRUnichar is unsigned */
static_assert(PRUnichar(-1) > PRUnichar(0), "PRUnichar is by definition an unsigned type");