Bug 1221550 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in intl/; r=smontagu
--- a/intl/locale/nsLocaleService.cpp
+++ b/intl/locale/nsLocaleService.cpp
@@ -12,16 +12,17 @@
#include "nsAutoPtr.h"
#include "nsILocale.h"
#include "nsILocaleService.h"
#include "nsLocale.h"
#include "nsCRT.h"
#include "prprf.h"
#include "nsTArray.h"
#include "nsString.h"
+#include "mozilla/UniquePtr.h"
#include <ctype.h>
#if defined(XP_WIN)
# include "nsWin32Locale.h"
#elif defined(XP_MACOSX)
# include <Carbon/Carbon.h>
#elif defined(XP_UNIX)
@@ -263,44 +264,44 @@ nsLocaleService::GetLocaleFromAcceptLang
char* cPtr1;
char* cPtr2;
int i;
int j;
int countLang = 0;
char acceptLanguageList[NSILOCALE_MAX_ACCEPT_LANGUAGE][NSILOCALE_MAX_ACCEPT_LENGTH];
nsresult result;
- nsAutoArrayPtr<char> input(new char[strlen(acceptLanguage)+1]);
+ auto input = MakeUnique<char[]>(strlen(acceptLanguage)+1);
- strcpy(input, acceptLanguage);
- cPtr1 = input-1;
- cPtr2 = input;
+ strcpy(input.get(), acceptLanguage);
+ cPtr1 = input.get()-1;
+ cPtr2 = input.get();
/* put in standard form */
while (*(++cPtr1)) {
if (isalpha(*cPtr1)) *cPtr2++ = tolower(*cPtr1); /* force lower case */
else if (isspace(*cPtr1)) ; /* ignore any space */
else if (*cPtr1=='-') *cPtr2++ = '_'; /* "-" -> "_" */
else if (*cPtr1=='*') ; /* ignore "*" */
else *cPtr2++ = *cPtr1; /* else unchanged */
}
*cPtr2 = '\0';
countLang = 0;
- if (strchr(input,';')) {
+ if (strchr(input.get(), ';')) {
/* deal with the quality values */
float qvalue[NSILOCALE_MAX_ACCEPT_LANGUAGE];
float qSwap;
float bias = 0.0f;
char* ptrLanguage[NSILOCALE_MAX_ACCEPT_LANGUAGE];
char* ptrSwap;
- cPtr = nsCRT::strtok(input,",",&cPtr2);
+ cPtr = nsCRT::strtok(input.get(),",",&cPtr2);
while (cPtr) {
qvalue[countLang] = 1.0f;
/* add extra parens to get rid of warning */
if ((cPtr1 = strchr(cPtr,';')) != nullptr) {
PR_sscanf(cPtr1,";q=%f",&qvalue[countLang]);
*cPtr1 = '\0';
}
if (strlen(cPtr)<NSILOCALE_MAX_ACCEPT_LANGUAGE) { /* ignore if too long */
@@ -327,17 +328,17 @@ nsLocaleService::GetLocaleFromAcceptLang
}
for ( i=0 ; i<countLang ; i++ ) {
PL_strncpyz(acceptLanguageList[i],ptrLanguage[i],NSILOCALE_MAX_ACCEPT_LENGTH);
}
} else {
/* simple case: no quality values */
- cPtr = nsCRT::strtok(input,",",&cPtr2);
+ cPtr = nsCRT::strtok(input.get(),",",&cPtr2);
while (cPtr) {
if (strlen(cPtr)<NSILOCALE_MAX_ACCEPT_LENGTH) { /* ignore if too long */
PL_strncpyz(acceptLanguageList[countLang++],cPtr,NSILOCALE_MAX_ACCEPT_LENGTH);
if (countLang>=NSILOCALE_MAX_ACCEPT_LENGTH) break; /* quit if too many */
}
cPtr = nsCRT::strtok(cPtr2,",",&cPtr2);
}
}
--- a/intl/uconv/nsUTF8ConverterService.cpp
+++ b/intl/uconv/nsUTF8ConverterService.cpp
@@ -5,16 +5,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsString.h"
#include "nsUTF8ConverterService.h"
#include "nsEscape.h"
#include "nsAutoPtr.h"
#include "nsIUnicodeDecoder.h"
#include "mozilla/dom/EncodingUtils.h"
+#include "mozilla/UniquePtr.h"
using mozilla::dom::EncodingUtils;
NS_IMPL_ISUPPORTS(nsUTF8ConverterService, nsIUTF8ConverterService)
static nsresult
ToUTF8(const nsACString &aString, const char *aCharset,
bool aAllowSubstitution, nsACString &aResult)
@@ -35,23 +36,22 @@ ToUTF8(const nsACString &aString, const
unicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
int32_t srcLen = aString.Length();
int32_t dstLen;
const nsAFlatCString& inStr = PromiseFlatCString(aString);
rv = unicodeDecoder->GetMaxLength(inStr.get(), srcLen, &dstLen);
NS_ENSURE_SUCCESS(rv, rv);
- nsAutoArrayPtr<char16_t> ustr(new char16_t[dstLen]);
+ auto ustr = mozilla::MakeUnique<char16_t[]>(dstLen);
NS_ENSURE_TRUE(ustr, NS_ERROR_OUT_OF_MEMORY);
- rv = unicodeDecoder->Convert(inStr.get(), &srcLen, ustr, &dstLen);
+ rv = unicodeDecoder->Convert(inStr.get(), &srcLen, ustr.get(), &dstLen);
if (NS_SUCCEEDED(rv)){
- // Tru64 Cxx needs an explicit get()
- CopyUTF16toUTF8(Substring(ustr.get(), ustr + dstLen), aResult);
+ CopyUTF16toUTF8(Substring(ustr.get(), ustr.get() + dstLen), aResult);
}
return rv;
}
NS_IMETHODIMP
nsUTF8ConverterService::ConvertStringToUTF8(const nsACString &aString,
const char *aCharset,
bool aSkipCheck,
--- a/intl/uconv/util/nsUnicodeDecodeHelper.cpp
+++ b/intl/uconv/util/nsUnicodeDecodeHelper.cpp
@@ -1,16 +1,16 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "unicpriv.h"
#include "nsUnicodeDecodeHelper.h"
-#include "nsAutoPtr.h"
+#include "mozilla/UniquePtr.h"
//----------------------------------------------------------------------
// Class nsUnicodeDecodeHelper [implementation]
nsresult nsUnicodeDecodeHelper::ConvertByTable(
const char * aSrc,
int32_t * aSrcLength,
char16_t * aDest,
int32_t * aDestLength,
@@ -219,16 +219,16 @@ nsresult nsUnicodeDecodeHelper::ConvertB
nsresult nsUnicodeDecodeHelper::CreateFastTable(
uMappingTable * aMappingTable,
char16_t * aFastTable,
int32_t aTableSize)
{
int32_t tableSize = aTableSize;
int32_t buffSize = aTableSize;
- nsAutoArrayPtr<char> buff(new char [buffSize]);
+ auto buff = mozilla::MakeUnique<char[]>(buffSize);
- char * p = buff;
+ char * p = buff.get();
for (int32_t i=0; i<aTableSize; i++) *(p++) = i;
- return ConvertByTable(buff, &buffSize, aFastTable, &tableSize,
+ return ConvertByTable(buff.get(), &buffSize, aFastTable, &tableSize,
u1ByteCharset, nullptr, aMappingTable);
}