Bug 387522. Native JSON support. r=crowder/jst, sr=brendan

This commit is contained in:
sayrer@gmail.com 2007-12-27 13:45:03 -08:00
Родитель bf0d4a7536
Коммит 6977f174a3
2 изменённых файлов: 54 добавлений и 0 удалений

Просмотреть файл

@ -472,6 +472,19 @@ public:
const nsACString& aInput,
nsAString& aOutput);
/**
* Determine whether a buffer begins with a BOM for UTF-8, UTF-16LE,
* UTF-16BE, UTF-32LE, UTF-32BE.
*
* @param aBuffer the buffer to check
* @param aLength the length of the buffer
* @param aCharset empty if not found
* @return boolean indicating whether a BOM was detected.
*/
static PRBool CheckForBOM(const unsigned char* aBuffer, PRUint32 aLength,
nsACString& aCharset);
/**
* Determine whether aContent is in some way associated with aForm. If the
* form is a container the only elements that are considered to be associated

Просмотреть файл

@ -2874,6 +2874,47 @@ nsContentUtils::ConvertStringFromCharset(const nsACString& aCharset,
return rv;
}
/* static */
PRBool
nsContentUtils::CheckForBOM(const unsigned char* aBuffer, PRUint32 aLength,
nsACString& aCharset)
{
PRBool found = PR_TRUE;
aCharset.Truncate();
if (aLength >= 3 &&
aBuffer[0] == 0xEF &&
aBuffer[1] == 0xBB &&
aBuffer[2] == 0xBF) {
aCharset = "UTF-8";
}
else if (aLength >= 4 &&
aBuffer[0] == 0x00 &&
aBuffer[1] == 0x00 &&
aBuffer[2] == 0xFE &&
aBuffer[3] == 0xFF) {
aCharset = "UTF-32BE";
}
else if (aLength >= 4 &&
aBuffer[0] == 0xFF &&
aBuffer[1] == 0xFE &&
aBuffer[2] == 0x00 &&
aBuffer[3] == 0x00) {
aCharset = "UTF-32LE";
}
else if (aLength >= 2 &&
aBuffer[0] == 0xFE && aBuffer[1] == 0xFF) {
aCharset = "UTF-16BE";
}
else if (aLength >= 2 &&
aBuffer[0] == 0xFF && aBuffer[1] == 0xFE) {
aCharset = "UTF-16LE";
} else {
found = PR_FALSE;
}
return found;
}
static PRBool EqualExceptRef(nsIURL* aURL1, nsIURL* aURL2)
{
nsCOMPtr<nsIURI> u1;