зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1362449 - part 3 - templatify core nsCString base64 encode routine; r=erahm
The nsACString -> nsACString encode routine has several checks in it for correct operation, and the nsAString -> nsAString encode routine relies on those checks happening via the nsACString -> nsACString routine. Once we start encoding nsAStrings directly, we'll still need those checks, and the easiest way to ensure they happen is to move the core base64 encode logic for strings into a templated helper.
This commit is contained in:
Родитель
fe35e37738
Коммит
d68341d832
|
@ -326,8 +326,9 @@ Base64Encode(const char* aBinary, uint32_t aBinaryLen, char** aBase64)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Base64Encode(const nsACString& aBinary, nsACString& aBase64)
|
||||
template<typename T>
|
||||
static nsresult
|
||||
Base64EncodeHelper(const T& aBinary, T& aBase64)
|
||||
{
|
||||
// Check for overflow.
|
||||
if (aBinary.Length() > (UINT32_MAX / 4) * 3) {
|
||||
|
@ -346,7 +347,7 @@ Base64Encode(const nsACString& aBinary, nsACString& aBase64)
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
char* base64 = aBase64.BeginWriting();
|
||||
typename T::char_type* base64 = aBase64.BeginWriting();
|
||||
Encode(aBinary.BeginReading(), aBinary.Length(), base64);
|
||||
base64[base64Len] = '\0';
|
||||
|
||||
|
@ -354,6 +355,12 @@ Base64Encode(const nsACString& aBinary, nsACString& aBase64)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Base64Encode(const nsACString& aBinary, nsACString& aBase64)
|
||||
{
|
||||
return Base64EncodeHelper(aBinary, aBase64);
|
||||
}
|
||||
|
||||
nsresult
|
||||
Base64Encode(const nsAString& aBinary, nsAString& aBase64)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче