Bug 1444329 - Remove nsIScriptableUnicodeConverter::convertFromByteArray. r?hsivonen
MozReview-Commit-ID: IPgCK6slIqj
--- a/intl/uconv/nsIScriptableUConv.idl
+++ b/intl/uconv/nsIScriptableUConv.idl
@@ -37,22 +37,16 @@ interface nsIScriptableUnicodeConverter
ACString Finish();
/**
* Converts the data from one Charset to Unicode.
*/
AString ConvertToUnicode(in ACString aSrc);
/**
- * Converts an array of bytes to a unicode string.
- */
- AString convertFromByteArray([const,array,size_is(aCount)] in octet aData,
- in unsigned long aCount);
-
- /**
* Convert a unicode string to an array of bytes. Finish does not need to be
* called.
*/
void convertToByteArray(in AString aString,
[optional] out unsigned long aLen,
[array, size_is(aLen),retval] out octet aData);
/**
--- a/intl/uconv/nsScriptableUConv.cpp
+++ b/intl/uconv/nsScriptableUConv.cpp
@@ -109,40 +109,31 @@ nsScriptableUnicodeConverter::Finish(nsA
mDecoder->Encoding()->NewDecoderWithBOMRemovalInto(*mDecoder);
mEncoder->Encoding()->NewEncoderInto(*mEncoder);
return NS_OK;
}
NS_IMETHODIMP
nsScriptableUnicodeConverter::ConvertToUnicode(const nsACString& aSrc, nsAString& _retval)
{
- return ConvertFromByteArray(
- reinterpret_cast<const uint8_t*>(aSrc.BeginReading()),
- aSrc.Length(),
- _retval);
-}
-
-NS_IMETHODIMP
-nsScriptableUnicodeConverter::ConvertFromByteArray(const uint8_t* aData,
- uint32_t aCount,
- nsAString& _retval)
-{
if (!mDecoder)
return NS_ERROR_FAILURE;
- CheckedInt<size_t> needed = mDecoder->MaxUTF16BufferLength(aCount);
+ uint32_t length = aSrc.Length();
+
+ CheckedInt<size_t> needed = mDecoder->MaxUTF16BufferLength(length);
if (!needed.isValid() || needed.value() > UINT32_MAX) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!_retval.SetLength(needed.value(), fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
- auto src = MakeSpan(aData, aCount);
+ auto src = MakeSpan(reinterpret_cast<const uint8_t*>(aSrc.BeginReading()), length);
uint32_t result;
size_t read;
size_t written;
bool hadErrors;
// The UTF-8 decoder used to throw regardless of the error behavior.
// Simulating the old behavior for compatibility with legacy callers.
// If callers want control over the behavior, they should switch to
// TextDecoder.
@@ -152,17 +143,17 @@ nsScriptableUnicodeConverter::ConvertFro
if (result != kInputEmpty) {
return NS_ERROR_UDEC_ILLEGALINPUT;
}
} else {
Tie(result, read, written, hadErrors) =
mDecoder->DecodeToUTF16(src, _retval, false);
}
MOZ_ASSERT(result == kInputEmpty);
- MOZ_ASSERT(read == aCount);
+ MOZ_ASSERT(read == length);
MOZ_ASSERT(written <= needed.value());
Unused << hadErrors;
if (!_retval.SetLength(written, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}