Bug 1362194 - part 1 - add a fallible CopyASCIItoUTF16 function; r=mccr8

We already have all the machinery to expose a function like this, we
just need to write it.
This commit is contained in:
Nathan Froyd
2017-05-05 11:33:36 -04:00
parent 77c6e243b5
commit e5e6dfef1d
2 changed files with 14 additions and 1 deletions

View File

@@ -87,9 +87,20 @@ LossyCopyUTF16toASCII(const nsAString& aSource, nsACString& aDest)
void
CopyASCIItoUTF16(const nsACString& aSource, nsAString& aDest)
{
if (!CopyASCIItoUTF16(aSource, aDest, mozilla::fallible)) {
// Note that this may wildly underestimate the allocation that failed, as
// we report the length of aSource as UTF-16 instead of UTF-8.
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
bool
CopyASCIItoUTF16(const nsACString& aSource, nsAString& aDest,
const mozilla::fallible_t& aFallible)
{
aDest.Truncate();
AppendASCIItoUTF16(aSource, aDest);
return AppendASCIItoUTF16(aSource, aDest, aFallible);
}
void