This commit is contained in:
tor%cs.brown.edu 2003-10-27 17:00:38 +00:00
Родитель 0ed88eb6e1
Коммит 9d3e99b64f
4 изменённых файлов: 1 добавлений и 87 удалений

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

@ -78,9 +78,6 @@
#include "nsIAtom.h" #include "nsIAtom.h"
// For locale aware string methods // For locale aware string methods
#include "plstr.h"
#include "nsIPlatformCharset.h"
#include "nsICharsetConverterManager.h"
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
#include "nsILocaleService.h" #include "nsILocaleService.h"
#include "nsICollation.h" #include "nsICollation.h"
@ -137,7 +134,6 @@ static nsIScriptSecurityManager *sSecurityManager;
static nsICollation *gCollation; static nsICollation *gCollation;
static nsIUnicodeDecoder *gDecoder;
void JS_DLL_CALLBACK void JS_DLL_CALLBACK
NS_ScriptErrorReporter(JSContext *cx, NS_ScriptErrorReporter(JSContext *cx,
@ -302,78 +298,6 @@ NS_ScriptErrorReporter(JSContext *cx,
::JS_ClearPendingException(cx); ::JS_ClearPendingException(cx);
} }
static JSBool JS_DLL_CALLBACK
LocaleToUnicode(JSContext *cx, char *src, jsval *rval)
{
nsresult rv;
if (!gDecoder) {
// use app default locale
nsCOMPtr<nsILocaleService> localeService =
do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsILocale> appLocale;
rv = localeService->GetApplicationLocale(getter_AddRefs(appLocale));
if (NS_SUCCEEDED(rv)) {
nsXPIDLString locale;
rv = appLocale->
GetCategory(NS_LITERAL_STRING("NSILOCALE_TIME##PLATFORM").get(),
getter_Copies(locale));
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get app locale info");
nsCOMPtr<nsIPlatformCharset> platformCharset =
do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCAutoString charset;
rv = platformCharset->GetDefaultCharsetForLocale(locale, charset);
if (NS_SUCCEEDED(rv)) {
// get/create unicode decoder for charset
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
ccm->GetUnicodeDecoder(charset.get(), &gDecoder);
}
}
}
}
}
JSString *str = nsnull;
PRInt32 srcLength = PL_strlen(src);
if (gDecoder) {
PRInt32 unicharLength = srcLength;
PRUnichar *unichars = (PRUnichar *)malloc(srcLength * sizeof(PRUnichar));
if (unichars) {
rv = gDecoder->Convert(src, &srcLength, unichars, &unicharLength);
if (NS_SUCCEEDED(rv)) {
// nsIUnicodeDecoder::Convert may use fewer than srcLength PRUnichars
if (unicharLength < srcLength) {
PRUnichar *shrunkUnichars =
(PRUnichar *)realloc(unichars, unicharLength * sizeof(PRUnichar));
if (shrunkUnichars)
unichars = shrunkUnichars;
}
str = JS_NewUCString(cx,
NS_REINTERPRET_CAST(jschar*, unichars),
unicharLength);
}
if (!str)
free(unichars);
}
}
if (!str) {
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED);
return JS_FALSE;
}
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
static JSBool static JSBool
ChangeCase(JSContext *cx, JSString *src, jsval *rval, ChangeCase(JSContext *cx, JSString *src, jsval *rval,
void(* changeCaseFnc)(const nsAString&, nsAString&)) void(* changeCaseFnc)(const nsAString&, nsAString&))
@ -603,8 +527,7 @@ nsJSContext::nsJSContext(JSRuntime *aRuntime) : mGCOnDestruction(PR_TRUE)
{ {
LocaleToUpperCase, LocaleToUpperCase,
LocaleToLowerCase, LocaleToLowerCase,
LocaleCompare, LocaleCompare
LocaleToUnicode
}; };
::JS_SetLocaleCallbacks(mContext, &localeCallbacks); ::JS_SetLocaleCallbacks(mContext, &localeCallbacks);
@ -659,7 +582,6 @@ nsJSContext::~nsJSContext()
NS_IF_RELEASE(sRuntimeService); NS_IF_RELEASE(sRuntimeService);
NS_IF_RELEASE(sSecurityManager); NS_IF_RELEASE(sSecurityManager);
NS_IF_RELEASE(gCollation); NS_IF_RELEASE(gCollation);
NS_IF_RELEASE(gDecoder);
} }
} }
@ -1988,7 +1910,6 @@ void nsJSEnvironment::ShutDown()
NS_IF_RELEASE(sRuntimeService); NS_IF_RELEASE(sRuntimeService);
NS_IF_RELEASE(sSecurityManager); NS_IF_RELEASE(sSecurityManager);
NS_IF_RELEASE(gCollation); NS_IF_RELEASE(gCollation);
NS_IF_RELEASE(gDecoder);
} }
sDidShutdown = PR_TRUE; sDidShutdown = PR_TRUE;

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

@ -1524,7 +1524,6 @@ struct JSLocaleCallbacks {
JSLocaleToUpperCase localeToUpperCase; JSLocaleToUpperCase localeToUpperCase;
JSLocaleToLowerCase localeToLowerCase; JSLocaleToLowerCase localeToLowerCase;
JSLocaleCompare localeCompare; JSLocaleCompare localeCompare;
JSLocaleToUnicode localeToUnicode;
}; };
/* /*

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

@ -1640,9 +1640,6 @@ date_toLocaleHelper(JSContext *cx, JSObject *obj, uintN argc,
} }
if (cx->localeCallbacks && cx->localeCallbacks->localeToUnicode)
return cx->localeCallbacks->localeToUnicode(cx, buf, rval);
str = JS_NewStringCopyZ(cx, buf); str = JS_NewStringCopyZ(cx, buf);
if (!str) if (!str)
return JS_FALSE; return JS_FALSE;

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

@ -527,9 +527,6 @@ typedef JSBool
JSString *src1, JSString *src2, JSString *src1, JSString *src2,
jsval *rval); jsval *rval);
typedef JSBool
(* JS_DLL_CALLBACK JSLocaleToUnicode)(JSContext *cx, char *src, jsval *rval);
/* /*
* Security protocol types. * Security protocol types.
*/ */