mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 13:25:37 +00:00
add new unicode-friendly pref accessors
(prefs will be stored in UTF8) preparation for #20405, r=nhotta
This commit is contained in:
parent
a7e0325cf6
commit
5f6698699e
@ -106,6 +106,7 @@ interface nsIPref : nsISupports {
|
|||||||
|
|
||||||
/* set preferences */
|
/* set preferences */
|
||||||
void SetCharPref(in string pref, in string value);
|
void SetCharPref(in string pref, in string value);
|
||||||
|
void SetUnicharPref(in string pref, in wstring value);
|
||||||
void SetIntPref(in string pref, in long value);
|
void SetIntPref(in string pref, in long value);
|
||||||
void SetBoolPref(in string pref, in boolean value);
|
void SetBoolPref(in string pref, in boolean value);
|
||||||
[noscript] void SetBinaryPref(in string pref, in voidStar value, in unsigned long size);
|
[noscript] void SetBinaryPref(in string pref, in voidStar value, in unsigned long size);
|
||||||
@ -143,6 +144,7 @@ interface nsIPref : nsISupports {
|
|||||||
|
|
||||||
/* copy versions of getters */
|
/* copy versions of getters */
|
||||||
string CopyCharPref(in string pref);
|
string CopyCharPref(in string pref);
|
||||||
|
wstring CopyUnicharPref(in string pref);
|
||||||
[noscript] voidStar CopyBinaryPref(in string pref, out long size);
|
[noscript] voidStar CopyBinaryPref(in string pref, out long size);
|
||||||
|
|
||||||
string CopyDefaultCharPref(in string pref);
|
string CopyDefaultCharPref(in string pref);
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
#include "nsIProfile.h"
|
#include "nsIProfile.h"
|
||||||
#include "nsQuickSort.h"
|
#include "nsQuickSort.h"
|
||||||
|
|
||||||
|
#include "nsTextFormater.h"
|
||||||
|
|
||||||
#include "plhash.h"
|
#include "plhash.h"
|
||||||
#include "prmem.h"
|
#include "prmem.h"
|
||||||
#include "plstr.h"
|
#include "plstr.h"
|
||||||
@ -596,6 +598,21 @@ NS_IMETHODIMP nsPref::SetCharPref(const char *pref,const char* value)
|
|||||||
return _convertRes(PREF_SetCharPref(pref, value));
|
return _convertRes(PREF_SetCharPref(pref, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsPref::SetUnicharPref(const char *pref, const PRUnichar *value)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
nsAutoString str(value);
|
||||||
|
|
||||||
|
char *utf8String = str.ToNewUTF8String();
|
||||||
|
|
||||||
|
if (!utf8String) return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
rv = SetCharPref(pref, utf8String);
|
||||||
|
nsCRT::free(utf8String);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsPref::SetIntPref(const char *pref,PRInt32 value)
|
NS_IMETHODIMP nsPref::SetIntPref(const char *pref,PRInt32 value)
|
||||||
{
|
{
|
||||||
return _convertRes(PREF_SetIntPref(pref, value));
|
return _convertRes(PREF_SetIntPref(pref, value));
|
||||||
@ -726,6 +743,37 @@ NS_IMETHODIMP nsPref::CopyCharPref(const char *pref, char ** return_buf)
|
|||||||
return _convertRes(PREF_CopyCharPref(pref, return_buf));
|
return _convertRes(PREF_CopyCharPref(pref, return_buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unicode "%s" format string
|
||||||
|
static const PRUnichar unicodeFormatter[] = {
|
||||||
|
(PRUnichar)'%',
|
||||||
|
(PRUnichar)'s',
|
||||||
|
(PRUnichar)0,
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsPref::CopyUnicharPref(const char *pref, PRUnichar ** return_buf)
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
|
// get the UTF8 string for conversion
|
||||||
|
char *utf8String;
|
||||||
|
rv = CopyCharPref(pref, &utf8String);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
// convert to PRUnichar using nsTextFormatter
|
||||||
|
// this is so ugly, it allocates memory at least 4 times :(
|
||||||
|
PRUnichar *unicodeString =
|
||||||
|
nsTextFormater::smprintf(unicodeFormatter, utf8String);
|
||||||
|
PL_strfree(utf8String);
|
||||||
|
if (!unicodeString) return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
// use the right allocator
|
||||||
|
*return_buf = nsCRT::strdup(unicodeString);
|
||||||
|
nsTextFormater::smprintf_free(unicodeString);
|
||||||
|
if (!*return_buf) return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsPref::CopyBinaryPref(const char *pref,
|
NS_IMETHODIMP nsPref::CopyBinaryPref(const char *pref,
|
||||||
int *size, void ** return_value)
|
int *size, void ** return_value)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user