Added an option to use charset code point as collation key controlled by a pref, bug 18338.

This commit is contained in:
nhotta%netscape.com 2000-05-04 21:31:14 +00:00
Родитель 69a4fa9208
Коммит 3ed709f662
3 изменённых файлов: 30 добавлений и 10 удалений

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

@ -32,6 +32,7 @@
#include "nsIPosixLocale.h"
#include "nsCOMPtr.h"
#include "nsFileSpec.h" /* for nsAutoString */
#include "nsIPref.h"
//#define DEBUG_UNIX_COLLATION
static NS_DEFINE_IID(kICollationIID, NS_ICOLLATION_IID);
@ -65,6 +66,7 @@ nsCollationUnix::nsCollationUnix()
{
NS_INIT_REFCNT();
mCollation = NULL;
mKeyAsCodePoint = PR_FALSE;
}
nsCollationUnix::~nsCollationUnix()
@ -80,6 +82,11 @@ nsresult nsCollationUnix::Initialize(nsILocale* locale)
nsresult res;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_PROGID);
if (prefs) {
res = prefs->GetBoolPref("intl.collationKeyAsCodePoint", &mKeyAsCodePoint);
}
mCollation = new nsCollation;
if (mCollation == NULL) {
NS_ASSERTION(0, "mCollation creation failed");
@ -177,11 +184,16 @@ nsresult nsCollationUnix::GetSortKeyLen(const nsCollationStrength strength,
res = mCollation->UnicodeToChar(stringNormalized, &str, mCharset);
if (NS_SUCCEEDED(res) && str != NULL) {
DoSetLocale();
// call strxfrm to calculate a key length
int len = strxfrm(NULL, str, 0) + 1;
DoRestoreLocale();
*outLen = (len == -1) ? 0 : (PRUint32)len;
if (mKeyAsCodePoint) {
*outLen = nsCRT::strlen(str);
}
else {
DoSetLocale();
// call strxfrm to calculate a key length
int len = strxfrm(NULL, str, 0) + 1;
DoRestoreLocale();
*outLen = (len == -1) ? 0 : (PRUint32)len;
}
PR_Free(str);
}
@ -202,11 +214,17 @@ nsresult nsCollationUnix::CreateRawSortKey(const nsCollationStrength strength,
res = mCollation->UnicodeToChar(stringNormalized, &str, mCharset);
if (NS_SUCCEEDED(res) && str != NULL) {
DoSetLocale();
// call strxfrm to generate a key
int len = strxfrm((char *) key, str, strlen(str));
DoRestoreLocale();
*outLen = (len == -1) ? 0 : (PRUint32)len;
if (mKeyAsCodePoint) {
*outLen = nsCRT::strlen(str);
nsCRT::memcpy(key, str, *outLen);
}
else {
DoSetLocale();
// call strxfrm to generate a key
int len = strxfrm((char *) key, str, strlen(str));
DoRestoreLocale();
*outLen = (len == -1) ? 0 : (PRUint32)len;
}
PR_Free(str);
}

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

@ -36,6 +36,7 @@ protected:
nsString mLocale;
nsString mSavedLocale;
nsString mCharset;
PRBool mKeyAsCodePoint;
void DoSetLocale();
void DoRestoreLocale();

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

@ -284,6 +284,7 @@ pref("imageblocker.enabled", false);
pref("messages.new_window", true); // ML obsolete; use mailnews.message_in_thread_window
pref("intl.accept_languages", "en");
pref("intl.accept_charsets", "iso-8859-1,*,utf-8");
pref("intl.collationKeyAsCodePoint", false);
pref("intl.charsetmenu.browser.static", "iso-8859-1");
pref("intl.charsetmenu.mailedit", "iso-8859-1, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-9, iso-8859-10, iso-8859-14, iso-8859-15, iso-2022-jp, big5, gb2312, euc-kr, utf-8, koi8-r, windows-1251, koi8-u, iso-8859-7, viscii, tis-620, armscii-8");