Bug 1306329 part A - nsUTF8Utils is used from outside libxul, and NS_WARNING now only works from within libxul, so make its usage conditional, r=froydnj
draft
Bug 1306329 part A - nsUTF8Utils is used from outside libxul, and NS_WARNING now only works from within libxul, so make its usage conditional, r=froydnj
MozReview-Commit-ID: HRYpj8C9c5k
--- a/xpcom/string/nsUTF8Utils.h
+++ b/xpcom/string/nsUTF8Utils.h
@@ -12,16 +12,22 @@
#include "nscore.h"
#include "mozilla/Assertions.h"
#include "mozilla/SSE.h"
#include "mozilla/TypeTraits.h"
#include "nsCharTraits.h"
+#ifdef MOZILLA_INTERNAL_API
+#define UTF8UTILS_WARNING(msg) NS_WARNING(msg)
+#else
+#define UTF8UTILS_WARNING(msg)
+#endif
+
class UTF8traits
{
public:
static bool isASCII(char aChar)
{
return (aChar & 0x80) == 0x00;
}
static bool isInSeq(char aChar)
@@ -205,17 +211,17 @@ public:
*aBuffer = p;
return c;
} else if (NS_IS_HIGH_SURROGATE(c)) { // U+D800 - U+DBFF
if (p == aEnd) {
// Found a high surrogate at the end of the buffer. Flag this
// as an error and return the Unicode replacement
// character 0xFFFD.
- NS_WARNING("Unexpected end of buffer after high surrogate");
+ UTF8UTILS_WARNING("Unexpected end of buffer after high surrogate");
if (aErr) {
*aErr = true;
}
*aBuffer = p;
return 0xFFFD;
}
@@ -238,32 +244,32 @@ public:
// a low surrogate. Flag this as an error and return the
// Unicode replacement character 0xFFFD. Note that the
// pointer to the next character points to the second 16-bit
// value, not beyond it, as per Unicode 5.0.0 Chapter 3 C10,
// only the first code unit of an illegal sequence must be
// treated as an illegally terminated code unit sequence
// (also Chapter 3 D91, "isolated [not paired and ill-formed]
// UTF-16 code units in the range D800..DFFF are ill-formed").
- NS_WARNING("got a High Surrogate but no low surrogate");
+ UTF8UTILS_WARNING("got a High Surrogate but no low surrogate");
if (aErr) {
*aErr = true;
}
*aBuffer = p - 1;
return 0xFFFD;
}
} else { // U+DC00 - U+DFFF
// DC00- DFFF - Low Surrogate
// Found a low surrogate w/o a preceding high surrogate. Flag
// this as an error and return the Unicode replacement
// character 0xFFFD.
- NS_WARNING("got a low Surrogate but no high surrogate");
+ UTF8UTILS_WARNING("got a low Surrogate but no high surrogate");
if (aErr) {
*aErr = true;
}
*aBuffer = p;
return 0xFFFD;
}
MOZ_ASSERT_UNREACHABLE("Impossible UCS-2 character value.");
@@ -487,17 +493,17 @@ public:
if (p == end) {
// Treat broken characters as the Unicode
// replacement character 0xFFFD (0xEFBFBD in
// UTF-8)
*out++ = '\xEF';
*out++ = '\xBF';
*out++ = '\xBD';
- NS_WARNING("String ending in half a surrogate pair!");
+ UTF8UTILS_WARNING("String ending in half a surrogate pair!");
break;
}
c = *p;
if (NS_IS_LOW_SURROGATE(c)) {
// DC00- DFFF - Low Surrogate
// N = (H - D800) *400 + 10000 + ( L - DC00 )
@@ -520,27 +526,27 @@ public:
// 16-bit value, not beyond it, as per Unicode 5.0.0
// Chapter 3 C10, only the first code unit of an illegal
// sequence must be treated as an illegally terminated
// code unit sequence (also Chapter 3 D91, "isolated [not
// paired and ill-formed] UTF-16 code units in the range
// D800..DFFF are ill-formed").
p--;
- NS_WARNING("got a High Surrogate but no low surrogate");
+ UTF8UTILS_WARNING("got a High Surrogate but no low surrogate");
}
} else { // U+DC00 - U+DFFF
// Treat broken characters as the Unicode replacement
// character 0xFFFD (0xEFBFBD in UTF-8)
*out++ = '\xEF';
*out++ = '\xBF';
*out++ = '\xBD';
// DC00- DFFF - Low Surrogate
- NS_WARNING("got a low Surrogate but no high surrogate");
+ UTF8UTILS_WARNING("got a low Surrogate but no high surrogate");
}
}
mBuffer = out;
}
void write_terminator()
{
@@ -586,17 +592,17 @@ public:
} else if (0xD800 == (0xFC00 & c)) { // U+D800 - U+DBFF
++p;
if (p == end) {
// Treat broken characters as the Unicode
// replacement character 0xFFFD (0xEFBFBD in
// UTF-8)
mSize += 3;
- NS_WARNING("String ending in half a surrogate pair!");
+ UTF8UTILS_WARNING("String ending in half a surrogate pair!");
break;
}
c = *p;
if (0xDC00 == (0xFC00 & c)) {
mSize += 4;
} else {
@@ -609,24 +615,24 @@ public:
// the one beyond it, as per Unicode 5.0.0 Chapter 3 C10,
// only the first code unit of an illegal sequence must
// be treated as an illegally terminated code unit
// sequence (also Chapter 3 D91, "isolated [not paired and
// ill-formed] UTF-16 code units in the range D800..DFFF
// are ill-formed").
p--;
- NS_WARNING("got a high Surrogate but no low surrogate");
+ UTF8UTILS_WARNING("got a high Surrogate but no low surrogate");
}
} else { // U+DC00 - U+DFFF
// Treat broken characters as the Unicode replacement
// character 0xFFFD (0xEFBFBD in UTF-8)
mSize += 3;
- NS_WARNING("got a low Surrogate but no high surrogate");
+ UTF8UTILS_WARNING("got a low Surrogate but no high surrogate");
}
}
}
private:
size_t mSize;
};
@@ -734,9 +740,11 @@ RewindToPriorUTF8Codepoint(const Char* u
"UTF-8 data must be in 8-bit units");
static_assert(mozilla::IsUnsigned<UnsignedT>::value, "index type must be unsigned");
while (index > 0 && (utf8Chars[index] & 0xC0) == 0x80)
--index;
return index;
}
+#undef UTF8UTILS_WARNING
+
#endif /* !defined(nsUTF8Utils_h_) */