- combine nsICharsetConverterManager2 and nsICharsetConverterManager
- get rid of nsIAtom in most of the methods
- provide versions of getUnicodeDecoder/Encoder which don't do alias resolution
- change all charset types to ASCII strings
- clean up some other i18n APIs which could be simplified
- fix all consumers of all changed i18n interfaces
r=jshin, smontagu
rs=sfraser
This commit is contained in:
alecf%flett.org 2003-06-11 18:16:03 +00:00
Родитель 1a7211d52d
Коммит ccf01a2786
168 изменённых файлов: 1741 добавлений и 1921 удалений

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

@ -52,11 +52,13 @@ class nsIDOMElement; /* forward declaration */
class nsIDOMDocument; /* forward declaration */
/* starting interface: nsIContentSerializer */
#define NS_ICONTENTSERIALIZER_IID_STR "61e9b9a3-d30c-429e-b0cf-ade73466df06"
/* d650439a-ca29-410d-a906-b0557fb62fcd */
#define NS_ICONTENTSERIALIZER_IID \
{0x61e9b9a3, 0xd30c, 0x429e, \
{ 0xb0, 0xcf, 0xad, 0xe7, 0x34, 0x66, 0xdf, 0x06 }}
{ 0xd650439a, \
0xca29, \
0x410d, \
{0xa9, 0x06, 0xb0, 0x55, 0x7f, 0xb6, 0x2f, 0xcd} }
class nsIContentSerializer : public nsISupports {
public:
@ -64,7 +66,7 @@ class nsIContentSerializer : public nsISupports {
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENTSERIALIZER_IID)
NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn,
nsIAtom* aCharSet, PRBool aIsCopying) = 0;
const char* aCharSet, PRBool aIsCopying) = 0;
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr) = 0;

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

@ -120,7 +120,7 @@ NS_IMPL_ISUPPORTS4(mozSanitizingHTMLSerializer,
NS_IMETHODIMP
mozSanitizingHTMLSerializer::Init(PRUint32 aFlags, PRUint32 dummy,
nsIAtom* aCharSet, PRBool aIsCopying)
const char* aCharSet, PRBool aIsCopying)
{
return NS_OK;
}

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

@ -65,7 +65,7 @@ public:
NS_DECL_ISUPPORTS
// nsIContentSerializer
NS_IMETHOD Init(PRUint32 flags, PRUint32 dummy, nsIAtom* aCharSet,
NS_IMETHOD Init(PRUint32 flags, PRUint32 dummy, const char* aCharSet,
PRBool aIsCopying);
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset,

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

@ -61,7 +61,6 @@
#include "nsIDOMRange.h"
#include "nsIDOMDocument.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsHTMLAtoms.h"
#include "nsITextContent.h"
#include "nsIEnumerator.h"
@ -74,6 +73,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsContentUtils.h"
#include "nsUnicharUtils.h"
#include "nsReadableUtils.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID,
NS_ICHARSETCONVERTERMANAGER_CID);
@ -150,10 +150,10 @@ protected:
nsCOMPtr<nsIUnicodeEncoder> mUnicodeEncoder;
nsCOMPtr<nsIDOMNode> mCommonParent;
nsCOMPtr<nsIDocumentEncoderNodeFixup> mNodeFixup;
nsCOMPtr<nsICharsetConverterManager2> mCharsetConverterManager;
nsCOMPtr<nsICharsetConverterManager> mCharsetConverterManager;
nsString mMimeType;
nsString mCharset;
nsCString mCharset;
PRUint32 mFlags;
PRUint32 mWrapColumn;
PRUint32 mStartDepth;
@ -275,7 +275,7 @@ nsDocumentEncoder::SetNode(nsIDOMNode* aNode)
NS_IMETHODIMP
nsDocumentEncoder::SetCharset(const nsAString& aCharset)
{
mCharset = aCharset;
CopyUCS2toASCII(aCharset, mCharset);
return NS_OK;
}
@ -926,10 +926,8 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString)
mCharsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = mCharsetConverterManager->GetCharsetAtom(mCharset.get(), getter_AddRefs(charsetAtom));
NS_ENSURE_SUCCESS(rv, rv);
}
mSerializer->Init(mFlags, mWrapColumn, charsetAtom, mIsCopying);
mSerializer->Init(mFlags, mWrapColumn, mCharset.get(), mIsCopying);
if (mSelection) {
nsCOMPtr<nsIDOMRange> range;
@ -983,11 +981,7 @@ nsDocumentEncoder::EncodeToStream(nsIOutputStream* aStream)
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIAtom> charsetAtom;
rv = mCharsetConverterManager->GetCharsetAtom(mCharset.get(), getter_AddRefs(charsetAtom));
NS_ENSURE_SUCCESS(rv, rv);
rv = mCharsetConverterManager->GetUnicodeEncoder(charsetAtom,
rv = mCharsetConverterManager->GetUnicodeEncoder(mCharset.get(),
getter_AddRefs(mUnicodeEncoder));
NS_ENSURE_SUCCESS(rv, rv);

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

@ -107,7 +107,7 @@ nsHTMLContentSerializer::~nsHTMLContentSerializer()
NS_IMETHODIMP
nsHTMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn,
nsIAtom* aCharSet, PRBool aIsCopying)
const char* aCharSet, PRBool aIsCopying)
{
mFlags = aFlags;
if (!aWrapColumn) {
@ -509,12 +509,10 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI
// See HTML 4.01 spec, "Appendix B.2.1 Non-ASCII characters in URI attribute values"
nsCOMPtr<nsITextToSubURI> textToSubURI;
nsAutoString uri(aURI); // in order to use FindCharInSet(), IsASCII()
nsXPIDLCString documentCharset;
nsresult rv = NS_OK;
if (mCharSet && !uri.IsASCII()) {
mCharSet->ToUTF8String(documentCharset);
if (!mCharSet.IsEmpty() && !uri.IsASCII()) {
textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -529,7 +527,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI
while ((end = uri.FindCharInSet("%#;/?:@&=+$,", start)) != -1) {
part = Substring(aURI, start, (end-start));
if (textToSubURI && !part.IsASCII()) {
rv = textToSubURI->ConvertAndEscape(documentCharset, part.get(), getter_Copies(escapedURI));
rv = textToSubURI->ConvertAndEscape(mCharSet.get(), part.get(), getter_Copies(escapedURI));
NS_ENSURE_SUCCESS(rv, rv);
}
else {
@ -547,7 +545,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI
// Escape the remaining part.
part = Substring(aURI, start, aURI.Length()-start);
if (textToSubURI) {
rv = textToSubURI->ConvertAndEscape(documentCharset, part.get(), getter_Copies(escapedURI));
rv = textToSubURI->ConvertAndEscape(mCharSet.get(), part.get(), getter_Copies(escapedURI));
NS_ENSURE_SUCCESS(rv, rv);
}
else {

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

@ -53,7 +53,7 @@ class nsHTMLContentSerializer : public nsXMLContentSerializer {
virtual ~nsHTMLContentSerializer();
NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn,
nsIAtom* aCharSet, PRBool aIsCopying);
const char* aCharSet, PRBool aIsCopying);
NS_IMETHOD AppendText(nsIDOMText* aText,
PRInt32 aStartOffset,
@ -156,7 +156,7 @@ class nsHTMLContentSerializer : public nsXMLContentSerializer {
PRInt32 mMaxColumn;
nsString mLineBreak;
nsCOMPtr<nsIAtom> mCharSet;
nsCString mCharSet;
// To keep track of startvalue of OL and first list item for nested lists
struct olState {

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

@ -149,7 +149,7 @@ NS_IMPL_ISUPPORTS4(nsPlainTextSerializer,
NS_IMETHODIMP
nsPlainTextSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn,
nsIAtom* aCharSet, PRBool aIsCopying)
const char* aCharSet, PRBool aIsCopying)
{
#ifdef DEBUG
// Check if the major control flags are set correctly.

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

@ -64,7 +64,7 @@ public:
// nsIContentSerializer
NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn,
nsIAtom* aCharSet, PRBool aIsCopying);
const char* aCharSet, PRBool aIsCopying);
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr);

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

@ -25,7 +25,6 @@
#include "nsIDOMCharacterData.h"
#include "nsParserUtils.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsIUnicodeDecoder.h"
#include "nsICharsetAlias.h"
#include "nsIContent.h"
@ -677,7 +676,7 @@ nsScriptLoader::ProcessPendingReqests()
// This function is copied from nsParser.cpp. It was simplified though, unnecessary part is removed.
static PRBool
DetectByteOrderMark(const unsigned char* aBytes, PRInt32 aLen, nsString& oCharset)
DetectByteOrderMark(const unsigned char* aBytes, PRInt32 aLen, nsCString& oCharset)
{
if (aLen < 2)
return PR_FALSE;
@ -687,21 +686,21 @@ DetectByteOrderMark(const unsigned char* aBytes, PRInt32 aLen, nsString& oCharse
if( aLen >= 3 && (0xBB==aBytes[1]) && (0xBF==aBytes[2])) {
// EF BB BF
// Win2K UTF-8 BOM
oCharset.AssignWithConversion("UTF-8");
oCharset.Assign("UTF-8");
}
break;
case 0xFE:
if(0xFF==aBytes[1]) {
// FE FF
// UTF-16, big-endian
oCharset.AssignWithConversion("UTF-16BE");
oCharset.Assign("UTF-16BE");
}
break;
case 0xFF:
if(0xFE==aBytes[1]) {
// FF FE
// UTF-16, little-endian
oCharset.AssignWithConversion("UTF-16LE");
oCharset.Assign("UTF-16LE");
}
break;
} // switch
@ -759,7 +758,7 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
}
if (stringLen) {
nsAutoString characterSet, preferred;
nsCAutoString characterSet, preferred;
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
nsCOMPtr<nsIChannel> channel;
@ -775,7 +774,9 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && calias) {
rv = calias->GetPreferred(charset, preferred);
NS_LossyConvertUCS2toASCII asciiCharset(charset);
rv = calias->GetPreferred(asciiCharset, preferred);
if(NS_SUCCEEDED(rv)) {
characterSet = preferred;
@ -792,7 +793,9 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
// is one.
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if (NS_SUCCEEDED(rv)) {
rv = calias->GetPreferred(charset, preferred);
NS_LossyConvertUCS2toASCII asciiCharset(charset);
rv = calias->GetPreferred(asciiCharset, preferred);
if(NS_SUCCEEDED(rv)) {
characterSet = preferred;
@ -807,22 +810,24 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
if (characterSet.IsEmpty()) {
// charset from document default
rv = mDocument->GetDocumentCharacterSet(characterSet);
nsAutoString uCharset;
rv = mDocument->GetDocumentCharacterSet(uCharset);
CopyUCS2toASCII(uCharset, characterSet);
}
NS_ASSERTION(NS_SUCCEEDED(rv), "Could not get document charset!");
if (characterSet.IsEmpty()) {
// fall back to ISO-8851-1, see bug 118404
characterSet = NS_LITERAL_STRING("ISO-8859-1");
characterSet = NS_LITERAL_CSTRING("ISO-8859-1");
}
nsCOMPtr<nsICharsetConverterManager> charsetConv =
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv) && charsetConv) {
rv = charsetConv->GetUnicodeDecoder(&characterSet,
getter_AddRefs(unicodeDecoder));
rv = charsetConv->GetUnicodeDecoderRaw(characterSet.get(),
getter_AddRefs(unicodeDecoder));
}
// converts from the charset to unicode

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

@ -87,7 +87,7 @@ NS_IMPL_ISUPPORTS1(nsXMLContentSerializer, nsIContentSerializer)
NS_IMETHODIMP
nsXMLContentSerializer::Init(PRUint32 flags, PRUint32 aWrapColumn,
nsIAtom* aCharSet, PRBool aIsCopying)
const char* aCharSet, PRBool aIsCopying)
{
return NS_OK;
}

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

@ -54,7 +54,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
NS_DECL_ISUPPORTS
NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn,
nsIAtom* aCharSet, PRBool aIsCopying);
const char* aCharSet, PRBool aIsCopying);
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr);

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

@ -78,7 +78,7 @@ public:
* @param aFormProcessor a form processor who can listen to
* @param aBidiOptions the BIDI options flags for the current pres context
*/
nsFormSubmission(const nsAString& aCharset,
nsFormSubmission(const nsACString& aCharset,
nsISaveAsCharset* aEncoder,
nsIFormProcessor* aFormProcessor,
PRInt32 aBidiOptions)
@ -148,7 +148,7 @@ protected:
nsISaveAsCharset* aEncoder);
/** The name of the encoder charset */
nsString mCharset;
nsCString mCharset;
/** The encoder that will encode Unicode names and values into
* bytes to be sent over the wire (usually a charset transformation)
*/
@ -170,7 +170,7 @@ public:
*/
static void GetSubmitCharset(nsIHTMLContent* aForm,
PRUint8 aCtrlsModAtSubmit,
nsAString& aCharset);
nsACString& aCharset);
/**
* Get the encoder for a form (suitable to pass in to the constructor).
* @param aForm the form in question
@ -180,7 +180,7 @@ public:
*/
static nsresult GetEncoder(nsIHTMLContent* aForm,
nsIPresContext* aPresContext,
const nsAString& aCharset,
const nsACString& aCharset,
nsISaveAsCharset** aEncoder);
/**
* Get an attribute of a form as int, provided that it is an enumerated value.
@ -244,7 +244,7 @@ public:
* @param aMethod the method of the submit (either NS_FORM_METHOD_GET or
* NS_FORM_METHOD_POST).
*/
nsFSURLEncoded(const nsAString& aCharset,
nsFSURLEncoded(const nsACString& aCharset,
nsISaveAsCharset* aEncoder,
nsIFormProcessor* aFormProcessor,
PRInt32 aBidiOptions,
@ -567,7 +567,7 @@ public:
* @param aFormProcessor a form processor who can listen to
* @param aBidiOptions the BIDI options flags for the current pres context
*/
nsFSMultipartFormData(const nsAString& aCharset,
nsFSMultipartFormData(const nsACString& aCharset,
nsISaveAsCharset* aEncoder,
nsIFormProcessor* aFormProcessor,
PRInt32 aBidiOptions);
@ -659,7 +659,7 @@ NS_IMPL_QUERY_INTERFACE_INHERITED0(nsFSMultipartFormData, nsFormSubmission)
//
// Constructor
//
nsFSMultipartFormData::nsFSMultipartFormData(const nsAString& aCharset,
nsFSMultipartFormData::nsFSMultipartFormData(const nsACString& aCharset,
nsISaveAsCharset* aEncoder,
nsIFormProcessor* aFormProcessor,
PRInt32 aBidiOptions)
@ -886,7 +886,7 @@ nsFSMultipartFormData::AddPostDataStream()
class nsFSTextPlain : public nsFormSubmission
{
public:
nsFSTextPlain(const nsAString& aCharset,
nsFSTextPlain(const nsACString& aCharset,
nsISaveAsCharset* aEncoder,
nsIFormProcessor* aFormProcessor,
PRInt32 aBidiOptions)
@ -1152,7 +1152,7 @@ GetSubmissionFromForm(nsIHTMLContent* aForm,
nsFormSubmission::GetEnumAttr(aForm, nsHTMLAtoms::method, &method);
// Get charset
nsAutoString charset;
nsCAutoString charset;
nsFormSubmission::GetSubmitCharset(aForm, ctrlsModAtSubmit, charset);
// Get unicode encoder
@ -1234,9 +1234,9 @@ nsFormSubmission::SubmitTo(nsIURI* aActionURL, const nsAString& aTarget,
void
nsFormSubmission::GetSubmitCharset(nsIHTMLContent* aForm,
PRUint8 aCtrlsModAtSubmit,
nsAString& oCharset)
nsACString& oCharset)
{
oCharset = NS_LITERAL_STRING("UTF-8"); // default to utf-8
oCharset = NS_LITERAL_CSTRING("UTF-8"); // default to utf-8
nsresult rv = NS_OK;
nsAutoString acceptCharsetValue;
@ -1260,8 +1260,10 @@ nsFormSubmission::GetSubmitCharset(nsIHTMLContent* aForm,
spPos = acceptCharsetValue.FindChar(PRUnichar(' '), offset);
PRInt32 cnt = ((-1==spPos)?(charsetLen-offset):(spPos-offset));
if (cnt > 0) {
nsAutoString charset;
acceptCharsetValue.Mid(charset, offset, cnt);
nsAutoString uCharset;
acceptCharsetValue.Mid(uCharset, offset, cnt);
nsCAutoString charset; charset.AssignWithConversion(uCharset);
if (NS_SUCCEEDED(calias->GetPreferred(charset, oCharset)))
return;
}
@ -1274,29 +1276,32 @@ nsFormSubmission::GetSubmitCharset(nsIHTMLContent* aForm,
nsCOMPtr<nsIDocument> doc;
aForm->GetDocument(*getter_AddRefs(doc));
if (doc) {
rv = doc->GetDocumentCharacterSet(oCharset);
nsAutoString docCharset;
rv = doc->GetDocumentCharacterSet(docCharset);
if (NS_SUCCEEDED(rv))
CopyUCS2toASCII(docCharset, oCharset);
}
if (aCtrlsModAtSubmit==IBMBIDI_CONTROLSTEXTMODE_VISUAL
&& oCharset.Equals(NS_LITERAL_STRING("windows-1256"),
nsCaseInsensitiveStringComparator())) {
&& oCharset.Equals(NS_LITERAL_CSTRING("windows-1256"),
nsCaseInsensitiveCStringComparator())) {
//Mohamed
oCharset = NS_LITERAL_STRING("IBM864");
oCharset = NS_LITERAL_CSTRING("IBM864");
}
else if (aCtrlsModAtSubmit==IBMBIDI_CONTROLSTEXTMODE_LOGICAL
&& oCharset.Equals(NS_LITERAL_STRING("IBM864"),
nsCaseInsensitiveStringComparator())) {
oCharset = NS_LITERAL_STRING("IBM864i");
&& oCharset.Equals(NS_LITERAL_CSTRING("IBM864"),
nsCaseInsensitiveCStringComparator())) {
oCharset = NS_LITERAL_CSTRING("IBM864i");
}
else if (aCtrlsModAtSubmit==IBMBIDI_CONTROLSTEXTMODE_VISUAL
&& oCharset.Equals(NS_LITERAL_STRING("ISO-8859-6"),
nsCaseInsensitiveStringComparator())) {
oCharset = NS_LITERAL_STRING("IBM864");
&& oCharset.Equals(NS_LITERAL_CSTRING("ISO-8859-6"),
nsCaseInsensitiveCStringComparator())) {
oCharset = NS_LITERAL_CSTRING("IBM864");
}
else if (aCtrlsModAtSubmit==IBMBIDI_CONTROLSTEXTMODE_VISUAL
&& oCharset.Equals(NS_LITERAL_STRING("UTF-8"),
nsCaseInsensitiveStringComparator())) {
oCharset = NS_LITERAL_STRING("IBM864");
&& oCharset.Equals(NS_LITERAL_CSTRING("UTF-8"),
nsCaseInsensitiveCStringComparator())) {
oCharset = NS_LITERAL_CSTRING("IBM864");
}
}
@ -1306,21 +1311,21 @@ nsFormSubmission::GetSubmitCharset(nsIHTMLContent* aForm,
nsresult
nsFormSubmission::GetEncoder(nsIHTMLContent* aForm,
nsIPresContext* aPresContext,
const nsAString& aCharset,
const nsACString& aCharset,
nsISaveAsCharset** aEncoder)
{
*aEncoder = nsnull;
nsresult rv = NS_OK;
nsAutoString charset(aCharset);
if(charset.Equals(NS_LITERAL_STRING("ISO-8859-1")))
charset.Assign(NS_LITERAL_STRING("windows-1252"));
nsCAutoString charset(aCharset);
if(charset.Equals(NS_LITERAL_CSTRING("ISO-8859-1")))
charset.Assign(NS_LITERAL_CSTRING("windows-1252"));
rv = CallCreateInstance( NS_SAVEASCHARSET_CONTRACTID, aEncoder);
NS_ASSERTION(NS_SUCCEEDED(rv), "create nsISaveAsCharset failed");
NS_ENSURE_SUCCESS(rv, rv);
rv = (*aEncoder)->Init(NS_ConvertUCS2toUTF8(charset).get(),
rv = (*aEncoder)->Init(charset.get(),
(nsISaveAsCharset::attr_EntityAfterCharsetConv +
nsISaveAsCharset::attr_FallbackDecimalNCR),
0);
@ -1344,8 +1349,8 @@ nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aStr, PRUint32 aLen,
nsAutoString newBuffer;
//This condition handle the RTL,LTR for a logical file
if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_VISUAL
&& mCharset.Equals(NS_LITERAL_STRING("windows-1256"),
nsCaseInsensitiveStringComparator())) {
&& mCharset.Equals(NS_LITERAL_CSTRING("windows-1256"),
nsCaseInsensitiveCStringComparator())) {
Conv_06_FE_WithReverse(nsString(aStr),
newBuffer,
textDirAtSubmit);
@ -1353,8 +1358,8 @@ nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aStr, PRUint32 aLen,
aLen=newBuffer.Length();
}
else if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_LOGICAL
&& mCharset.Equals(NS_LITERAL_STRING("IBM864"),
nsCaseInsensitiveStringComparator())) {
&& mCharset.Equals(NS_LITERAL_CSTRING("IBM864"),
nsCaseInsensitiveCStringComparator())) {
//For 864 file, When it is logical, if LTR then only convert
//If RTL will mak a reverse for the buffer
Conv_FE_06(nsString(aStr), newBuffer);
@ -1373,8 +1378,8 @@ nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aStr, PRUint32 aLen,
aStr = (PRUnichar*)temp.get();
}
else if (ctrlsModAtSubmit == IBMBIDI_CONTROLSTEXTMODE_VISUAL
&& mCharset.Equals(NS_LITERAL_STRING("IBM864"),
nsCaseInsensitiveStringComparator())
&& mCharset.Equals(NS_LITERAL_CSTRING("IBM864"),
nsCaseInsensitiveCStringComparator())
&& textDirAtSubmit == IBMBIDI_TEXTDIRECTION_RTL) {
Conv_FE_06(nsString(aStr), newBuffer);
@ -1439,7 +1444,7 @@ nsFormSubmission::ProcessValue(nsIDOMHTMLElement* aSource,
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(aSource);
if (formControl) {
if (formControl->GetType() == NS_FORM_INPUT_HIDDEN) {
return new nsString(mCharset);
return new NS_ConvertASCIItoUCS2(mCharset);
}
}
}

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

@ -97,7 +97,6 @@
#include "nsContentUtils.h"
#include "nsIFrame.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsIUnicodeDecoder.h"
#include "nsICharsetAlias.h"
#include "nsIChannel.h"
@ -4262,26 +4261,21 @@ HTMLContentSink::StartLayout()
// Convert the ref from document charset to unicode.
nsresult
CharsetConvRef(const nsString& aDocCharset, const nsCString& aRefInDocCharset,
CharsetConvRef(const nsCString& aDocCharset, const nsCString& aRefInDocCharset,
nsString& aRefInUnicode)
{
nsresult rv;
nsCOMPtr <nsIAtom> docCharsetAtom;
nsCOMPtr<nsICharsetConverterManager2> ccm2 =
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return rv;
}
rv = ccm2->GetCharsetAtom(aDocCharset.get(), getter_AddRefs(docCharsetAtom));
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIUnicodeDecoder> decoder;
rv = ccm2->GetUnicodeDecoder(docCharsetAtom, getter_AddRefs(decoder));
rv = ccm->GetUnicodeDecoder(aDocCharset.get(), getter_AddRefs(decoder));
if (NS_FAILED(rv)) {
return rv;
}
@ -4373,7 +4367,8 @@ HTMLContentSink::ScrollToRef(PRBool aReallyScroll)
rv = mDocument->GetDocumentCharacterSet(docCharset);
if (NS_SUCCEEDED(rv)) {
rv = CharsetConvRef(docCharset, unescapedRef, ref);
NS_LossyConvertUCS2toASCII charset(docCharset);
rv = CharsetConvRef(charset, unescapedRef, ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty())
rv = shell->GoToAnchor(ref, aReallyScroll);

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

@ -675,11 +675,11 @@ nsHTMLDocument::TryChannelCharset(nsIChannel *aChannel,
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID));
if (calias) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal),
nsCAutoString preferred;
rv = calias->GetPreferred(charsetVal,
preferred);
if(NS_SUCCEEDED(rv)) {
aCharset = preferred;
CopyASCIItoUCS2(preferred, aCharset);
aCharsetSource = kCharsetFromChannel;
return PR_TRUE;
}

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

@ -363,8 +363,8 @@ CSSLoaderImpl::RecycleParser(nsICSSParser* aParser)
// XXX We call this function a good bit. Consider caching the service
// in a static global or something?
static nsresult ResolveCharset(const nsAString& aCharsetAlias,
nsAString& aCharset)
static nsresult ResolveCharset(const nsACString& aCharsetAlias,
nsACString& aCharset)
{
nsresult rv = NS_ERROR_NOT_AVAILABLE;
if (! aCharsetAlias.IsEmpty()) {
@ -382,7 +382,7 @@ static const char kCharsetSym[] = "@charset";
static nsresult GetCharsetFromData(const unsigned char* aStyleSheetData,
PRUint32 aDataLength,
nsAString& aCharset)
nsACString& aCharset)
{
aCharset.Truncate();
if (aDataLength <= sizeof(kCharsetSym) - 1)
@ -544,7 +544,8 @@ static nsresult GetCharsetFromData(const unsigned char* aStyleSheetData,
break;
}
aCharset.Append(PRUnichar(aStyleSheetData[pos]));
// casting to avoid ambiguities
aCharset.Append(char(aStyleSheetData[pos]));
pos += step;
}
@ -584,18 +585,15 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
* default (document charset or ISO-8859-1 if we have no document
* charset)
*/
nsAutoString charset;
nsAutoString charsetCandidate;
nsCAutoString charset, charsetCandidate;
if (channel) {
nsCAutoString charsetVal;
channel->GetContentCharset(charsetVal);
CopyASCIItoUCS2(charsetVal, charsetCandidate);
channel->GetContentCharset(charsetCandidate);
}
result = NS_ERROR_NOT_AVAILABLE;
if (! charsetCandidate.IsEmpty()) {
#ifdef DEBUG_bzbarsky
fprintf(stderr, "Setting from HTTP to: %s\n", NS_ConvertUCS2toUTF8(charsetCandidate).get());
fprintf(stderr, "Setting from HTTP to: %s\n", charsetCandidate.get());
#endif
result = ResolveCharset(charsetCandidate, charset);
}
@ -608,7 +606,7 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
if (NS_SUCCEEDED(result)) {
#ifdef DEBUG_bzbarsky
fprintf(stderr, "Setting from @charset rule: %s\n",
NS_ConvertUCS2toUTF8(charsetCandidate).get());
charsetCandidate.get());
#endif
result = ResolveCharset(charsetCandidate, charset);
}
@ -618,11 +616,13 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
// Now try the charset on the <link> or processing instruction
// that loaded us
if (mOwningElement) {
mOwningElement->GetCharset(charsetCandidate);
nsAutoString elementCharset;
mOwningElement->GetCharset(elementCharset);
CopyUCS2toASCII(elementCharset, charsetCandidate);
if (! charsetCandidate.IsEmpty()) {
#ifdef DEBUG_bzbarsky
fprintf(stderr, "Setting from property on element: %s\n",
NS_ConvertUCS2toUTF8(charsetCandidate).get());
charsetCandidate.get());
#endif
result = ResolveCharset(charsetCandidate, charset);
}
@ -632,19 +632,21 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
if (NS_FAILED(result) && mLoader->mDocument) {
// no useful data on charset. Try the document charset.
// That needs no resolution, since it's already fully resolved
mLoader->mDocument->GetDocumentCharacterSet(charset);
nsAutoString docCharset;
mLoader->mDocument->GetDocumentCharacterSet(docCharset);
CopyUCS2toASCII(docCharset, charset);
#ifdef DEBUG_bzbarsky
fprintf(stderr, "Set from document: %s\n",
NS_ConvertUCS2toUTF8(charset).get());
charset.get());
#endif
}
if (charset.IsEmpty()) {
NS_WARNING("Unable to determine charset for sheet, using ISO-8859-1!");
charset = NS_LITERAL_STRING("ISO-8859-1");
charset = NS_LITERAL_CSTRING("ISO-8859-1");
}
aCharset = NS_ConvertUCS2toUTF8(charset);
aCharset = charset;
return NS_OK;
}
@ -1284,7 +1286,7 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
// 8192 is a nice magic number that happens to be what a lot of
// other things use for buffer sizes.
rv = converterStream->Init(stream, NS_LITERAL_STRING("UTF-8").get(),
rv = converterStream->Init(stream, "UTF-8",
8192, PR_TRUE);
if (NS_FAILED(rv)) {

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

@ -93,7 +93,6 @@
#include "nsIImageLoadingContent.h"
#include "nsEscape.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsICookieService.h"
@ -319,7 +318,9 @@ nsXMLContentSink::WillBuildModel(void)
}
// This function's implementation is in nsHTMLContentSink.cpp
nsresult CharsetConvRef(const nsString& aDocCharset, const nsCString& aRefInDocCharset, nsString& aRefInUnicode);
nsresult
CharsetConvRef(const nsCString& aDocCharset, const nsCString& aRefInDocCharset,
nsString& aRefInUnicode);
void
nsXMLContentSink::ScrollToRef(PRBool aReallyScroll)
@ -338,7 +339,7 @@ nsXMLContentSink::ScrollToRef(PRBool aReallyScroll)
nsresult rv = NS_ERROR_FAILURE;
// We assume that the bytes are in UTF-8, as it says in the spec:
// http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1
nsAutoString ref = NS_ConvertUTF8toUCS2(unescapedRef);
NS_ConvertUTF8toUCS2 ref(unescapedRef);
PRInt32 i, ns = mDocument->GetNumberOfShells();
for (i = 0; i < ns; i++) {
@ -364,7 +365,8 @@ nsXMLContentSink::ScrollToRef(PRBool aReallyScroll)
rv = mDocument->GetDocumentCharacterSet(docCharset);
if (NS_SUCCEEDED(rv)) {
rv = CharsetConvRef(docCharset, unescapedRef, ref);
rv = CharsetConvRef(NS_LossyConvertUCS2toASCII(docCharset),
unescapedRef, ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty())
rv = shell->GoToAnchor(ref, aReallyScroll);

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

@ -620,10 +620,10 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && (nsnull != calias) ) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal), preferred);
nsCAutoString preferred;
rv = calias->GetPreferred(charsetVal, preferred);
if(NS_SUCCEEDED(rv)){
charset = preferred;
CopyASCIItoUCS2(preferred, charset);
charsetSource = kCharsetFromChannel;
}
}

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

@ -606,7 +606,7 @@ const char * nsDefaultURIFixup::GetFileSystemCharset()
if (mFsCharset.IsEmpty())
{
nsresult rv;
nsAutoString charset;
nsCAutoString charset;
nsCOMPtr<nsIPlatformCharset> plat(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv))
rv = plat->GetCharset(kPlatformCharsetSel_FileName, charset);
@ -614,7 +614,7 @@ const char * nsDefaultURIFixup::GetFileSystemCharset()
if (charset.IsEmpty())
mFsCharset.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
else
mFsCharset.Assign(NS_LossyConvertUCS2toASCII(charset));
mFsCharset.Assign(charset);
}
return mFsCharset.get();

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

@ -3487,7 +3487,8 @@ GlobalWindowImpl::ConvertCharset(const nsAString& aStr,
return result;
// Get an encoder for the character set
result = ccm->GetUnicodeEncoder(&charset, getter_AddRefs(encoder));
result = ccm->GetUnicodeEncoderRaw(NS_LossyConvertUCS2toASCII(charset).get(),
getter_AddRefs(encoder));
if (NS_FAILED(result))
return result;
@ -3584,7 +3585,8 @@ GlobalWindowImpl::Unescape(const nsAString& aStr,
return result;
// Get an decoder for the character set
result = ccm->GetUnicodeDecoder(&charset, getter_AddRefs(decoder));
result = ccm->GetUnicodeDecoderRaw(NS_LossyConvertUCS2toASCII(charset).get(),
getter_AddRefs(decoder));
if (NS_FAILED(result))
return result;

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

@ -25,7 +25,7 @@
#include "nsSpellCheckUtils.h"
#include "nsReadableUtils.h"
#include "nsICharsetConverterManager2.h"
#include "nsICharsetConverterManager.h"
#include "nsIPlatformCharset.h"
#include "nsIServiceManager.h"
@ -112,17 +112,15 @@ nsSpellCheckUtils::CreateUnicodeConverters(const PRUnichar* aCharset,
nsresult rv;
nsCOMPtr <nsICharsetConverterManager2> ccm2 = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr <nsIAtom> charsetAtom;
rv = ccm2->GetCharsetAtom(aCharset, getter_AddRefs(charsetAtom));
NS_LossyConvertUCS2toASCII charset(aCharset);
rv = ccm->GetUnicodeDecoder(charset.get(), aUnicodeDecoder);
NS_ENSURE_SUCCESS(rv, rv);
rv = ccm2->GetUnicodeDecoder(charsetAtom, aUnicodeDecoder);
NS_ENSURE_SUCCESS(rv, rv);
rv = ccm2->GetUnicodeEncoder(charsetAtom, aUnicodeEncoder);
rv = ccm->GetUnicodeEncoder(charset.get(), aUnicodeEncoder);
NS_ENSURE_SUCCESS(rv, rv);
// Set the error behavior, in case a character cannot be mapped.

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

@ -272,7 +272,7 @@ txStylesheetSink::OnDataAvailable(nsIRequest *aRequest, nsISupports *aContext,
NS_IMETHODIMP
txStylesheetSink::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
{
nsAutoString charset(NS_LITERAL_STRING("UTF-8"));
nsCAutoString charset(NS_LITERAL_CSTRING("UTF-8"));
PRInt32 charsetSource = kCharsetFromDocTypeDefault;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
@ -285,8 +285,8 @@ txStylesheetSink::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
do_GetService(NS_CHARSETALIAS_CONTRACTID);
if (calias) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal),
nsCAutoString preferred;
rv = calias->GetPreferred(charsetVal,
preferred);
if (NS_SUCCEEDED(rv)) {
charset = preferred;
@ -296,7 +296,7 @@ txStylesheetSink::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
}
nsCOMPtr<nsIParser> parser = do_QueryInterface(aContext);
parser->SetDocumentCharset(charset, charsetSource);
parser->SetDocumentCharset(NS_ConvertASCIItoUCS2(charset), charsetSource);
nsCAutoString contentType;
channel->GetContentType(contentType);

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

@ -357,7 +357,6 @@ ConvertWStringToStream(const PRUnichar* aStr,
{
nsresult rv;
nsCOMPtr<nsIUnicodeEncoder> encoder;
nsAutoString charsetStr;
char* charBuf;
// We want to encode the string as utf-8, so get the right encoder
@ -365,8 +364,7 @@ ConvertWStringToStream(const PRUnichar* aStr,
do_GetService(kCharsetConverterManagerCID, &rv);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
charsetStr.Assign(NS_LITERAL_STRING("UTF-8"));
rv = charsetConv->GetUnicodeEncoder(&charsetStr,
rv = charsetConv->GetUnicodeEncoderRaw("UTF-8",
getter_AddRefs(encoder));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

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

@ -364,10 +364,10 @@ nsXMLHttpRequest::DetectCharset(nsAString& aCharset)
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID,&rv));
if(NS_SUCCEEDED(rv) && calias) {
nsAutoString preferred;
rv = calias->GetPreferred(NS_ConvertASCIItoUCS2(charsetVal), preferred);
nsCAutoString preferred;
rv = calias->GetPreferred(charsetVal, preferred);
if(NS_SUCCEEDED(rv)) {
aCharset.Assign(preferred);
CopyASCIItoUCS2(preferred, aCharset);
}
}
}
@ -415,7 +415,8 @@ nsXMLHttpRequest::ConvertBodyToText(PRUnichar **aOutBuffer)
return rv;
nsCOMPtr<nsIUnicodeDecoder> decoder;
rv = ccm->GetUnicodeDecoder(&dataCharset,getter_AddRefs(decoder));
rv = ccm->GetUnicodeDecoderRaw(NS_LossyConvertUCS2toASCII(dataCharset).get(),
getter_AddRefs(decoder));
if (NS_FAILED(rv))
return rv;
@ -822,7 +823,6 @@ nsXMLHttpRequest::GetStreamForWString(const PRUnichar* aStr,
{
nsresult rv;
nsCOMPtr<nsIUnicodeEncoder> encoder;
nsAutoString charsetStr;
char* postData;
// We want to encode the string as utf-8, so get the right encoder
@ -830,9 +830,8 @@ nsXMLHttpRequest::GetStreamForWString(const PRUnichar* aStr,
do_GetService(kCharsetConverterManagerCID, &rv);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
charsetStr.Assign(NS_LITERAL_STRING("UTF-8"));
rv = charsetConv->GetUnicodeEncoder(&charsetStr,
getter_AddRefs(encoder));
rv = charsetConv->GetUnicodeEncoderRaw("UTF-8",
getter_AddRefs(encoder));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
// Convert to utf-8

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

@ -75,7 +75,7 @@ PRInt32 nsFreeType2::gEmbeddedBitmapMaximumHeight = 1000000;
nsHashtable* nsFreeType2::sFontFamilies = nsnull;
nsHashtable* nsFreeType2::sRange1CharSetNames = nsnull;
nsHashtable* nsFreeType2::sRange2CharSetNames = nsnull;
nsICharsetConverterManager2* nsFreeType2::sCharSetManager = nsnull;
nsICharsetConverterManager* nsFreeType2::sCharSetManager = nsnull;
PRBool nsFreeType2::gHasExtFunc = PR_TRUE;
extern nsulCodePageRangeCharSetName ulCodePageRange1CharSetNames[];
@ -720,22 +720,19 @@ nsFreeType2::GetCustomEncoderInfo(const char * aFamilyName)
//
// build the converter
//
nsICharsetConverterManager2* charSetManager = GetCharSetManager();
nsICharsetConverterManager* charSetManager = GetCharSetManager();
if (!charSetManager)
return nsnull;
nsCOMPtr<nsIAtom> charset(dont_AddRef(NS_NewAtom(fei->mConverterName)));
if (charset) {
nsresult res;
res = charSetManager->GetUnicodeEncoder(charset, &fei->mConverter);
if (NS_FAILED(res)) {
return nsnull;
}
nsresult res;
res = charSetManager->GetUnicodeEncoderRaw(fei->mConverterName, &fei->mConverter);
if (NS_FAILED(res)) {
return nsnull;
}
}
return ffei;
}
nsICharsetConverterManager2*
nsICharsetConverterManager*
nsFreeType2::GetCharSetManager()
{
if (!sCharSetManager) {
@ -743,7 +740,7 @@ nsFreeType2::GetCharSetManager()
// get the sCharSetManager
//
nsServiceManager::GetService(kCharSetManagerCID,
NS_GET_IID(nsICharsetConverterManager2),
NS_GET_IID(nsICharsetConverterManager),
(nsISupports**) &sCharSetManager);
NS_ASSERTION(sCharSetManager,"failed to create the charset manager");
}

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

@ -29,7 +29,7 @@
#include "nspr.h"
#include "nsHashtable.h"
#include "nsICharsetConverterManager2.h"
#include "nsICharsetConverterManager.h"
#include "nsIFontCatalogService.h"
#include "nsIFreeType2.h"
#include <ft2build.h>
@ -190,7 +190,7 @@ protected:
void UnloadSharedLib();
// this belongs in nsFT2FontCatalog
static nsICharsetConverterManager2* GetCharSetManager();
static nsICharsetConverterManager* GetCharSetManager();
PRLibrary *mSharedLib;
FT_Library mFreeTypeLibrary;
@ -200,7 +200,7 @@ protected:
static nsHashtable *sFontFamilies;
static nsHashtable *sRange1CharSetNames;
static nsHashtable *sRange2CharSetNames;
static nsICharsetConverterManager2* sCharSetManager;
static nsICharsetConverterManager* sCharSetManager;
};
/* this simple record is used to model a given `installed' face */

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

@ -49,7 +49,6 @@
#include "nsFontMetricsGTK.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsILanguageAtomService.h"
#include "nsISaveAsCharset.h"
#include "nsIPref.h"
@ -163,7 +162,7 @@ static PRBool gAllowDoubleByteSpecialChars = PR_TRUE;
static nsIPref* gPref = nsnull;
static float gDevScale = 0.0f; /* Scaler value from |GetCanonicalPixelScale()| */
static PRBool gScaleBitmapFontsWithDevScale = PR_FALSE;
static nsICharsetConverterManager2* gCharSetManager = nsnull;
static nsICharsetConverterManager* gCharSetManager = nsnull;
static nsIUnicodeEncoder* gUserDefinedConverter = nsnull;
static nsHashtable* gAliases = nsnull;
@ -875,7 +874,7 @@ InitGlobals(nsIDeviceContext *aDevice)
aDevice->GetCanonicalPixelScale(gDevScale);
nsServiceManager::GetService(kCharSetManagerCID,
NS_GET_IID(nsICharsetConverterManager2), (nsISupports**) &gCharSetManager);
NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharSetManager);
if (!gCharSetManager) {
FreeGlobals();
return NS_ERROR_FAILURE;
@ -1435,31 +1434,26 @@ NS_IMETHODIMP nsFontMetricsGTK::Init(const nsFont& aFont, nsIAtom* aLangGroup,
if (mLangGroup.get() == gUserDefined) {
if (!gUserDefinedConverter) {
nsCOMPtr<nsIAtom> charset;
res = gCharSetManager->GetCharsetAtom2("x-user-defined",
getter_AddRefs(charset));
if (NS_SUCCEEDED(res)) {
res = gCharSetManager->GetUnicodeEncoder(charset,
res = gCharSetManager->GetUnicodeEncoderRaw("x-user-defined",
&gUserDefinedConverter);
if (NS_SUCCEEDED(res)) {
res = gUserDefinedConverter->SetOutputErrorBehavior(
if (NS_SUCCEEDED(res)) {
res = gUserDefinedConverter->SetOutputErrorBehavior(
gUserDefinedConverter->kOnError_Replace, nsnull, '?');
nsCOMPtr<nsICharRepresentable> mapper =
do_QueryInterface(gUserDefinedConverter);
if (mapper) {
gUserDefinedCCMap = MapperToCCMap(mapper);
if (!gUserDefinedCCMap)
return NS_ERROR_OUT_OF_MEMORY;
}
}
else {
return res;
nsCOMPtr<nsICharRepresentable> mapper =
do_QueryInterface(gUserDefinedConverter);
if (mapper) {
gUserDefinedCCMap = MapperToCCMap(mapper);
if (!gUserDefinedCCMap)
return NS_ERROR_OUT_OF_MEMORY;
}
}
else {
return res;
}
}
else {
return res;
}
nsCAutoString name("font.name.");
name.Append(*mGeneric);
@ -2173,20 +2167,17 @@ CheckMap(nsFontCharSetMap* aEntry)
{
while (aEntry->mName) {
if (aEntry->mInfo->mCharSet) {
// used to use NS_NewAtom??
nsresult res;
nsCOMPtr<nsIAtom> charset =
getter_AddRefs(NS_NewAtom(aEntry->mInfo->mCharSet));
if (charset) {
nsCOMPtr<nsIUnicodeEncoder> converter;
res = gCharSetManager->GetUnicodeEncoder(charset,
getter_AddRefs(converter));
if (NS_FAILED(res)) {
printf("=== %s failed (%s)\n", aEntry->mInfo->mCharSet, __FILE__);
}
nsCOMPtr<nsIUnicodeEncoder> converter;
res = gCharSetManager->GetUnicodeEncoderRaw(aEntry->mInfo->mCharSet,
getter_AddRefs(converter));
if (NS_FAILED(res)) {
printf("=== %s failed (%s)\n", aEntry->mInfo->mCharSet, __FILE__);
}
}
aEntry++;
}
aEntry++;
}
static void
@ -2215,64 +2206,56 @@ SetUpFontCharSetInfo(nsFontCharSetInfo* aSelf)
#endif
nsresult res;
nsCOMPtr<nsIAtom> charset = getter_AddRefs(NS_NewAtom(aSelf->mCharSet));
if (charset) {
nsIUnicodeEncoder* converter = nsnull;
res = gCharSetManager->GetUnicodeEncoder(charset, &converter);
if (NS_SUCCEEDED(res)) {
aSelf->mConverter = converter;
res = converter->SetOutputErrorBehavior(converter->kOnError_Replace,
nsnull, '?');
nsCOMPtr<nsICharRepresentable> mapper = do_QueryInterface(converter);
if (mapper) {
aSelf->mCCMap = MapperToCCMap(mapper);
if (aSelf->mCCMap) {
// used NS_NewAtom before??
nsIUnicodeEncoder* converter = nsnull;
res = gCharSetManager->GetUnicodeEncoderRaw(aSelf->mCharSet, &converter);
if (NS_SUCCEEDED(res)) {
aSelf->mConverter = converter;
res = converter->SetOutputErrorBehavior(converter->kOnError_Replace,
nsnull, '?');
nsCOMPtr<nsICharRepresentable> mapper = do_QueryInterface(converter);
if (mapper) {
aSelf->mCCMap = MapperToCCMap(mapper);
if (aSelf->mCCMap) {
#ifdef DEBUG_bzbarsky
char* atomname = atomToName(charset);
if (atomname) {
NS_WARNING(nsPrintfCString("\n\ncharset = %s", atomname).get());
nsMemory::Free(atomname);
}
NS_WARNING(nsPrintfCString("\n\ncharset = %s", aSelf->mCharSet).get());
nsMemory::Free(atomname);
#endif /* DEBUG */
/*
* We used to disable special characters like smart quotes
* in CJK fonts because if they are quite a bit larger than
* western glyphs and we did not want glyph fill-in to use them
* in single byte documents.
*
* Now, single byte documents find these special chars before
* the CJK fonts are searched so this is no longer needed
* but is useful when trying to determine which font(s) the
* special chars are found in.
*/
if ((aSelf->Convert == DoubleByteConvert)
&& (!gAllowDoubleByteSpecialChars)) {
PRUint16* ccmap = aSelf->mCCMap;
PRUint32 page = CCMAP_BEGIN_AT_START_OF_MAP;
const PRUint16* specialmap = gDoubleByteSpecialCharsCCMap;
while (NextNonEmptyCCMapPage(specialmap, &page)) {
PRUint32 pagechar = page;
for (int i=0; i < CCMAP_BITS_PER_PAGE; i++) {
if (CCMAP_HAS_CHAR(specialmap, pagechar))
CCMAP_UNSET_CHAR(ccmap, pagechar);
pagechar++;
}
/*
* We used to disable special characters like smart quotes
* in CJK fonts because if they are quite a bit larger than
* western glyphs and we did not want glyph fill-in to use them
* in single byte documents.
*
* Now, single byte documents find these special chars before
* the CJK fonts are searched so this is no longer needed
* but is useful when trying to determine which font(s) the
* special chars are found in.
*/
if ((aSelf->Convert == DoubleByteConvert)
&& (!gAllowDoubleByteSpecialChars)) {
PRUint16* ccmap = aSelf->mCCMap;
PRUint32 page = CCMAP_BEGIN_AT_START_OF_MAP;
const PRUint16* specialmap = gDoubleByteSpecialCharsCCMap;
while (NextNonEmptyCCMapPage(specialmap, &page)) {
PRUint32 pagechar = page;
for (int i=0; i < CCMAP_BITS_PER_PAGE; i++) {
if (CCMAP_HAS_CHAR(specialmap, pagechar))
CCMAP_UNSET_CHAR(ccmap, pagechar);
pagechar++;
}
}
return PR_TRUE;
}
}
else {
NS_WARNING("cannot get nsICharRepresentable");
return PR_TRUE;
}
}
else {
NS_WARNING("cannot get Unicode converter");
NS_WARNING("cannot get nsICharRepresentable");
}
}
else {
NS_WARNING("cannot get atom");
NS_WARNING("cannot get Unicode converter");
}
//
@ -4747,18 +4730,15 @@ SetCharsetLangGroup(nsFontCharSetInfo* aCharSetInfo)
if (!aCharSetInfo->mCharSet || aCharSetInfo->mLangGroup)
return;
nsCOMPtr<nsIAtom> charset;
nsresult res = gCharSetManager->GetCharsetAtom2(aCharSetInfo->mCharSet,
getter_AddRefs(charset));
if (NS_SUCCEEDED(res)) {
res = gCharSetManager->GetCharsetLangGroup(charset,
&aCharSetInfo->mLangGroup);
if (NS_FAILED(res)) {
aCharSetInfo->mLangGroup = NS_NewAtom("");
nsresult res;
res = gCharSetManager->GetCharsetLangGroupRaw(aCharSetInfo->mCharSet,
&aCharSetInfo->mLangGroup);
if (NS_FAILED(res)) {
aCharSetInfo->mLangGroup = NS_NewAtom("");
#ifdef NOISY_FONTS
printf("=== cannot get lang group for %s\n", aCharSetInfo->mCharSet);
printf("=== cannot get lang group for %s\n", aCharSetInfo->mCharSet);
#endif
}
}
}

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

@ -51,7 +51,6 @@
#include "nsLiteralString.h"
#include "nsDeviceContextMac.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsIPersistentProperties2.h"
#include "nsNetUtil.h"
#include "nsIURI.h"
@ -89,7 +88,7 @@ NS_IMETHODIMP nsFontCleanupObserver::Observe(nsISupports *aSubject, const char *
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static nsIPersistentProperties* gFontEncodingProperties = nsnull;
static nsICharsetConverterManager2* gCharsetManager = nsnull;
static nsICharsetConverterManager* gCharsetManager = nsnull;
static nsObjectHashtable* gFontMaps = nsnull;
static nsFontCleanupObserver *gFontCleanupObserver = nsnull;
static PRUint16* gCCMap = nsnull;
@ -504,8 +503,9 @@ InitFontEncodingProperties(void)
// Helper to determine if a font has a private encoding that we know something about
static nsresult
GetEncoding(const nsCString& aFontName, nsString& aValue)
GetEncoding(const nsCString& aFontName, nsACString& aValue)
{
nsresult rv;
// see if we should init the property
if (! gFontEncodingProperties) {
// but bail out for common fonts used at startup...
@ -521,7 +521,7 @@ GetEncoding(const nsCString& aFontName, nsString& aValue)
return NS_ERROR_NOT_AVAILABLE; // error mean do not get a special encoding
// init the property now
nsresult rv = InitFontEncodingProperties();
rv = InitFontEncodingProperties();
if NS_FAILED(rv)
return rv;
}
@ -532,7 +532,11 @@ GetEncoding(const nsCString& aFontName, nsString& aValue)
name.StripWhitespace();
ToLowerCase(name);
return gFontEncodingProperties->GetStringProperty(name, aValue);
nsAutoString value;
rv = gFontEncodingProperties->GetStringProperty(name, value);
if (NS_SUCCEEDED(rv))
CopyUCS2toASCII(value, aValue);
return rv;
}
// This function uses the charset converter manager (CCM) to get a pointer on
@ -543,22 +547,18 @@ GetConverter(const nsCString& aFontName, nsIUnicodeEncoder** aConverter)
{
*aConverter = nsnull;
nsAutoString value;
nsCAutoString value;
nsresult rv = GetEncoding(aFontName, value);
if (NS_FAILED(rv)) return rv;
if (!gCharsetManager)
{
rv = nsServiceManager::GetService(kCharsetConverterManagerCID,
NS_GET_IID(nsICharsetConverterManager2), (nsISupports**) &gCharsetManager);
NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharsetManager);
if(NS_FAILED(rv)) return rv;
}
nsCOMPtr<nsIAtom> charset;
rv = gCharsetManager->GetCharsetAtom(value.get(), getter_AddRefs(charset));
if (NS_FAILED(rv)) return rv;
rv = gCharsetManager->GetUnicodeEncoder(charset, aConverter);
rv = gCharsetManager->GetUnicodeEncoderRaw(value.get(), aConverter);
if (NS_FAILED(rv)) return rv;
nsIUnicodeEncoder* tmp = *aConverter;

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

@ -27,7 +27,6 @@
#include "nsIServiceManager.h"
#include "nsILanguageAtomService.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsICollation.h"
#include "nsCollationCID.h"
#include "nsLocaleCID.h"
@ -74,7 +73,7 @@ int nsFontMetricsOS2::gCachedIndex = 0;
nsICollation *nsFontMetricsOS2::gCollation = nsnull;
#ifdef WINCODE
static nsICharsetConverterManager2 *gCharsetManager = nsnull;
static nsICharsetConverterManager *gCharsetManager = nsnull;
#endif
static nsIPref *gPref = nsnull;
static nsIAtom *gUsersLocale = nsnull;
@ -308,7 +307,7 @@ InitGlobals(void)
{
#ifdef WINCODE
nsServiceManager::GetService(kCharsetConverterManagerCID,
NS_GET_IID(nsICharsetConverterManager2), (nsISupports**) &gCharsetManager);
NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharsetManager);
if (!gCharsetManager) {
FreeGlobals();
return NS_ERROR_FAILURE;

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

@ -3076,21 +3076,11 @@ static void PrefEnumCallback(const char *aName, void *aClosure)
if (psnativecode) {
nsAutoString str;
nsICharsetConverterManager *ccMain = nsnull;
nsICharsetAlias *aliasmgr = nsnull;
res = nsServiceManager::GetService(kCharsetConverterManagerCID,
kICharsetConverterManagerIID, (nsISupports **) & ccMain);
if (NS_SUCCEEDED(res) && ccMain) {
res = nsServiceManager::GetService(NS_CHARSETALIAS_CONTRACTID,
NS_GET_IID(nsICharsetAlias), (nsISupports **) & aliasmgr);
if (NS_SUCCEEDED(res) && aliasmgr) {
res = aliasmgr->GetPreferred(NS_ConvertASCIItoUCS2(psnativecode), str);
if (NS_SUCCEEDED(res)) {
res = ccMain->GetUnicodeEncoder(&str, &linfo->mEncoder);
}
nsServiceManager::ReleaseService(NS_CHARSETALIAS_CONTRACTID, aliasmgr);
}
nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccMain);
nsCOMPtr<nsICharsetConverterManager> ccMain =
do_GetService(kCharsetConverterManagerCID, &res);
if (NS_SUCCEEDED(res)) {
res = ccMain->GetUnicodeEncoder(psnativecode.get(), &linfo->mEncoder);
}
}

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

@ -44,7 +44,6 @@
#include "nsIServiceManager.h"
#include "nsILanguageAtomService.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsICharRepresentable.h"
#include "nsISaveAsCharset.h"
#include "nsIObserver.h"
@ -144,7 +143,7 @@ PRUint16* nsFontMetricsWin::gEmptyCCMap = nsnull;
static nsIPersistentProperties* gFontEncodingProperties = nsnull;
static nsICharsetConverterManager2* gCharsetManager = nsnull;
static nsICharsetConverterManager* gCharsetManager = nsnull;
static nsIUnicodeEncoder* gUserDefinedConverter = nsnull;
static nsISaveAsCharset* gFontSubstituteConverter = nsnull;
static nsIPref* gPref = nsnull;
@ -289,7 +288,7 @@ static nsresult
InitGlobals(void)
{
nsServiceManager::GetService(kCharsetConverterManagerCID,
NS_GET_IID(nsICharsetConverterManager2), (nsISupports**) &gCharsetManager);
NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharsetManager);
if (!gCharsetManager) {
FreeGlobals();
return NS_ERROR_FAILURE;
@ -1255,7 +1254,7 @@ static PRUint8 gBitToUnicodeRange[] =
// Helper to determine if a font has a private encoding that we know something about
static nsresult
GetEncoding(const char* aFontName, nsString& aValue)
GetEncoding(const char* aFontName, nsCString& aValue)
{
// this is "MS P Gothic" in Japanese
static const char* mspgothic=
@ -1290,8 +1289,12 @@ GetEncoding(const char* aFontName, nsString& aValue)
if (! gFontEncodingProperties)
InitFontEncodingProperties();
if (gFontEncodingProperties)
return gFontEncodingProperties->GetStringProperty(name, aValue);
if (gFontEncodingProperties) {
nsAutoString prop;
nsresult rv = gFontEncodingProperties->GetStringProperty(name, prop);
aValue.AssignWithConversion(prop);
return rv;
}
return NS_ERROR_NOT_AVAILABLE;
}
@ -1299,13 +1302,11 @@ GetEncoding(const char* aFontName, nsString& aValue)
// converter for the font whose name is given. The caller holds a reference
// to the converter, and should take care of the release...
static nsresult
GetConverterCommon(nsString& aEncoding, nsIUnicodeEncoder** aConverter)
GetConverterCommon(const char* aEncoding, nsIUnicodeEncoder** aConverter)
{
*aConverter = nsnull;
nsCOMPtr<nsIAtom> charset;
nsresult rv = gCharsetManager->GetCharsetAtom(aEncoding.get(), getter_AddRefs(charset));
if (NS_FAILED(rv)) return rv;
rv = gCharsetManager->GetUnicodeEncoder(charset, aConverter);
nsresult rv;
rv = gCharsetManager->GetUnicodeEncoderRaw(aEncoding, aConverter);
if (NS_FAILED(rv)) return rv;
return (*aConverter)->SetOutputErrorBehavior((*aConverter)->kOnError_Replace, nsnull, '?');
}
@ -1313,9 +1314,7 @@ GetConverterCommon(nsString& aEncoding, nsIUnicodeEncoder** aConverter)
static nsresult
GetDefaultConverterForTTFSymbolEncoding(nsIUnicodeEncoder** aConverter)
{
nsAutoString value;
value.AssignWithConversion(DEFAULT_TTF_SYMBOL_ENCODING);
return GetConverterCommon(value, aConverter);
return GetConverterCommon(DEFAULT_TTF_SYMBOL_ENCODING, aConverter);
}
static nsresult
@ -1323,13 +1322,13 @@ GetConverter(const char* aFontName, nsIUnicodeEncoder** aConverter, PRBool* aIsW
{
*aConverter = nsnull;
nsAutoString value;
nsCAutoString value;
nsresult rv = GetEncoding(aFontName, value);
if (NS_FAILED(rv)) return rv;
// The encoding name of a wide NonUnicode font in fontEncoding.properties
// has '.wide' suffix which has to be removed to get the converter
// for the encoding.
if (Substring(value, value.Length() - 5, 5) == (NS_LITERAL_STRING(".wide"))) {
if (Substring(value, value.Length() - 5, 5) == (NS_LITERAL_CSTRING(".wide"))) {
value.Truncate(value.Length()-5);
if (aIsWide)
*aIsWide = PR_TRUE;
@ -1338,7 +1337,7 @@ GetConverter(const char* aFontName, nsIUnicodeEncoder** aConverter, PRBool* aIsW
if (aIsWide)
*aIsWide = PR_FALSE;
return GetConverterCommon(value, aConverter);
return GetConverterCommon(value.get(), aConverter);
}
// This function uses the charset converter manager to fill the map for the
@ -1648,7 +1647,7 @@ nsFontMetricsWin::GetFontCCMAP(HDC aDC, const char* aShortName, eFontType& aFont
// Here, we check if this font is a pseudo-unicode font that
// we know something about, and we force it to be treated as
// a non-unicode font.
nsAutoString encoding;
nsCAutoString encoding;
if (NS_SUCCEEDED(GetEncoding(aShortName, encoding))) {
aCharset = DEFAULT_CHARSET;
aFontType = eFontType_NonUnicode;
@ -3546,11 +3545,7 @@ nsFontMetricsWin::RealizeFont()
if (mLangGroup.get() == gUserDefined) {
if (!gUserDefinedConverter) {
nsCOMPtr<nsIAtom> charset;
rv = gCharsetManager->GetCharsetAtom2("x-user-defined",
getter_AddRefs(charset));
if (NS_FAILED(rv)) return rv;
rv = gCharsetManager->GetUnicodeEncoder(charset, &gUserDefinedConverter);
rv = gCharsetManager->GetUnicodeEncoderRaw("x-user-defined", &gUserDefinedConverter);
if (NS_FAILED(rv)) return rv;
gUserDefinedConverter->SetOutputErrorBehavior(
gUserDefinedConverter->kOnError_Replace, nsnull, '?');

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

@ -52,7 +52,6 @@
#include "nsFontMetricsXlib.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsILanguageAtomService.h"
#include "nsISaveAsCharset.h"
#include "nsIPref.h"
@ -152,7 +151,7 @@ public:
nsCOMPtr<nsIPref> mPref;
nsCOMPtr<nsICharsetConverterManager2> mCharSetManager;
nsCOMPtr<nsICharsetConverterManager> mCharSetManager;
nsCOMPtr<nsIUnicodeEncoder> mUserDefinedConverter;
nsHashtable mAliases;
@ -1801,12 +1800,8 @@ NS_IMETHODIMP nsFontMetricsXlib::Init(const nsFont& aFont, nsIAtom* aLangGroup,
if (mLangGroup.get() == mFontMetricsContext->mUserDefined) {
if (!mFontMetricsContext->mUserDefinedConverter) {
nsCOMPtr<nsIAtom> charset;
res = mFontMetricsContext->mCharSetManager->GetCharsetAtom2("x-user-defined",
getter_AddRefs(charset));
if (NS_SUCCEEDED(res)) {
nsIUnicodeEncoder *ud_conv;
res = mFontMetricsContext->mCharSetManager->GetUnicodeEncoder(charset, &ud_conv);
res = mFontMetricsContext->mCharSetManager->GetUnicodeEncoderRaw("x-user-defined", &ud_conv);
if (NS_SUCCEEDED(res)) {
mFontMetricsContext->mUserDefinedConverter = ud_conv;
res = mFontMetricsContext->mUserDefinedConverter->SetOutputErrorBehavior(
@ -1822,10 +1817,6 @@ NS_IMETHODIMP nsFontMetricsXlib::Init(const nsFont& aFont, nsIAtom* aLangGroup,
else {
return res;
}
}
else {
return res;
}
}
nsCAutoString name("font.name.");
@ -2539,17 +2530,15 @@ CheckMap(nsFontMetricsXlibContext *aFmctx, const nsFontCharSetMapXlib* aEntry)
{
while (aEntry->mName) {
if (aEntry->mInfo->mCharSet) {
nsresult res;
nsCOMPtr<nsIAtom> charset =
getter_AddRefs(NS_NewAtom(aEntry->mInfo->mCharSet));
if (charset) {
nsresult res;
// used to use NS_NewAtom??
nsCOMPtr<nsIUnicodeEncoder> converter;
res = aFmctx->mCharSetManager->GetUnicodeEncoder(charset,
res = aFmctx->mCharSetManager->GetUnicodeEncoderRaw(aEntry->mInfo->mCharSet,
getter_AddRefs(converter));
if (NS_FAILED(res)) {
printf("=== %s failed (%s)\n", aEntry->mInfo->mCharSet, __FILE__);
}
}
}
aEntry++;
}
@ -2580,64 +2569,55 @@ SetUpFontCharSetInfo(nsFontMetricsXlibContext *aFmctx, nsFontCharSetInfoXlib* aS
#endif /* DEBUG */
nsresult res;
nsCOMPtr<nsIAtom> charset = getter_AddRefs(NS_NewAtom(aSelf->mCharSet));
if (charset) {
nsIUnicodeEncoder* converter = nsnull;
res = aFmctx->mCharSetManager->GetUnicodeEncoder(charset, &converter);
if (NS_SUCCEEDED(res)) {
aSelf->mConverter = converter;
res = converter->SetOutputErrorBehavior(converter->kOnError_Replace,
nsnull, '?');
nsCOMPtr<nsICharRepresentable> mapper = do_QueryInterface(converter);
if (mapper) {
aSelf->mCCMap = MapperToCCMap(mapper);
if (aSelf->mCCMap) {
nsIUnicodeEncoder* converter = nsnull;
res = aFmctx->mCharSetManager->GetUnicodeEncoderRaw(aSelf->mCharSet, &converter);
if (NS_SUCCEEDED(res)) {
aSelf->mConverter = converter;
res = converter->SetOutputErrorBehavior(converter->kOnError_Replace,
nsnull, '?');
nsCOMPtr<nsICharRepresentable> mapper = do_QueryInterface(converter);
if (mapper) {
aSelf->mCCMap = MapperToCCMap(mapper);
if (aSelf->mCCMap) {
#ifdef DEBUG
char *atomname = atomToName(charset);
if (atomname) {
NS_WARNING(nsPrintfCString(256, "SetUpFontCharSetInfo: charset = '%s'", atomname).get());
nsMemory::Free(atomname);
}
NS_WARNING(nsPrintfCString(256, "SetUpFontCharSetInfo: charset = '%s'", aSelf->mCharSet).get());
#endif /* DEBUG */
/*
* We used to disable special characters like smart quotes
* in CJK fonts because if they are quite a bit larger than
* western glyphs and we did not want glyph fill-in to use them
* in single byte documents.
*
* Now, single byte documents find these special chars before
* the CJK fonts are searched so this is no longer needed
* but is useful when trying to determine which font(s) the
* special chars are found in.
*/
if ((aSelf->Convert == DoubleByteConvert)
&& (!aFmctx->mAllowDoubleByteSpecialChars)) {
PRUint16* ccmap = aSelf->mCCMap;
PRUint32 page = CCMAP_BEGIN_AT_START_OF_MAP;
const PRUint16* specialmap = aFmctx->mDoubleByteSpecialCharsCCMap;
while (NextNonEmptyCCMapPage(specialmap, &page)) {
PRUint32 pagechar = page;
for (int i=0; i < CCMAP_BITS_PER_PAGE; i++) {
if (CCMAP_HAS_CHAR(specialmap, pagechar))
CCMAP_UNSET_CHAR(ccmap, pagechar);
pagechar++;
}
/*
* We used to disable special characters like smart quotes
* in CJK fonts because if they are quite a bit larger than
* western glyphs and we did not want glyph fill-in to use them
* in single byte documents.
*
* Now, single byte documents find these special chars before
* the CJK fonts are searched so this is no longer needed
* but is useful when trying to determine which font(s) the
* special chars are found in.
*/
if ((aSelf->Convert == DoubleByteConvert)
&& (!aFmctx->mAllowDoubleByteSpecialChars)) {
PRUint16* ccmap = aSelf->mCCMap;
PRUint32 page = CCMAP_BEGIN_AT_START_OF_MAP;
const PRUint16* specialmap = aFmctx->mDoubleByteSpecialCharsCCMap;
while (NextNonEmptyCCMapPage(specialmap, &page)) {
PRUint32 pagechar = page;
for (int i=0; i < CCMAP_BITS_PER_PAGE; i++) {
if (CCMAP_HAS_CHAR(specialmap, pagechar))
CCMAP_UNSET_CHAR(ccmap, pagechar);
pagechar++;
}
}
return PR_TRUE;
}
}
else {
NS_WARNING("cannot get nsICharRepresentable");
return PR_TRUE;
}
}
else {
NS_WARNING("cannot get Unicode converter");
NS_WARNING("cannot get nsICharRepresentable");
}
}
else {
NS_WARNING("cannot get atom");
NS_WARNING("cannot get Unicode converter");
}
//
@ -4040,18 +4020,15 @@ SetCharsetLangGroup(nsFontMetricsXlibContext *aFmctx, nsFontCharSetInfoXlib* aCh
if (!aCharSetInfo->mCharSet || aCharSetInfo->mLangGroup)
return;
nsCOMPtr<nsIAtom> charset;
nsresult res = aFmctx->mCharSetManager->GetCharsetAtom2(aCharSetInfo->mCharSet,
getter_AddRefs(charset));
if (NS_SUCCEEDED(res)) {
res = aFmctx->mCharSetManager->GetCharsetLangGroup(charset,
&aCharSetInfo->mLangGroup);
if (NS_FAILED(res)) {
aCharSetInfo->mLangGroup = NS_NewAtom("");
nsresult res;
res = aFmctx->mCharSetManager->GetCharsetLangGroupRaw(aCharSetInfo->mCharSet,
&aCharSetInfo->mLangGroup);
if (NS_FAILED(res)) {
aCharSetInfo->mLangGroup = NS_NewAtom("");
#ifdef NOISY_FONTS
printf("=== cannot get lang group for %s\n", aCharSetInfo->mCharSet);
printf("=== cannot get lang group for %s\n", aCharSetInfo->mCharSet);
#endif
}
}
}

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

@ -2323,8 +2323,9 @@ ParserWriteFunc(nsIInputStream* in,
}
if(pws->mNeedCharsetCheck) {
PRInt32 guessSource;
nsAutoString guess, preferred;
PRInt32 guessSource;
nsAutoString guess;
nsCAutoString preferred;
pws->mNeedCharsetCheck = PR_FALSE;
if(pws->mParser->DetectMetaTag(buf, theNumRead,
@ -2333,17 +2334,17 @@ ParserWriteFunc(nsIInputStream* in,
DetectByteOrderMark((const unsigned char*)buf,
theNumRead, guess, guessSource))) {
nsCOMPtr<nsICharsetAlias> alias(do_GetService(NS_CHARSETALIAS_CONTRACTID));
result = alias->GetPreferred(guess, preferred);
result = alias->GetPreferred(NS_LossyConvertUCS2toASCII(guess), preferred);
// Only continue if it's a recognized charset and not
// one of a designated set that we ignore.
if (NS_SUCCEEDED(result) &&
((kCharsetFromByteOrderMark == guessSource) ||
(!preferred.Equals(NS_LITERAL_STRING("UTF-16")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-16BE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-16LE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-32BE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-32LE"))))) {
guess.Assign(preferred);
(!preferred.Equals(NS_LITERAL_CSTRING("UTF-16")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-16BE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-16LE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-32BE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-32LE"))))) {
guess.Assign(NS_ConvertASCIItoUCS2(preferred));
pws->mParser->SetDocumentCharset(guess, guessSource);
pws->mParser->SetSinkCharset(guess);
nsCOMPtr<nsICachingChannel> channel(do_QueryInterface(pws->mRequest));

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

@ -204,22 +204,22 @@ nsresult nsScanner::SetDocumentCharset(const nsAString& aCharset , PRInt32 aSour
nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID, &res));
NS_ASSERTION( nsnull != calias, "cannot find charset alias");
nsAutoString charsetName; charsetName.Assign(aCharset);
nsCAutoString charsetName = NS_LossyConvertUCS2toASCII(aCharset);
if( NS_SUCCEEDED(res) && (nsnull != calias))
{
PRBool same = PR_FALSE;
res = calias->Equals(aCharset, mCharset, &same);
res = calias->Equals(charsetName, mCharset, &same);
if(NS_SUCCEEDED(res) && same)
{
return NS_OK; // no difference, don't change it
}
// different, need to change it
res = calias->GetPreferred(aCharset, charsetName);
res = calias->GetPreferred(charsetName, charsetName);
if(NS_FAILED(res) && (kCharsetUninitialized == mCharsetSource) )
{
// failed - unknown alias , fallback to ISO-8859-1
charsetName.Assign(NS_LITERAL_STRING("ISO-8859-1"));
charsetName.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
}
mCharset = charsetName;
mCharsetSource = aSource;
@ -229,7 +229,7 @@ nsresult nsScanner::SetDocumentCharset(const nsAString& aCharset , PRInt32 aSour
if(NS_SUCCEEDED(res) && (nsnull != ccm))
{
nsIUnicodeDecoder * decoder = nsnull;
res = ccm->GetUnicodeDecoder(&mCharset, &decoder);
res = ccm->GetUnicodeDecoderRaw(mCharset.get(), &decoder);
if(NS_SUCCEEDED(res) && (nsnull != decoder))
{
NS_IF_RELEASE(mUnicodeDecoder);

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

@ -394,7 +394,7 @@ class nsScanner {
PRUint32 mTotalRead;
PRPackedBool mIncremental;
PRInt32 mCharsetSource;
nsString mCharset;
nsCString mCharset;
nsIUnicodeDecoder *mUnicodeDecoder;
};

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

@ -39,7 +39,6 @@
#include "nsCharDetDll.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsDocumentCharsetInfo.h"
#include "nsCOMPtr.h"

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

@ -54,6 +54,7 @@
#include "nsIParserService.h"
#include "nsParserCIID.h"
#include "nsMetaCharsetCID.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
@ -258,7 +259,7 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
)
{
nsAutoString newCharset;
nsCAutoString newCharset;
if (nsnull == charsetValue)
{
@ -271,39 +272,39 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
if(kNotFound == end )
end = contentPart1.Length();
NS_ASSERTION(end>=start, "wrong index");
contentPart1.Mid(newCharset, start, end - start);
CopyUCS2toASCII(Substring(contentPart1, start, end-start), newCharset);
}
}
else
{
newCharset = charsetValue;
CopyUCS2toASCII(nsDependentString(charsetValue), newCharset);
}
nsDependentString charsetString(charset);
nsCAutoString charsetString; charsetString.AssignWithConversion(charset);
if (!newCharset.IsEmpty())
{
if(! newCharset.Equals(charsetString, nsCaseInsensitiveStringComparator()))
if(! newCharset.Equals(charsetString, nsCaseInsensitiveCStringComparator()))
{
PRBool same = PR_FALSE;
nsresult res2 = mAlias->Equals( newCharset, charsetString , &same);
if(NS_SUCCEEDED(res2) && (! same))
{
nsAutoString preferred;
nsCAutoString preferred;
res2 = mAlias->GetPreferred(newCharset, preferred);
if(NS_SUCCEEDED(res2))
{
// following charset should have been detected by parser
if (!preferred.Equals(NS_LITERAL_STRING("UTF-16")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-16BE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-16LE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-32BE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-32LE"))) {
if (!preferred.Equals(NS_LITERAL_CSTRING("UTF-16")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-16BE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-16LE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-32BE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-32LE"))) {
// Propagate the error message so that the parser can
// shutdown correctly. - Ref. Bug 96440
res = NotifyWebShell(aWebShell,
aChannel,
NS_ConvertUCS2toUTF8(preferred).get(),
preferred.get(),
kCharsetFromMetaTag);
}
} // if(NS_SUCCEEDED(res)
@ -358,21 +359,25 @@ NS_IMETHODIMP nsMetaCharsetObserver::GetCharsetFromCompatibilityTag(
// current charset have a lower priority
if (kCharsetFromMetaTag > src)
{
// need nsString for GetPreferred
nsAutoString newCharset((values->StringAt(0))->get());
nsAutoString preferred;
res = mAlias->GetPreferred(newCharset, preferred);
nsCAutoString newCharset;
newCharset.AssignWithConversion(values->StringAt(0)->get());
nsCAutoString preferred;
res = mAlias->GetPreferred(newCharset,
preferred);
if (NS_SUCCEEDED(res))
{
// compare against the current charset,
// also some charsets which should have been found in the BOM detection.
if (!preferred.Equals((values->StringAt(numOfAttributes-3))->get()) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-16")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-16BE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-16LE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-32BE")) &&
!preferred.Equals(NS_LITERAL_STRING("UTF-32LE")))
aCharset = preferred;
// also some charsets which should have been found in
// the BOM detection.
nsString* currentCharset = values->StringAt(numOfAttributes-3);
if (!preferred.Equals(NS_LossyConvertUCS2toASCII(*currentCharset)) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-16")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-16BE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-16LE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-32BE")) &&
!preferred.Equals(NS_LITERAL_CSTRING("UTF-32LE")))
aCharset = NS_ConvertASCIItoUCS2(preferred);
}
}
}

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

@ -129,23 +129,23 @@ NS_IMETHODIMP nsXMLEncodingObserver::Notify(
PRBool bGotCurrentCharsetSource = PR_FALSE;
PRBool bGotEncoding = PR_FALSE;
nsAutoString currentCharset(NS_LITERAL_STRING("unknown"));
nsCAutoString currentCharset(NS_LITERAL_CSTRING("unknown"));
nsAutoString charsetSourceStr(NS_LITERAL_STRING("unknown"));
nsAutoString encoding(NS_LITERAL_STRING("unknown"));
nsCAutoString encoding(NS_LITERAL_CSTRING("unknown"));
for(i=0; i < numOfAttributes; i++)
{
if(0==nsCRT::strcmp(nameArray[i], NS_LITERAL_STRING("charset").get()))
{
bGotCurrentCharset = PR_TRUE;
currentCharset = valueArray[i];
CopyUCS2toASCII(nsDependentString(valueArray[i]), currentCharset);
} else if(0==nsCRT::strcmp(nameArray[i], NS_LITERAL_STRING("charsetSource").get())) {
bGotCurrentCharsetSource = PR_TRUE;
charsetSourceStr = valueArray[i];
} else if(nsDependentString(nameArray[i]).Equals(NS_LITERAL_STRING("encoding"),
nsCaseInsensitiveStringComparator())) {
bGotEncoding = PR_TRUE;
encoding = valueArray[i];
CopyUCS2toASCII(nsDependentString(valueArray[i]), encoding);
}
}
@ -176,16 +176,13 @@ NS_IMETHODIMP nsXMLEncodingObserver::Notify(
res = calias->Equals( encoding, currentCharset, &same);
if(NS_SUCCEEDED(res) && (! same))
{
nsAutoString preferred;
res = calias->GetPreferred(encoding, preferred);
nsCAutoString preferred;
res = calias->GetPreferred(encoding,
preferred);
if(NS_SUCCEEDED(res))
{
const char* charsetInCStr = ToNewCString(preferred);
if(nsnull != charsetInCStr) {
res = NotifyWebShell(0,0, charsetInCStr, kCharsetFromMetaTag );
delete [] (char*)charsetInCStr;
return res;
}
res = NotifyWebShell(0,0, preferred.get(), kCharsetFromMetaTag );
return res;
} // if check for GetPreferred
} // if check res for Equals
} // if check res for GetService

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

@ -31,7 +31,8 @@
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsULE.h"
#include "nsICharsetConverterManager.h"
#include "nsICategoryManager.h"
#include "nsEncoderDecoderUtils.h"
#include "nsUnicodeToTIS620.h"
#include "nsUnicodeToSunIndic.h"
#include "nsUnicodeToThaiTTF.h"

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

@ -27,7 +27,6 @@
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsILanguageAtomService.h"
#include "nsCtlCIID.h"
#include "nsILE.h"
@ -170,11 +169,11 @@ NS_IMETHODIMP nsUnicodeToTIS620::Convert(const PRUnichar* input,
#endif
if (mCtlObj == nsnull) {
nsICharsetConverterManager2* gCharSetManager = nsnull;
nsICharsetConverterManager* gCharSetManager = nsnull;
nsIUnicodeEncoder* gDefaultTISConverter = nsnull;
nsresult res;
nsServiceManager::GetService(kCharSetManagerCID,
NS_GET_IID(nsICharsetConverterManager2), (nsISupports**) &gCharSetManager);
NS_GET_IID(nsICharsetConverterManager), (nsISupports**) &gCharSetManager);
#ifdef DEBUG_prabhath
printf("ERROR: No CTL IMPLEMENTATION - Default Thai Conversion");
@ -185,13 +184,7 @@ NS_IMETHODIMP nsUnicodeToTIS620::Convert(const PRUnichar* input,
if (!gCharSetManager)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIAtom> charset = getter_AddRefs(NS_NewAtom("TIS-620"));
if (charset)
res = gCharSetManager->GetUnicodeEncoder(charset, &gDefaultTISConverter);
else {
NS_IF_RELEASE(gCharSetManager);
return NS_ERROR_FAILURE;
}
res = gCharSetManager->GetUnicodeEncoderRaw("TIS-620", &gDefaultTISConverter);
if (!gDefaultTISConverter) {
NS_WARNING("cannot get default converter for tis-620");

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

@ -34,7 +34,7 @@
interface nsILanguageAtomService : nsISupports
{
nsILanguageAtom LookupLanguage(in wstring aLanguage);
nsILanguageAtom LookupCharSet(in wstring aCharSet);
nsILanguageAtom LookupCharSet(in string aCharSet);
nsIAtom GetLocaleLanguageGroup();
};

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

@ -43,10 +43,12 @@
#include "nscore.h"
#include "nsString.h"
// {21434951-EC71-11d2-9E89-0060089FE59B}
/* a434957c-6514-447c-991b-2117b633359c */
#define NS_IPOSIXLOCALE_IID \
{ 0x21434951, 0xec71, 0x11d2, \
{ 0x9e, 0x89, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
{ 0xa434957c, \
0x6514, \
0x447c, \
{0x99, 0x1b, 0x21, 0x17, 0xb6, 0x33, 0x35, 0x9c} }
#define MAX_LANGUAGE_CODE_LEN 3
#define MAX_COUNTRY_CODE_LEN 3
@ -57,9 +59,9 @@ class nsIPosixLocale : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPOSIXLOCALE_IID)
NS_IMETHOD GetPlatformLocale(const nsString* locale,char* posixLocale,size_t length)=0;
NS_IMETHOD GetXPLocale(const char* posixLocale, nsString* locale)=0;
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPOSIXLOCALE_IID)
NS_IMETHOD GetPlatformLocale(const nsString* locale, nsACString& posixLocale) = 0;
NS_IMETHOD GetXPLocale(const char* posixLocale, nsString* locale)=0;
};

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

@ -187,7 +187,7 @@ nsresult nsCollationMac::Initialize(nsILocale* locale)
PRUnichar* mappedCharset = NULL;
res = platformCharset->GetDefaultCharsetForLocale(aLocale.get(), &mappedCharset);
if (NS_SUCCEEDED(res) && mappedCharset) {
res = mCollation->SetCharset(mappedCharset);
res = mCollation->SetCharset(NS_LossyConvertUCS2toASCII(mappedCharset).get());
nsMemory::Free(mappedCharset);
}
}
@ -229,7 +229,7 @@ nsresult nsCollationMac::CreateRawSortKey(const nsCollationStrength strength,
res = mCollation->UnicodeToChar(stringNormalized, &str);
if (NS_SUCCEEDED(res) && str != NULL) {
str_len = strlen(str);
NS_ASSERTION(str_len <= *outLen, "output buffer too small");
NS_ASSERTION(str_len <= int(*outLen), "output buffer too small");
// If no CJK then generate a collation key
if (smJapanese != m_scriptcode && smKorean != m_scriptcode &&

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

@ -262,7 +262,7 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
mScriptcode = smSystemScript;
mLangcode = langEnglish;
mRegioncode = verUS;
mCharset.Assign(NS_LITERAL_STRING("x-mac-roman"));
mCharset.Assign(NS_LITERAL_CSTRING("x-mac-roman"));
// get application locale
@ -305,7 +305,7 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
PRUnichar* mappedCharset = NULL;
res = platformCharset->GetDefaultCharsetForLocale(mLocale.get(), &mappedCharset);
if (NS_SUCCEEDED(res) && mappedCharset) {
mCharset.Assign(mappedCharset);
mCharset.AssignWithConversion(mappedCharset);
nsMemory::Free(mappedCharset);
}
@ -316,14 +316,12 @@ nsresult nsDateTimeFormatMac::Initialize(nsILocale* locale)
// Initialize unicode decoder
nsCOMPtr <nsIAtom> charsetAtom;
nsCOMPtr <nsICharsetConverterManager2> charsetConverterManager;
nsCOMPtr <nsICharsetConverterManager> charsetConverterManager;
charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
res = charsetConverterManager->GetCharsetAtom(mUseDefaultLocale ? mSystemCharset.get() : mCharset.get(),
getter_AddRefs(charsetAtom));
if (NS_SUCCEEDED(res)) {
res = charsetConverterManager->GetUnicodeDecoder(charsetAtom, getter_AddRefs(mDecoder));
}
res = charsetConverterManager->GetUnicodeDecoder(mUseDefaultLocale ? mSystemCharset.get() :
mCharset.get(),
getter_AddRefs(mDecoder));
}
return res;

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

@ -25,7 +25,6 @@
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsCOMPtr.h"
#include "nsIDateTimeFormat.h"
@ -72,8 +71,8 @@ private:
nsString mLocale;
nsString mAppLocale;
nsString mCharset;
nsString mSystemCharset;
nsCString mCharset;
nsCString mSystemCharset;
short mScriptcode;
short mLangcode;
short mRegioncode;

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

@ -212,17 +212,15 @@ nsresult nsCollation::NormalizeString(const nsAString& stringIn, nsAString& stri
return NS_OK;
}
nsresult nsCollation::SetCharset(const PRUnichar* aCharset)
nsresult nsCollation::SetCharset(const char* aCharset)
{
NS_ENSURE_ARG_POINTER(aCharset);
nsresult rv;
nsCOMPtr <nsICharsetConverterManager2> charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
nsCOMPtr <nsICharsetConverterManager> charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr <nsIAtom> charsetAtom;
rv = charsetConverterManager->GetCharsetAtom(aCharset, getter_AddRefs(charsetAtom));
if (NS_SUCCEEDED(rv))
rv = charsetConverterManager->GetUnicodeEncoder(charsetAtom, getter_AddRefs(mEncoder));
rv = charsetConverterManager->GetUnicodeEncoder(aCharset,
getter_AddRefs(mEncoder));
}
return rv;
}
@ -233,7 +231,7 @@ nsresult nsCollation::UnicodeToChar(const nsAString& aSrc, char** dst)
nsresult res = NS_OK;
if (!mEncoder)
res = SetCharset(NS_LITERAL_STRING("ISO-8859-1").get());
res = SetCharset(NS_LITERAL_CSTRING("ISO-8859-1").get());
if (NS_SUCCEEDED(res)) {
const nsPromiseFlatString& src = PromiseFlatString(aSrc);

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

@ -27,7 +27,6 @@
#include "nsICollation.h"
#include "nsICaseConversion.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsCOMPtr.h"
@ -69,7 +68,7 @@ public:
nsresult NormalizeString(const nsAString& stringIn, nsAString& stringOut);
// charset conversion util, C string buffer is allocate by PR_Malloc, caller should call PR_Free
nsresult SetCharset(const PRUnichar* aCharset);
nsresult SetCharset(const char* aCharset);
nsresult UnicodeToChar(const nsAString& aSrc, char** dst);
protected:

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

@ -221,8 +221,8 @@ nsLanguageAtomService::LookupLanguage(const PRUnichar* aLanguage,
}
NS_IMETHODIMP
nsLanguageAtomService::LookupCharSet(const PRUnichar* aCharSet,
nsILanguageAtom** aResult)
nsLanguageAtomService::LookupCharSet(const char* aCharSet,
nsILanguageAtom** aResult)
{
nsresult res;
NS_ENSURE_ARG_POINTER(aResult);
@ -239,10 +239,10 @@ nsLanguageAtomService::LookupCharSet(const PRUnichar* aCharSet,
if (!mUnicode) {
mUnicode = getter_AddRefs(NS_NewAtom("x-unicode"));
}
nsCOMPtr<nsIAtom> charset;
mCharSets->GetCharsetAtom(aCharSet, getter_AddRefs(charset));
nsCOMPtr<nsIAtom> langGroup;
mCharSets->GetCharsetLangGroup(charset, getter_AddRefs(langGroup));
mCharSets->GetCharsetLangGroup(aCharSet,
getter_AddRefs(langGroup));
if (!langGroup) {
return NS_ERROR_FAILURE;
}

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

@ -37,7 +37,7 @@
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsICharsetConverterManager2.h"
#include "nsICharsetConverterManager.h"
#include "nsILanguageAtomService.h"
#include "nsIStringBundle.h"
#include "nsISupportsArray.h"
@ -58,7 +58,7 @@ public:
NS_IMETHOD InitLangGroupTable();
protected:
nsCOMPtr<nsICharsetConverterManager2> mCharSets;
nsCOMPtr<nsICharsetConverterManager> mCharSets;
nsCOMPtr<nsISupportsArray> mLangs;
nsCOMPtr<nsIStringBundle> mLangGroups;
nsCOMPtr<nsIAtom> mLocaleLangGroup;

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

@ -153,11 +153,7 @@ nsresult nsCollationUnix::Initialize(nsILocale* locale)
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(NS_POSIXLOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
char platformLocale[kPlatformLocaleLength+1];
res = posixLocale->GetPlatformLocale(&aLocale, platformLocale, kPlatformLocaleLength+1);
if (NS_SUCCEEDED(res)) {
mLocale.Assign(platformLocale);
}
res = posixLocale->GetPlatformLocale(&aLocale, mLocale);
}
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
@ -165,7 +161,7 @@ nsresult nsCollationUnix::Initialize(nsILocale* locale)
PRUnichar* mappedCharset = NULL;
res = platformCharset->GetDefaultCharsetForLocale(aLocale.get(), &mappedCharset);
if (NS_SUCCEEDED(res) && mappedCharset) {
mCollation->SetCharset(mappedCharset);
mCollation->SetCharset(NS_LossyConvertUCS2toASCII(mappedCharset).get());
nsMemory::Free(mappedCharset);
}
}
@ -237,7 +233,7 @@ nsresult nsCollationUnix::CreateRawSortKey(const nsCollationStrength strength,
// call strxfrm to generate a key
int len = strxfrm((char *) key, str, *outLen);
DoRestoreLocale();
if (len >= *outLen) {
if (PRUint32(len) >= *outLen) {
res = NS_ERROR_FAILURE;
len = -1;
}

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

@ -47,6 +47,7 @@
#include "nsIPlatformCharset.h"
#include "nsIPosixLocale.h"
#include "nsCRT.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsDateTimeFormatUnix, nsIDateTimeFormat);
@ -79,8 +80,8 @@ nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
}
}
mCharset.Assign(NS_LITERAL_STRING("ISO-8859-1"));
PL_strncpy(mPlatformLocale, "en_US", kPlatformLocaleLength+1);
mCharset.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
mPlatformLocale.Assign("en_US");
// get locale name string, use app default if no locale specified
if (NULL == locale) {
@ -110,7 +111,7 @@ nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
nsCOMPtr <nsIPosixLocale> posixLocale = do_GetService(NS_POSIXLOCALE_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
res = posixLocale->GetPlatformLocale(&mLocale, mPlatformLocale, kPlatformLocaleLength+1);
res = posixLocale->GetPlatformLocale(&mLocale, mPlatformLocale);
}
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
@ -118,21 +119,19 @@ nsresult nsDateTimeFormatUnix::Initialize(nsILocale* locale)
PRUnichar* mappedCharset = NULL;
res = platformCharset->GetDefaultCharsetForLocale(mLocale.get(), &mappedCharset);
if (NS_SUCCEEDED(res) && mappedCharset) {
mCharset = mappedCharset;
// XXX hacky, nsIPlatformCharset::GetDefaultCharsetForLocale
// should return a nsACString&
CopyUCS2toASCII(nsDependentString(mappedCharset), mCharset);
nsMemory::Free(mappedCharset);
}
}
}
// Initialize unicode decoder
nsCOMPtr <nsIAtom> charsetAtom;
nsCOMPtr <nsICharsetConverterManager2> charsetConverterManager;
nsCOMPtr <nsICharsetConverterManager> charsetConverterManager;
charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
if (NS_SUCCEEDED(res)) {
res = charsetConverterManager->GetCharsetAtom(mCharset.get(), getter_AddRefs(charsetAtom));
if (NS_SUCCEEDED(res)) {
res = charsetConverterManager->GetUnicodeDecoder(charsetAtom, getter_AddRefs(mDecoder));
}
res = charsetConverterManager->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mDecoder));
}
LocalePreferred24hour();
@ -154,7 +153,7 @@ void nsDateTimeFormatUnix::LocalePreferred24hour()
tmc->tm_min=0; // set the min & sec other number than '2'
tmc->tm_sec=0;
char *temp = setlocale(LC_TIME, mPlatformLocale);
char *temp = setlocale(LC_TIME, mPlatformLocale.get());
strftime(str, (size_t)99, "%X", (struct tm *)tmc);
(void) setlocale(LC_TIME, temp);
@ -250,7 +249,7 @@ nsresult nsDateTimeFormatUnix::FormatTMTime(nsILocale* locale,
// generate data/time string
char *old_locale = setlocale(LC_TIME, NULL);
(void) setlocale(LC_TIME, mPlatformLocale);
(void) setlocale(LC_TIME, mPlatformLocale.get());
if (PL_strlen(fmtD) && PL_strlen(fmtT)) {
PL_strncat(fmtD, " ", NSDATETIME_FORMAT_BUFFER_LEN);
PL_strncat(fmtD, fmtT, NSDATETIME_FORMAT_BUFFER_LEN);

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

@ -25,7 +25,6 @@
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsCOMPtr.h"
#include "nsIDateTimeFormat.h"
@ -77,8 +76,8 @@ private:
nsString mLocale;
nsString mAppLocale;
nsString mCharset; // in order to convert API result to unicode
char mPlatformLocale[kPlatformLocaleLength+1]; // for setlocale
nsCString mCharset; // in order to convert API result to unicode
nsCString mPlatformLocale; // for setlocale
PRBool mLocalePreferred24hour; // true if 24 hour format is preferred by current locale
PRBool mLocaleAMPMfirst; // true if AM/PM string is preferred before the time
nsCOMPtr <nsIUnicodeDecoder> mDecoder;

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

@ -58,7 +58,7 @@ nsPosixLocale::~nsPosixLocale(void)
}
NS_IMETHODIMP
nsPosixLocale::GetPlatformLocale(const nsString* locale,char* posixLocale, size_t length)
nsPosixLocale::GetPlatformLocale(const nsString* locale, nsACString& posixLocale)
{
char country_code[MAX_COUNTRY_CODE_LEN+1];
char lang_code[MAX_LANGUAGE_CODE_LEN+1];
@ -69,7 +69,7 @@ nsPosixLocale::GetPlatformLocale(const nsString* locale,char* posixLocale, size_
if (xp_locale.get()) {
if (!ParseLocaleString(xp_locale.get(),lang_code,country_code,extra,'-')) {
// strncpy(posixLocale,"C",length);
PL_strncpyz(posixLocale,xp_locale.get(),length); // use xp locale if parse failed
posixLocale = xp_locale; // use xp locale if parse failed
return NS_OK;
}
@ -90,7 +90,7 @@ nsPosixLocale::GetPlatformLocale(const nsString* locale,char* posixLocale, size_
}
}
strncpy(posixLocale,posix_locale,length);
posixLocale = posix_locale;
return NS_OK;
}

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

@ -55,8 +55,7 @@ public:
nsPosixLocale();
virtual ~nsPosixLocale();
NS_IMETHOD GetPlatformLocale(const nsString* locale,char* posixLocale,
size_t length);
NS_IMETHOD GetPlatformLocale(const nsString* locale, nsACString& posixLocale);
NS_IMETHOD GetXPLocale(const char* posixLocale, nsString* locale);
protected:

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

@ -132,7 +132,7 @@ nsresult nsCollationWin::Initialize(nsILocale* locale)
PRUnichar* mappedCharset = NULL;
res = platformCharset->GetDefaultCharsetForLocale(aLocale.get(), &mappedCharset);
if (NS_SUCCEEDED(res) && mappedCharset) {
mCollation->SetCharset(mappedCharset);
mCollation->SetCharset(NS_LossyConvertUCS2toASCII(mappedCharset).get());
nsMemory::Free(mappedCharset);
}
}

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

@ -32,7 +32,7 @@ GRE_MODULE = 1
XPIDLSRCS = \
nsITextToSubURI.idl \
nsICurrentCharsetListener.idl \
nsICharsetConverterManager2.idl \
nsICharsetConverterManager.idl \
nsIScriptableUConv.idl \
$(NULL)

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

@ -0,0 +1,123 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is character set conversion service
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alec Flett <alecf@flett.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsISupportsArray.idl"
#include "nsIAtom.idl"
%{ C++
#include "nsIUnicodeDecoder.h"
#include "nsIUnicodeEncoder.h"
#include "nsString.h"
// XXX change to NS_CHARSETCONVERTERMANAGER_CID
#define NS_ICHARSETCONVERTERMANAGER_CID \
{0x3c1c0163, 0x9bd0, 0x11d3, { 0x9d, 0x9, 0x0, 0x50, 0x4, 0x0, 0x7, 0xb2}}
// XXX change to NS_CHARSETCONVERTERMANAGER_PID
#define NS_CHARSETCONVERTERMANAGER_CONTRACTID "@mozilla.org/charset-converter-manager;1"
%}
interface nsIUnicodeDecoder;
interface nsIUnicodeEncoder;
interface nsIUTF8StringEnumerator;
/**
*
* Here Charsets are indentified by ASCII strings. Charset alias
* resolution is provided by default in most methods. "Raw"
* versions that do not need this resolution are also provided.
*
* @created 21/Feb/2000
* @author Catalin Rotaru [CATA]
*/
[scriptable, uuid(f5323a76-c8f7-4c65-8d0c-1250e969c7d5)]
interface nsICharsetConverterManager : nsISupports
{
/**
* Get the Unicode decoder for the given charset.
* The "Raw" version skips charset alias resolution
*/
nsIUnicodeDecoder getUnicodeDecoder(in string charset);
nsIUnicodeDecoder getUnicodeDecoderRaw(in string charset);
/**
* Get the Unicode encoder for the given charset.
* The "Raw" version skips charset alias resolution
*/
nsIUnicodeEncoder getUnicodeEncoder(in string charset);
nsIUnicodeEncoder getUnicodeEncoderRaw(in string charset);
/**
* A shortcut to calling nsICharsetAlias to do alias resolution
*/
ACString getCharsetAlias(in string charset);
/**
* Get the complete list of available decoders.
*/
nsIUTF8StringEnumerator getDecoderList();
/**
* Get the complete list of available encoders.
*/
nsIUTF8StringEnumerator getEncoderList();
/**
* Get the complete list of available charset detectors.
*/
nsIUTF8StringEnumerator GetCharsetDetectorList();
/**
* Get the human-readable name for the given charset.
*/
AString getCharsetTitle(in string charset);
/**
* Get some data about the given charset.
*/
AString getCharsetData(in string charset,
in wstring prop);
/**
* Get the language group for the given charset.
*/
nsIAtom getCharsetLangGroup(in string charset);
nsIAtom getCharsetLangGroupRaw(in string charset);
};

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

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

@ -50,13 +50,13 @@
* @created 8/Jun/2000
* @author Makoto Kato [m_kato@ga2.so-net.ne.jp]
*/
[scriptable, uuid(0A698C44-3BFF-11d4-9649-00C0CA135B4E)]
[scriptable, uuid(d395ef67-a613-47b9-b5e3-dc7ce1bdb71a)]
interface nsIScriptableUnicodeConverter : nsISupports
{
/**
* Converts the data from Unicode to one Charset.
*/
string ConvertFromUnicode([const] in wstring aSrc);
string ConvertFromUnicode(in wstring aSrc);
/**
* Returns the terminator string.
@ -72,5 +72,5 @@ interface nsIScriptableUnicodeConverter : nsISupports
/**
* Current charactor set
*/
attribute wstring charset;
attribute string charset;
};

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

@ -30,7 +30,6 @@ MODULE = uconv
EXPORTS = \
nsICharsetAlias.h \
nsICharsetConverterManager.h \
nsIPlatformCharset.h \
nsIUnicodeDecodeHelper.h \
nsIUnicodeDecoder.h \
@ -40,6 +39,7 @@ EXPORTS = \
nsIMappingCache.h \
nsIConverterInputStream.h \
uconvutil.h \
nsEncoderDecoderUtils.h \
$(NULL)
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,164 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is character set conversion utility macros.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corp.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Alec Flett <alecf@flett.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsEncoderDecoderUtils_h__
#define nsEncoderDecoderUtils_h__
#define NS_ERROR_UCONV_NOCONV \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 0x01)
#define NS_SUCCESS_USING_FALLBACK_LOCALE \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 0x02)
#define NS_UNICODEDECODER_NAME "Charset Decoders"
#define NS_UNICODEENCODER_NAME "Charset Encoders"
#define NS_DATA_BUNDLE_CATEGORY "uconv-charset-data"
#define NS_TITLE_BUNDLE_CATEGORY "uconv-charset-titles"
struct nsConverterRegistryInfo {
PRBool isEncoder; // PR_TRUE = encoder, PR_FALSE = decoder
const char *charset;
nsCID cid;
};
#define NS_CONVERTER_REGISTRY_START \
static const nsConverterRegistryInfo gConverterRegistryInfo[] = {
#define NS_CONVERTER_REGISTRY_END \
};
#define NS_IMPL_NSUCONVERTERREGSELF \
static NS_IMETHODIMP \
nsUConverterRegSelf(nsIComponentManager *aCompMgr, \
nsIFile *aPath, \
const char* registryLocation, \
const char* componentType, \
const nsModuleComponentInfo *info) \
{ \
nsresult rv; \
nsCOMPtr<nsICategoryManager> catman = \
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); \
if (NS_FAILED(rv)) return rv; \
\
nsXPIDLCString previous; \
PRUint32 i; \
for (i=0; i<sizeof(gConverterRegistryInfo)/sizeof(gConverterRegistryInfo[0]); i++) { \
const nsConverterRegistryInfo* entry = &gConverterRegistryInfo[i]; \
const char *category; \
const char *key; \
\
if (entry->isEncoder) { \
category = NS_UNICODEENCODER_NAME; \
} else { \
category = NS_UNICODEDECODER_NAME; \
} \
key = entry->charset; \
\
rv = catman->AddCategoryEntry(category, key, "", \
PR_TRUE, \
PR_TRUE, \
getter_Copies(previous)); \
} \
return rv; \
} \
static NS_IMETHODIMP \
nsUConverterUnregSelf(nsIComponentManager *aCompMgr, \
nsIFile *aPath, \
const char*, \
const nsModuleComponentInfo *info) \
{ \
nsresult rv; \
nsCOMPtr<nsICategoryManager> catman = \
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); \
if (NS_FAILED(rv)) return rv; \
\
nsXPIDLCString previous; \
PRUint32 i; \
for (i=0; i<sizeof(gConverterRegistryInfo)/sizeof(gConverterRegistryInfo[0]); i++) { \
const nsConverterRegistryInfo* entry = &gConverterRegistryInfo[i]; \
const char *category; \
const char *key; \
\
if (entry->isEncoder) { \
category = NS_UNICODEDECODER_NAME; \
} else { \
category = NS_UNICODEENCODER_NAME; \
} \
key = entry->charset; \
\
char * value = entry->cid.ToString(); \
\
rv = catman->DeleteCategoryEntry(category, key, PR_TRUE); \
CRTFREEIF(value); \
} \
return rv; \
}
#define NS_UCONV_REG_UNREG_DECODER(_Charset, _CID) \
{ \
PR_FALSE, \
_Charset, \
_CID, \
},
#define NS_UCONV_REG_UNREG_ENCODER(_Charset, _CID) \
{ \
PR_TRUE, \
_Charset, \
_CID, \
},
// this needs to be written out per some odd cpp behavior that
// I could not work around - the behavior is document in the cpp
// info page however, so I'm not the only one to hit this!
#define NS_UCONV_REG_UNREG(_Charset, _DecoderCID, _EncoderCID) \
{ \
PR_FALSE, \
_Charset, \
_DecoderCID, \
}, \
{ \
PR_TRUE, \
_Charset, \
_EncoderCID, \
},
#endif

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

@ -43,9 +43,12 @@
#include "nsString.h"
#include "nsISupports.h"
// {CCD4D374-CCDC-11d2-B3B1-00805F8A6670}
/* 0b4028d6-7473-4958-9b3c-4dee46bf68cb */
#define NS_ICHARSETALIAS_IID \
{ 0xccd4d374, 0xccdc, 0x11d2, { 0xb3, 0xb1, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 }}
{ 0x0b4028d6, \
0x7473, \
0x4958, \
{0x9b, 0x3c, 0x4d, 0xee, 0x46, 0xbf, 0x68, 0xcb} }
// {98D41C21-CCF3-11d2-B3B1-00805F8A6670}
#define NS_CHARSETALIAS_CID \
@ -61,14 +64,8 @@ class nsICharsetAlias : public nsISupports
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICHARSETALIAS_IID)
NS_IMETHOD GetPreferred(const nsAString& aAlias, nsAString& aResult) = 0;
NS_IMETHOD GetPreferred(const PRUnichar* aAlias, const PRUnichar** aResult) = 0;
NS_IMETHOD GetPreferred(const char* aAlias, char* aResult, PRInt32 aBufLength) = 0;
NS_IMETHOD Equals(const nsAString& aCharset1, const nsAString& aCharset2, PRBool* aResult) = 0;
NS_IMETHOD Equals(const PRUnichar* aCharset1, const PRUnichar* aCharset2, PRBool* aResult) = 0;
NS_IMETHOD Equals(const char* aCharset1, const char* aCharset2, PRBool* aResult) = 0;
NS_IMETHOD GetPreferred(const nsACString& aAlias, nsACString& aResult) = 0;
NS_IMETHOD Equals(const nsACString& aCharset1, const nsACString& aCharset2, PRBool* aResult) = 0;
};
#endif /* nsICharsetAlias_h___ */

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

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

@ -47,7 +47,7 @@ class nsIConverterInputStream : public nsIUnicharInputStream {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONVERTERSTREAM_IID)
NS_IMETHOD Init(nsIInputStream *aStream, const PRUnichar *aCharset,
NS_IMETHOD Init(nsIInputStream *aStream, const char *aCharset,
PRInt32 aBufferSize, PRBool aRecoverFromErrors) = 0;
};

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

@ -44,8 +44,12 @@
// Interface ID for our nsIPlatformCharset interface
/* 778859d5-fc01-4f4b-bfaa-3c0d1b6c81d6 */
#define NS_IPLATFORMCHARSET_IID \
{ 0x84b0f181, 0xc6c7, 0x11d2, {0xb3, 0xb0, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 }}
{ 0x778859d5, \
0xfc01, \
0x4f4b, \
{0xbf, 0xaa, 0x3c, 0x0d, 0x1b, 0x6c, 0x81, 0xd6} }
#define NS_PLATFORMCHARSET_CID \
{ 0x84b0f182, 0xc6c7, 0x11d2, {0xb3, 0xb0, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 }}
@ -68,7 +72,7 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPLATFORMCHARSET_IID)
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsAString& oResult) = 0;
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsACString& oResult) = 0;
NS_IMETHOD GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue) = 0;

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

@ -51,14 +51,10 @@ public:
nsCharsetAlias2();
virtual ~nsCharsetAlias2();
NS_IMETHOD GetPreferred(const nsAString& aAlias, nsAString& oResult);
NS_IMETHOD GetPreferred(const PRUnichar* aAlias, const PRUnichar** oResult) ;
NS_IMETHOD GetPreferred(const char* aAlias, char* oResult, PRInt32 aBufLength) ;
NS_IMETHOD Equals(const nsAString& aCharset1, const nsAString& aCharset2, PRBool* oResult) ;
NS_IMETHOD Equals(const PRUnichar* aCharset1, const PRUnichar* aCharset2, PRBool* oResult) ;
NS_IMETHOD Equals(const char* aCharset1, const char* aCharset2, PRBool* oResult) ;
NS_IMETHOD GetPreferred(const nsACString& aAlias, nsACString& aResult);
NS_IMETHOD Equals(const nsACString& aCharset1, const nsACString& aCharset2, PRBool* oResult) ;
private:
nsURLProperties* mDelegate;
};

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

@ -65,12 +65,13 @@ nsCharsetAlias2::~nsCharsetAlias2()
delete mDelegate;
}
//--------------------------------------------------------------
NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsAString& aAlias, nsAString& oResult)
NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsACString& aAlias,
nsACString& oResult)
{
if (aAlias.IsEmpty()) return NS_ERROR_NULL_POINTER;
NS_TIMELINE_START_TIMER("nsCharsetAlias2:GetPreferred");
nsAutoString aKey(aAlias);
nsCAutoString aKey(aAlias);
ToLowerCase(aKey);
oResult.Truncate();
@ -79,19 +80,19 @@ NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsAString& aAlias, nsAString&
// function *while loading* charsetalias.properties (see bug 190951),
// so we might have an |mDelegate| already that isn't valid yet, but
// the load is guaranteed to be "UTF-8" so things will be OK.
if(aKey.Equals(NS_LITERAL_STRING("utf-8"))) {
oResult = NS_LITERAL_STRING("UTF-8");
if(aKey.Equals(NS_LITERAL_CSTRING("utf-8"))) {
oResult = NS_LITERAL_CSTRING("UTF-8");
NS_TIMELINE_STOP_TIMER("nsCharsetAlias2:GetPreferred");
return NS_OK;
}
if(aKey.Equals(NS_LITERAL_STRING("iso-8859-1"))) {
oResult = NS_LITERAL_STRING("ISO-8859-1");
if(aKey.Equals(NS_LITERAL_CSTRING("iso-8859-1"))) {
oResult = NS_LITERAL_CSTRING("ISO-8859-1");
NS_TIMELINE_STOP_TIMER("nsCharsetAlias2:GetPreferred");
return NS_OK;
}
if(aKey.Equals(NS_LITERAL_STRING("x-sjis")) ||
aKey.Equals(NS_LITERAL_STRING("shift_jis"))) {
oResult = NS_LITERAL_STRING("Shift_JIS");
if(aKey.Equals(NS_LITERAL_CSTRING("x-sjis")) ||
aKey.Equals(NS_LITERAL_CSTRING("shift_jis"))) {
oResult = NS_LITERAL_CSTRING("Shift_JIS");
NS_TIMELINE_STOP_TIMER("nsCharsetAlias2:GetPreferred");
return NS_OK;
}
@ -109,26 +110,22 @@ NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsAString& aAlias, nsAString&
NS_TIMELINE_STOP_TIMER("nsCharsetAlias2:GetPreferred");
NS_TIMELINE_MARK_TIMER("nsCharsetAlias2:GetPreferred");
return mDelegate->Get(aKey, oResult);
// hack for now, have to fix nsURLProperties, but we can't until
// string bundles use UTF8 keys
nsAutoString result;
nsresult rv = mDelegate->Get(NS_ConvertASCIItoUCS2(aKey), result);
oResult = NS_LossyConvertUCS2toASCII(result);
return rv;
}
//--------------------------------------------------------------
NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const PRUnichar* aAlias, const PRUnichar** oResult)
{
// this method should be obsoleted
return NS_ERROR_NOT_IMPLEMENTED;
}
//--------------------------------------------------------------
NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const char* aAlias, char* oResult, PRInt32 aBufLength)
{
// this method should be obsoleted
return NS_ERROR_NOT_IMPLEMENTED;
}
//--------------------------------------------------------------
NS_IMETHODIMP nsCharsetAlias2::Equals(const nsAString& aCharset1, const nsAString& aCharset2, PRBool* oResult)
NS_IMETHODIMP
nsCharsetAlias2::Equals(const nsACString& aCharset1,
const nsACString& aCharset2, PRBool* oResult)
{
nsresult res = NS_OK;
if(aCharset1.Equals(aCharset2, nsCaseInsensitiveStringComparator())) {
if(aCharset1.Equals(aCharset2, nsCaseInsensitiveCStringComparator())) {
*oResult = PR_TRUE;
return res;
}
@ -139,29 +136,16 @@ NS_IMETHODIMP nsCharsetAlias2::Equals(const nsAString& aCharset1, const nsAStrin
}
*oResult = PR_FALSE;
nsString name1;
nsString name2;
nsCAutoString name1;
nsCAutoString name2;
res = this->GetPreferred(aCharset1, name1);
if(NS_SUCCEEDED(res)) {
res = this->GetPreferred(aCharset2, name2);
if(NS_SUCCEEDED(res)) {
*oResult = name1.Equals(name2, nsCaseInsensitiveStringComparator());
*oResult = name1.Equals(name2, nsCaseInsensitiveCStringComparator());
}
}
return res;
}
//--------------------------------------------------------------
NS_IMETHODIMP nsCharsetAlias2::Equals(const PRUnichar* aCharset1, const PRUnichar* aCharset2, PRBool* oResult)
{
// this method should be obsoleted
return NS_ERROR_NOT_IMPLEMENTED;
}
//--------------------------------------------------------------
NS_IMETHODIMP nsCharsetAlias2::Equals(const char* aCharset1, const char* aCharset2, PRBool* oResult)
{
// this method should be obsoleted
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -45,12 +45,14 @@
#include "nsIServiceManager.h"
#include "nsICategoryManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsEncoderDecoderUtils.h"
#include "nsIStringBundle.h"
#include "nsILocaleService.h"
#include "nsUConvDll.h"
#include "prmem.h"
#include "nsCRT.h"
#include "nsVoidArray.h"
#include "nsStringEnumerator.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
@ -64,7 +66,6 @@
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kSupportsArrayCID, NS_SUPPORTSARRAY_CID);
static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
// Pattern of cached, commonly used, single byte decoder
@ -73,9 +74,8 @@ static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
// Class nsCharsetConverterManager [implementation]
NS_IMPL_THREADSAFE_ISUPPORTS2(nsCharsetConverterManager,
nsICharsetConverterManager,
nsICharsetConverterManager2);
NS_IMPL_THREADSAFE_ISUPPORTS1(nsCharsetConverterManager,
nsICharsetConverterManager)
nsCharsetConverterManager::nsCharsetConverterManager()
:mDataBundle(NULL), mTitleBundle(NULL)
@ -132,15 +132,13 @@ nsresult nsCharsetConverterManager::LoadExtensibleBundle(
}
nsresult nsCharsetConverterManager::GetBundleValue(nsIStringBundle * aBundle,
const nsIAtom * aName,
const char * aName,
const nsAFlatString& aProp,
PRUnichar ** aResult)
{
nsresult res = NS_OK;
nsAutoString key;
res = ((nsIAtom *) aName)->ToString(key);
if (NS_FAILED(res)) return res;
nsAutoString key; key.AssignWithConversion(aName);
ToLowerCase(key); // we lowercase the main comparison key
if (!aProp.IsEmpty()) key.Append(aProp.get()); // yes, this param may be NULL
@ -150,31 +148,44 @@ nsresult nsCharsetConverterManager::GetBundleValue(nsIStringBundle * aBundle,
}
nsresult nsCharsetConverterManager::GetBundleValue(nsIStringBundle * aBundle,
const nsIAtom * aName,
const char * aName,
const nsAFlatString& aProp,
nsIAtom ** aResult)
nsAString& aResult)
{
nsresult res = NS_OK;
PRUnichar * value;
res = GetBundleValue(aBundle, aName, aProp, &value);
nsXPIDLString value;
res = GetBundleValue(aBundle, aName, aProp, getter_Copies(value));
if (NS_FAILED(res)) return res;
*aResult = NS_NewAtom(value);
PR_Free(value);
aResult = value;
return NS_OK;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------//----------------------------------------------------------------------------
// Interface nsICharsetConverterManager [implementation]
NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder(
const nsString * aDest,
nsIUnicodeEncoder ** aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetUnicodeEncoder(const char * aDest,
nsIUnicodeEncoder ** aResult)
{
// resolve the charset first
nsCAutoString charset;
// fully qualify to possibly avoid vtable call
nsCharsetConverterManager::GetCharsetAlias(aDest, charset);
return nsCharsetConverterManager::GetUnicodeEncoderRaw(charset.get(),
aResult);
}
NS_IMETHODIMP
nsCharsetConverterManager::GetUnicodeEncoderRaw(const char * aDest,
nsIUnicodeEncoder ** aResult)
{
*aResult= nsnull;
nsCOMPtr<nsIUnicodeEncoder> encoder;
@ -182,7 +193,7 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder(
if (mNativeUC) {
nsCOMPtr<nsISupports> supports;
mNativeUC->GetNativeConverter("UCS-2",
NS_LossyConvertUCS2toASCII(*aDest).get(),
aDest,
getter_AddRefs(supports));
encoder = do_QueryInterface(supports);
@ -195,9 +206,9 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder(
#endif
nsresult res = NS_OK;
nsCAutoString contractid(
NS_LITERAL_CSTRING(NS_UNICODEENCODER_CONTRACTID_BASE) +
NS_LossyConvertUCS2toASCII(*aDest));
nsCAutoString
contractid(NS_LITERAL_CSTRING(NS_UNICODEENCODER_CONTRACTID_BASE) +
nsDependentCString(aDest));
// Always create an instance since encoders hold state.
encoder = do_CreateInstance(contractid.get(), &res);
@ -212,9 +223,23 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder(
return res;
}
NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
const nsString * aSrc,
nsIUnicodeDecoder ** aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetUnicodeDecoder(const char * aSrc,
nsIUnicodeDecoder ** aResult)
{
// resolve the charset first
nsCAutoString charset;
// fully qualify to possibly avoid vtable call
nsCharsetConverterManager::GetCharsetAlias(aSrc, charset);
return nsCharsetConverterManager::GetUnicodeDecoderRaw(charset.get(),
aResult);
}
NS_IMETHODIMP
nsCharsetConverterManager::GetUnicodeDecoderRaw(const char * aSrc,
nsIUnicodeDecoder ** aResult)
{
*aResult= nsnull;
nsCOMPtr<nsIUnicodeDecoder> decoder;
@ -222,7 +247,7 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
#ifdef MOZ_USE_NATIVE_UCONV
if (mNativeUC) {
nsCOMPtr<nsISupports> supports;
mNativeUC->GetNativeConverter(NS_LossyConvertUCS2toASCII(*aSrc).get(),
mNativeUC->GetNativeConverter(aSrc,
"UCS-2",
getter_AddRefs(supports));
@ -240,9 +265,9 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
NS_UNICODEDECODER_CONTRACTID_BASE);
nsCAutoString contractid(kUnicodeDecoderContractIDBase +
NS_LossyConvertUCS2toASCII(*aSrc));
nsDependentCString(aSrc));
if (!strncmp(contractid.get()+kUnicodeDecoderContractIDBase.Length(),
if (!strncmp(aSrc,
NS_1BYTE_CODER_PATTERN,
NS_1BYTE_CODER_PATTERN_LEN))
{
@ -263,64 +288,21 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
return res;
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetLangGroup(
nsString * aCharset,
nsIAtom ** aResult)
{
if (aCharset == NULL) return NS_ERROR_NULL_POINTER;
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
*aResult = NULL;
nsCOMPtr<nsIAtom> atom;
nsresult res = GetCharsetAtom(aCharset->get(), getter_AddRefs(atom));
if (NS_FAILED(res)) return res;
res = GetCharsetLangGroup(atom, aResult);
return res;
}
NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
const nsIAtom * aCharset,
nsIUnicodeDecoder ** aResult)
{
if (aCharset == NULL) return NS_ERROR_NULL_POINTER;
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
*aResult = NULL;
// XXX use nsImmutableString
nsAutoString name;
NS_CONST_CAST(nsIAtom*, aCharset)->ToString(name);
return GetUnicodeDecoder(&name, aResult);
}
NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder(
const nsIAtom * aCharset,
nsIUnicodeEncoder ** aResult)
{
if (aCharset == NULL) return NS_ERROR_NULL_POINTER;
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
*aResult = NULL;
// XXX use nsImmutableString
nsAutoString name;
NS_CONST_CAST(nsIAtom*, aCharset)->ToString(name);
return GetUnicodeEncoder(&name, aResult);
}
nsresult
nsCharsetConverterManager::GetList(const nsACString& aCategory,
const nsACString& aPrefix,
nsISupportsArray** aResult)
nsIUTF8StringEnumerator** aResult)
{
if (aResult == NULL)
return NS_ERROR_NULL_POINTER;
*aResult = NULL;
nsresult rv;
nsCOMPtr<nsIAtom> atom;
nsCOMPtr<nsISupportsArray> array = do_CreateInstance(kSupportsArrayCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCAutoString alias;
nsCStringArray* array = new nsCStringArray;
if (!array)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
@ -346,89 +328,73 @@ nsCharsetConverterManager::GetList(const nsACString& aCategory,
continue;
fullName += name;
rv = GetCharsetAtom2(fullName.get(), getter_AddRefs(atom));
rv = GetCharsetAlias(fullName.get(), alias);
if (NS_FAILED(rv))
continue;
rv = array->AppendElement(atom);
rv = array->AppendCString(alias);
}
NS_ADDREF(*aResult = array);
return NS_OK;
return NS_NewAdoptingUTF8StringEnumerator(aResult, array);
}
// we should change the interface so that we can just pass back a enumerator!
NS_IMETHODIMP nsCharsetConverterManager::GetDecoderList(nsISupportsArray ** aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetDecoderList(nsIUTF8StringEnumerator ** aResult)
{
return GetList(NS_LITERAL_CSTRING(NS_UNICODEDECODER_NAME),
NS_LITERAL_CSTRING(""), aResult);
}
NS_IMETHODIMP nsCharsetConverterManager::GetEncoderList(
nsISupportsArray ** aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetEncoderList(nsIUTF8StringEnumerator ** aResult)
{
return GetList(NS_LITERAL_CSTRING(NS_UNICODEENCODER_NAME),
NS_LITERAL_CSTRING(""), aResult);
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetDetectorList(
nsISupportsArray ** aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetCharsetDetectorList(nsIUTF8StringEnumerator** aResult)
{
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
*aResult = NULL;
return GetList(NS_LITERAL_CSTRING(NS_CHARSET_DETECTOR_CATEGORY),
NS_LITERAL_CSTRING("chardet."), aResult);
}
// XXX Improve the implementation of this method. Right now, it is build on
// top of two things: the nsCharsetAlias service and the Atom engine. We can
// improve on both. First, make the nsCharsetAlias better, with its own hash
// table (not the StringBundle anymore) and a nicer file format. Second,
// reimplement the Atom engine for the specific Charset case - more optimal.
// Finally, unify the two for even better performance.
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetAtom(
const PRUnichar * aCharset,
nsIAtom ** aResult)
// top of the nsCharsetAlias service. We can make the nsCharsetAlias
// better, with its own hash table (not the StringBundle anymore) and
// a nicer file format.
NS_IMETHODIMP
nsCharsetConverterManager::GetCharsetAlias(const char * aCharset,
nsACString& aResult)
{
NS_PRECONDITION(aCharset && aResult, "null param");
NS_PRECONDITION(aCharset, "null param");
if (!aCharset)
return NS_ERROR_NULL_POINTER;
// We try to obtain the preferred name for this charset from the charset
// aliases. If we don't get it from there, we just use the original string
nsDependentString charset(aCharset);
nsDependentCString charset(aCharset);
nsCOMPtr<nsICharsetAlias> csAlias( do_GetService(kCharsetAliasCID) );
NS_ASSERTION(csAlias, "failed to get the CharsetAlias service");
if (csAlias) {
nsAutoString pref;
nsresult res = csAlias->GetPreferred(charset, pref);
nsresult res = csAlias->GetPreferred(charset, aResult);
if (NS_SUCCEEDED(res)) {
*aResult = NS_NewAtom(pref);
return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return (!aResult.IsEmpty()) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
}
*aResult = NS_NewAtom(charset);
return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
aResult = charset;
return NS_OK;
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetAtom2(
const char * aCharset,
nsIAtom ** aResult)
{
nsAutoString str;
str.AssignWithConversion(aCharset);
return GetCharsetAtom(str.get(), aResult);
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetTitle(
const nsIAtom * aCharset,
PRUnichar ** aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetCharsetTitle(const char * aCharset,
nsAString& aResult)
{
if (aCharset == NULL) return NS_ERROR_NULL_POINTER;
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
*aResult = NULL;
nsresult res = NS_OK;
@ -441,32 +407,13 @@ NS_IMETHODIMP nsCharsetConverterManager::GetCharsetTitle(
return res;
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetTitle2(
const nsIAtom * aCharset,
nsString * aResult)
{
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
nsresult res = NS_OK;
PRUnichar * title;
res = GetCharsetTitle(aCharset, &title);
if (NS_FAILED(res)) return res;
aResult->Assign(title);
PR_Free(title);
return res;
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetData(
const nsIAtom * aCharset,
const PRUnichar * aProp,
PRUnichar ** aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetCharsetData(const char * aCharset,
const PRUnichar * aProp,
nsAString& aResult)
{
if (aCharset == NULL) return NS_ERROR_NULL_POINTER;
// aProp can be NULL
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
*aResult = NULL;
nsresult res = NS_OK;
@ -479,31 +426,25 @@ NS_IMETHODIMP nsCharsetConverterManager::GetCharsetData(
return res;
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetData2(
const nsIAtom * aCharset,
const PRUnichar * aProp,
nsString * aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetCharsetLangGroup(const char * aCharset,
nsIAtom** aResult)
{
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
// resolve the charset first
nsCAutoString charset;
GetCharsetAlias(aCharset, charset);
nsresult res = NS_OK;
PRUnichar * data;
res = GetCharsetData(aCharset, aProp, &data);
if (NS_FAILED(res)) return res;
aResult->Assign(data);
PR_Free(data);
return res;
// fully qualify to possibly avoid vtable call
return nsCharsetConverterManager::GetCharsetLangGroupRaw(charset.get(),
aResult);
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetLangGroup(
const nsIAtom * aCharset,
nsIAtom ** aResult)
NS_IMETHODIMP
nsCharsetConverterManager::GetCharsetLangGroupRaw(const char * aCharset,
nsIAtom** aResult)
{
if (aCharset == NULL) return NS_ERROR_NULL_POINTER;
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
*aResult = NULL;
nsresult res = NS_OK;
@ -512,6 +453,17 @@ NS_IMETHODIMP nsCharsetConverterManager::GetCharsetLangGroup(
if (NS_FAILED(res)) return res;
}
res = GetBundleValue(mDataBundle, aCharset, NS_LITERAL_STRING(".LangGroup"), aResult);
nsCAutoString alias;
res = GetCharsetAlias(aCharset, alias);
if (NS_FAILED(res)) return res;
nsAutoString langGroup;
res = GetBundleValue(mDataBundle, alias.get(), NS_LITERAL_STRING(".LangGroup"), langGroup);
nsCOMPtr<nsIAtom> langGroupAtom = NS_NewAtom(langGroup);
NS_ADDREF(*aResult = langGroupAtom);
return res;
}

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

@ -45,23 +45,16 @@
#include "nsINativeUConvService.h"
class nsCharsetConverterManager : public nsICharsetConverterManager,
public nsICharsetConverterManager2
class nsCharsetConverterManager : public nsICharsetConverterManager
{
NS_DECL_ISUPPORTS
NS_DECL_NSICHARSETCONVERTERMANAGER2
NS_DECL_NSICHARSETCONVERTERMANAGER
public:
nsCharsetConverterManager();
virtual ~nsCharsetConverterManager();
NS_IMETHOD GetUnicodeEncoder(const nsString * aDest,
nsIUnicodeEncoder ** aResult);
NS_IMETHOD GetUnicodeDecoder(const nsString * aSrc,
nsIUnicodeDecoder ** aResult);
NS_IMETHOD GetCharsetLangGroup(nsString * aCharset, nsIAtom ** aResult);
private:
nsIStringBundle * mDataBundle;
@ -78,14 +71,17 @@ private:
const char* aCategory,
const char* aURL);
nsresult GetBundleValue(nsIStringBundle * aBundle, const nsIAtom * aName,
const nsAFlatString& aProp, PRUnichar ** aResult);
nsresult GetBundleValue(nsIStringBundle * aBundle, const nsIAtom * aName,
const nsAFlatString& aProp, nsIAtom ** aResult);
nsresult GetBundleValue(nsIStringBundle * aBundle,
const char * aName,
const nsAFlatString& aProp, PRUnichar ** aResult);
nsresult GetBundleValue(nsIStringBundle * aBundle,
const char * aName,
const nsAFlatString& aProp, nsAString& aResult);
nsresult GetList(const nsACString& aCategory,
const nsACString& aPrefix, nsISupportsArray** aResult);
const nsACString& aPrefix,
nsIUTF8StringEnumerator** aResult);
public:
static nsresult RegisterConverterManagerData();

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

@ -48,7 +48,7 @@ static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CI
NS_IMETHODIMP
nsConverterInputStream::Init(nsIInputStream* aStream,
const PRUnichar *aCharset,
const char *aCharset,
PRInt32 aBufferSize,
PRBool aRecoverFromErrors)
{
@ -61,13 +61,7 @@ nsConverterInputStream::Init(nsIInputStream* aStream,
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_FAILED(rv)) return nsnull;
nsAutoString charset;
if (aCharset)
charset.Assign(aCharset);
else
charset.Assign(NS_LITERAL_STRING("ISO-8859-1"));
rv = ccm->GetUnicodeDecoder(&charset, getter_AddRefs(mConverter));
rv = ccm->GetUnicodeDecoder(aCharset ? aCharset : "ISO-8859-1", getter_AddRefs(mConverter));
if (NS_FAILED(rv)) return rv;
// set up our buffers

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

@ -61,7 +61,7 @@ class nsConverterInputStream : nsIConverterInputStream {
PRUint32 aCount,
PRUint32 *aReadCount);
NS_IMETHOD Close();
NS_IMETHOD Init(nsIInputStream* aStream, const PRUnichar *aCharset,
NS_IMETHOD Init(nsIInputStream* aStream, const char *aCharset,
PRInt32 aBufferSize, PRBool aRecoverFromErrors);
NS_IMETHOD ReadSegments(nsWriteUnicharSegmentFun aWriter,
void* aClosure,

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

@ -25,72 +25,106 @@
#include "nsIPlatformCharset.h"
#include "nsURLProperties.h"
#include "pratom.h"
#define INCL_PM
#define INCL_WIN
#include <os2.h>
#include "nsUConvDll.h"
#include "nsIOS2Locale.h"
#include "nsCOMPtr.h"
#include "nsReadableUtils.h"
#include "nsLocaleCID.h"
#include "nsIComponentManager.h"
#include "nsITimelineService.h"
#include "nsPlatformCharset.h"
static nsURLProperties *gInfo = nsnull;
static PRInt32 gCnt= 0;
NS_IMPL_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset);
NS_IMPL_ISUPPORTS1(nsPlatformCharset, nsIPlatformCharset)
nsPlatformCharset::nsPlatformCharset()
{
PR_AtomicIncrement(&gCnt); // count for gInfo
NS_TIMELINE_START_TIMER("nsPlatformCharset()");
// XXX We should make the following block critical section
if(nsnull == gInfo)
{
nsURLProperties *info = new nsURLProperties(NS_LITERAL_CSTRING("resource:/res/os2charset.properties"));
NS_ASSERTION( info , " cannot create nsURLProperties");
gInfo = info;
}
NS_ASSERTION(gInfo, "Cannot open property file");
if( gInfo )
{
UINT acp = ::WinQueryCp(HMQ_CURRENT);
PRInt32 acpint = (PRInt32)(acp & 0x00FFFF);
nsAutoString acpKey(NS_LITERAL_STRING("os2."));
acpKey.AppendInt(acpint, 10);
nsresult res = gInfo->Get(acpKey, mCharset);
if(NS_FAILED(res)) {
mCharset.Assign(NS_LITERAL_STRING("IBM850"));
}
} else {
mCharset.Assign(NS_LITERAL_STRING("IBM850"));
}
}
UINT acp = ::WinQueryCp(HMQ_CURRENT);
PRInt32 acpint = (PRInt32)(acp & 0x00FFFF);
nsAutoString acpKey(NS_LITERAL_STRING("os2."));
acpKey.AppendInt(acpint, 10);
nsresult res = MapToCharset(acpKey, mCharset);
NS_TIMELINE_STOP_TIMER("nsPlatformCharset()");
NS_TIMELINE_MARK_TIMER("nsPlatformCharset()");
}
nsPlatformCharset::~nsPlatformCharset()
{
PR_AtomicDecrement(&gCnt);
if(0 == gCnt) {
if ((0 == gCnt) && (nsnull != gInfo)) {
delete gInfo;
gInfo = nsnull;
}
}
NS_IMETHODIMP
nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector, nsAString& oResult)
nsresult
nsPlatformCharset::InitInfo()
{
PR_AtomicIncrement(&gCnt); // count for gInfo
if (gInfo == nsnull) {
nsURLProperties *info = new nsURLProperties(NS_LITERAL_CSTRING("resource:/res/os2charset.properties"));
NS_ASSERTION(info , "cannot open properties file");
NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);
gInfo = info;
}
return NS_OK;
}
nsresult
nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
{
//delay loading os2charset.properties bundle if possible
if (inANSICodePage.Equals(NS_LITERAL_STRING("os2.850"))) {
outCharset = NS_LITERAL_CSTRING("IBM850");
return NS_OK;
}
if (inANSICodePage.Equals(NS_LITERAL_STRING("os2.932"))) {
outCharset = NS_LITERAL_CSTRING("Shift_JIS");
return NS_OK;
}
// ensure the .property file is loaded
nsresult rv = InitInfo();
if (NS_FAILED(rv)) {
outCharset.Assign(NS_LITERAL_CSTRING("IBM850"));
return rv;
}
nsAutoString charset;
rv = gInfo->Get(inANSICodePage, charset);
if (NS_FAILED(rv)) {
outCharset.Assign(NS_LITERAL_CSTRING("IBM850"));
return rv;
}
CopyUCS2toASCII(charset, outCharset);
return NS_OK;
}
NS_IMETHODIMP
nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
nsACString& oResult)
{
if ((selector == kPlatformCharsetSel_4xBookmarkFile) || (selector == kPlatformCharsetSel_4xPrefsJS)) {
if ((mCharset.Find("IBM850", IGNORE_CASE) != -1) || (mCharset.Find("IBM437", IGNORE_CASE) != -1))
oResult.Assign(NS_LITERAL_STRING("ISO-8859-1"));
oResult.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
else if (mCharset.Find("IBM852", IGNORE_CASE) != -1)
oResult.Assign(NS_LITERAL_STRING("windows-1250"));
oResult.Assign(NS_LITERAL_CSTRING("windows-1250"));
else if ((mCharset.Find("IBM855", IGNORE_CASE) != -1) || (mCharset.Find("IBM866", IGNORE_CASE) != -1))
oResult.Assign(NS_LITERAL_STRING("windows-1251"));
oResult.Assign(NS_LITERAL_CSTRING("windows-1251"));
else if ((mCharset.Find("IBM869", IGNORE_CASE) != -1) || (mCharset.Find("IBM813", IGNORE_CASE) != -1))
oResult.Assign(NS_LITERAL_STRING("windows-1253"));
oResult.Assign(NS_LITERAL_CSTRING("windows-1253"));
else if (mCharset.Find("IBM857", IGNORE_CASE) != -1)
oResult.Assign(NS_LITERAL_STRING("windows-1254"));
oResult.Assign(NS_LITERAL_CSTRING("windows-1254"));
else
oResult = mCharset;
} else {
@ -110,20 +144,15 @@ nsPlatformCharset::Init()
{
return NS_OK;
}
nsresult
nsPlatformCharset::MapToCharset(short script, short region, nsAString& outCharset)
{
return NS_OK;
}
nsresult
nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsAString& outCharset)
nsPlatformCharset::MapToCharset(short script, short region, nsACString& outCharset)
{
return NS_OK;
}
nsresult
nsPlatformCharset::InitGetCharset(nsAString &oString)
nsPlatformCharset::InitGetCharset(nsACString &oString)
{
return NS_OK;
}
@ -135,13 +164,7 @@ nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& loc
}
nsresult
nsPlatformCharset::VerifyCharset(nsString &aCharset)
nsPlatformCharset::VerifyCharset(nsCString &aCharset)
{
return NS_OK;
}
nsresult
nsPlatformCharset::InitInfo()
{
return NS_OK;
}

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

@ -50,19 +50,19 @@ public:
virtual ~nsPlatformCharset();
NS_IMETHOD Init();
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsAString& oResult);
NS_IMETHOD GetCharset(nsPlatformCharsetSel selector, nsACString& oResult);
NS_IMETHOD GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUnichar** _retValue);
private:
nsString mCharset;
nsCString mCharset;
nsString mLocale; // remember the locale & charset
nsresult InitInfo();
nsresult MapToCharset(short script, short region, nsAString& outCharset);
nsresult MapToCharset(nsAString& inANSICodePage, nsAString& outCharset);
nsresult InitGetCharset(nsAString& oString);
nsresult MapToCharset(short script, short region, nsACString& outCharset);
nsresult MapToCharset(nsAString& inANSICodePage, nsACString& outCharset);
nsresult InitGetCharset(nsACString& oString);
nsresult ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& locale, nsAString& oResult);
nsresult VerifyCharset(nsString &aCharset);
nsresult VerifyCharset(nsCString &aCharset);
};
#endif // nsPlatformCharset_h__

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

@ -43,7 +43,6 @@
#include "nsReadableUtils.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsIScriptableUConv.h"
#include "nsScriptableUConv.h"
#include "nsCRT.h"
@ -149,9 +148,9 @@ nsScriptableUnicodeConverter::ConvertToUnicode(const char *aSrc, PRUnichar **_re
/* attribute wstring charset; */
NS_IMETHODIMP
nsScriptableUnicodeConverter::GetCharset(PRUnichar * *aCharset)
nsScriptableUnicodeConverter::GetCharset(char * *aCharset)
{
*aCharset = ToNewUnicode(mCharset);
*aCharset = ToNewCString(mCharset);
if (!*aCharset)
return NS_ERROR_OUT_OF_MEMORY;
@ -159,7 +158,7 @@ nsScriptableUnicodeConverter::GetCharset(PRUnichar * *aCharset)
}
NS_IMETHODIMP
nsScriptableUnicodeConverter::SetCharset(const PRUnichar * aCharset)
nsScriptableUnicodeConverter::SetCharset(const char * aCharset)
{
mCharset.Assign(aCharset);
return InitConverter();
@ -171,20 +170,17 @@ nsScriptableUnicodeConverter::InitConverter()
nsresult rv = NS_OK;
mEncoder = NULL ;
nsCOMPtr<nsICharsetConverterManager2> ccm2 = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED( rv) && (nsnull != ccm2)) {
if (NS_SUCCEEDED( rv) && (nsnull != ccm)) {
// get charset atom due to getting unicode converter
nsCOMPtr <nsIAtom> charsetAtom;
rv = ccm2->GetCharsetAtom(mCharset.get(), getter_AddRefs(charsetAtom));
if (NS_SUCCEEDED(rv)) {
// get an unicode converter
rv = ccm2->GetUnicodeEncoder(charsetAtom, getter_AddRefs(mEncoder));
// get an unicode converter
rv = ccm->GetUnicodeEncoder(mCharset.get(), getter_AddRefs(mEncoder));
if(NS_SUCCEEDED(rv)) {
rv = mEncoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, (PRUnichar)'?');
if(NS_SUCCEEDED(rv)) {
rv = mEncoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, (PRUnichar)'?');
if(NS_SUCCEEDED(rv)) {
rv = ccm2->GetUnicodeDecoder(charsetAtom, getter_AddRefs(mDecoder));
}
rv = ccm->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mDecoder));
}
}
}

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

@ -55,7 +55,9 @@ public:
virtual ~nsScriptableUnicodeConverter();
protected:
nsAutoString mCharset;
// charsets are ALWAYS very short, so its actually better to use
// nsCAutoString here
nsCAutoString mCharset;
nsCOMPtr<nsIUnicodeEncoder> mEncoder;
nsCOMPtr<nsIUnicodeDecoder> mDecoder;

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

@ -39,7 +39,6 @@
#include "nsString.h"
#include "nsIUnicodeEncoder.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsReadableUtils.h"
#include "nsITextToSubURI.h"
#include "nsIServiceManager.h"
@ -67,7 +66,6 @@ NS_IMETHODIMP nsTextToSubURI::ConvertAndEscape(
if(nsnull == _retval)
return NS_ERROR_NULL_POINTER;
*_retval = nsnull;
nsAutoString charsetStr; charsetStr.AssignWithConversion(charset);
nsIUnicodeEncoder *encoder = nsnull;
nsresult rv = NS_OK;
@ -77,7 +75,7 @@ NS_IMETHODIMP nsTextToSubURI::ConvertAndEscape(
NS_GET_IID(nsICharsetConverterManager),
(nsISupports**)&ccm);
if(NS_SUCCEEDED(rv) && (nsnull != ccm)) {
rv = ccm->GetUnicodeEncoder(&charsetStr, &encoder);
rv = ccm->GetUnicodeEncoder(charset, &encoder);
nsServiceManager::ReleaseService( kCharsetConverterManagerCID, ccm);
if (NS_SUCCEEDED(rv)) {
rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, (PRUnichar)'?');
@ -139,9 +137,8 @@ NS_IMETHODIMP nsTextToSubURI::UnEscapeAndConvert(
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
nsAutoString charsetStr; charsetStr.AssignWithConversion(charset);
nsIUnicodeDecoder *decoder;
rv = ccm->GetUnicodeDecoder(&charsetStr, &decoder);
rv = ccm->GetUnicodeDecoder(charset, &decoder);
if (NS_SUCCEEDED(rv)) {
PRUnichar *pBuf = nsnull;
PRInt32 len = strlen(unescaped);
@ -200,17 +197,13 @@ nsresult nsTextToSubURI::convertURItoUnicode(const nsAFlatCString &aCharset,
// empty charset could indicate UTF-8, but aURI turns out not to be UTF-8.
NS_ENSURE_FALSE(aCharset.IsEmpty(), NS_ERROR_INVALID_ARG);
nsCOMPtr<nsICharsetConverterManager2> charsetConverterManager;
nsCOMPtr<nsICharsetConverterManager> charsetConverterManager;
charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAtom> charsetAtom;
rv = charsetConverterManager->GetCharsetAtom2(aCharset.get(), getter_AddRefs(charsetAtom));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
rv = charsetConverterManager->GetUnicodeDecoder(charsetAtom,
rv = charsetConverterManager->GetUnicodeDecoder(aCharset.get(),
getter_AddRefs(unicodeDecoder));
NS_ENSURE_SUCCESS(rv, rv);

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

@ -43,7 +43,7 @@
#include "nsIComponentManager.h"
#include "nsICategoryManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsEncoderDecoderUtils.h"
#include "nsIUnicodeDecoder.h"
#include "nsIUnicodeEncoder.h"
#include "nsICharsetAlias.h"

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

@ -49,7 +49,7 @@
#include "nsIUnicodeDecoder.h"
#include "nsIUnicodeEncoder.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsEncoderDecoderUtils.h"
#if HAVE_GNU_LIBC_VERSION_H
#include <gnu/libc-version.h>
#endif
@ -123,7 +123,7 @@ nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& loc
}
}
NS_ASSERTION(0, "unable to convert locale to charset using deprecated config");
mCharset.Assign(NS_LITERAL_STRING("ISO-8859-1"));
mCharset.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
return NS_SUCCESS_USING_FALLBACK_LOCALE;
}
@ -145,7 +145,7 @@ nsPlatformCharset::~nsPlatformCharset()
}
NS_IMETHODIMP
nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector, nsAString& oResult)
nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector, nsACString& oResult)
{
oResult = mCharset;
return NS_OK;
@ -200,10 +200,10 @@ nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUni
}
nsresult
nsPlatformCharset::InitGetCharset(nsAString &oString)
nsPlatformCharset::InitGetCharset(nsACString &oString)
{
char* nl_langinfo_codeset = nsnull;
nsString aCharset;
nsCString aCharset;
nsresult res;
#if HAVE_NL_LANGINFO && defined(CODESET)
@ -214,7 +214,7 @@ nsPlatformCharset::InitGetCharset(nsAString &oString)
// see if we can use nl_langinfo(CODESET) directly
//
if (nl_langinfo_codeset) {
aCharset.AssignWithConversion(nl_langinfo_codeset);
aCharset.Assign(nl_langinfo_codeset);
res = VerifyCharset(aCharset);
if (NS_SUCCEEDED(res)) {
oString = aCharset;
@ -263,8 +263,10 @@ nsPlatformCharset::InitGetCharset(nsAString &oString)
localeKey.AppendWithConversion(glibc_version);
localeKey.Append(NS_LITERAL_STRING("."));
localeKey.AppendWithConversion(nl_langinfo_codeset);
res = gNLInfo->Get(localeKey, aCharset);
nsAutoString uCharset;
res = gNLInfo->Get(localeKey, uCharset);
if (NS_SUCCEEDED(res)) {
aCharset.AssignWithConversion(uCharset);
res = VerifyCharset(aCharset);
if (NS_SUCCEEDED(res)) {
oString = aCharset;
@ -279,8 +281,10 @@ nsPlatformCharset::InitGetCharset(nsAString &oString)
//
localeKey.Assign(NS_LITERAL_STRING("nllic."));
localeKey.AppendWithConversion(nl_langinfo_codeset);
res = gNLInfo->Get(localeKey, aCharset);
nsAutoString uCharset;
res = gNLInfo->Get(localeKey, uCharset);
if (NS_SUCCEEDED(res)) {
aCharset.AssignWithConversion(uCharset);
res = VerifyCharset(aCharset);
if (NS_SUCCEEDED(res)) {
oString = aCharset;
@ -298,9 +302,10 @@ nsPlatformCharset::InitGetCharset(nsAString &oString)
char* locale = setlocale(LC_CTYPE, nsnull);
nsAutoString localeStr;
localeStr.AssignWithConversion(locale);
res = ConvertLocaleToCharsetUsingDeprecatedConfig(localeStr, aCharset);
nsAutoString uCharset;
res = ConvertLocaleToCharsetUsingDeprecatedConfig(localeStr, uCharset);
if (NS_SUCCEEDED(res)) {
oString = aCharset;
CopyUCS2toASCII(uCharset, oString);
return res; // succeeded
}
@ -310,7 +315,7 @@ nsPlatformCharset::InitGetCharset(nsAString &oString)
NS_IMETHODIMP
nsPlatformCharset::Init()
{
nsString charset;
nsCAutoString charset;
nsresult res;
//
@ -333,37 +338,27 @@ nsPlatformCharset::Init()
// last resort fallback
NS_ASSERTION(0, "unable to convert locale to charset using deprecated config");
mCharset.Assign(NS_LITERAL_STRING("ISO-8859-1"));
mCharset.Assign(NS_LITERAL_CSTRING("ISO-8859-1"));
return NS_SUCCESS_USING_FALLBACK_LOCALE;
}
nsresult
nsPlatformCharset::VerifyCharset(nsString &aCharset)
nsPlatformCharset::VerifyCharset(nsCString &aCharset)
{
nsresult res;
//
// get the convert manager
//
nsCOMPtr <nsICharsetConverterManager2> charsetConverterManager;
nsCOMPtr <nsICharsetConverterManager> charsetConverterManager;
charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
if (NS_FAILED(res))
return res;
//
// check if we recognize the charset string
//
nsCOMPtr <nsIAtom> charsetAtom;
res = charsetConverterManager->GetCharsetAtom(aCharset.get(),
getter_AddRefs(charsetAtom));
if (NS_FAILED(res)) {
return res;
}
//
// check if we can get an input converter
//
nsCOMPtr <nsIUnicodeEncoder> enc;
res = charsetConverterManager->GetUnicodeEncoder(charsetAtom, getter_AddRefs(enc));
res = charsetConverterManager->GetUnicodeEncoder(aCharset.get(), getter_AddRefs(enc));
if (NS_FAILED(res)) {
NS_ASSERTION(0, "failed to create encoder");
return res;
@ -373,35 +368,31 @@ nsPlatformCharset::VerifyCharset(nsString &aCharset)
// check if we can get an output converter
//
nsCOMPtr <nsIUnicodeDecoder> dec;
res = charsetConverterManager->GetUnicodeDecoder(charsetAtom, getter_AddRefs(dec));
res = charsetConverterManager->GetUnicodeDecoder(aCharset.get(), getter_AddRefs(dec));
if (NS_FAILED(res)) {
NS_ASSERTION(0, "failed to create decoder");
return res;
}
//
// check if we recognize the charset string
//
nsCAutoString result;
res = charsetConverterManager->GetCharsetAlias(aCharset.get(), result);
if (NS_FAILED(res)) {
return res;
}
//
// return the preferred string
//
const char *prefName;
res = charsetAtom->GetUTF8String(&prefName);
if (NS_SUCCEEDED(res))
aCharset.AssignWithConversion(prefName);
aCharset.Assign(result);
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get preferred charset name, using non-preferred");
return NS_OK;
}
nsresult
nsPlatformCharset::MapToCharset(short script, short region, nsAString& outCharset)
{
return NS_OK;
}
nsresult
nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsAString& outCharset)
{
return NS_OK;
}
nsresult
nsPlatformCharset::InitInfo()
{

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

@ -60,7 +60,7 @@ nsPlatformCharset::nsPlatformCharset()
UINT acp = ::GetACP();
PRInt32 acpint = (PRInt32)(acp & 0x00FFFF);
nsAutoString acpKey; acpKey.Assign(NS_LITERAL_STRING("acp."));
nsAutoString acpKey(NS_LITERAL_STRING("acp."));
acpKey.AppendInt(acpint, 10);
nsresult res = MapToCharset(acpKey, mCharset);
@ -92,36 +92,40 @@ nsPlatformCharset::InitInfo()
}
nsresult
nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsAString& outCharset)
nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsACString& outCharset)
{
//delay loading wincharset.properties bundle if possible
if (inANSICodePage.Equals(NS_LITERAL_STRING("acp.1252"))) {
outCharset = NS_LITERAL_STRING("windows-1252");
outCharset = NS_LITERAL_CSTRING("windows-1252");
return NS_OK;
}
if (inANSICodePage.Equals(NS_LITERAL_STRING("acp.932"))) {
outCharset = NS_LITERAL_STRING("Shift_JIS");
outCharset = NS_LITERAL_CSTRING("Shift_JIS");
return NS_OK;
}
// ensure the .property file is loaded
nsresult rv = InitInfo();
if (NS_FAILED(rv)) {
outCharset.Assign(NS_LITERAL_STRING("windows-1252"));
outCharset.Assign(NS_LITERAL_CSTRING("windows-1252"));
return rv;
}
rv = gInfo->Get(inANSICodePage, outCharset);
nsAutoString charset;
rv = gInfo->Get(inANSICodePage, charset);
if (NS_FAILED(rv)) {
outCharset.Assign(NS_LITERAL_STRING("windows-1252"));
outCharset.Assign(NS_LITERAL_CSTRING("windows-1252"));
return rv;
}
CopyUCS2toASCII(charset, outCharset);
return NS_OK;
}
NS_IMETHODIMP
nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector, nsAString& oResult)
nsPlatformCharset::GetCharset(nsPlatformCharsetSel selector,
nsACString& oResult)
{
oResult = mCharset;
return NS_OK;
@ -133,7 +137,7 @@ nsPlatformCharset::GetDefaultCharsetForLocale(const PRUnichar* localeName, PRUni
nsCOMPtr<nsIWin32Locale> winLocale;
LCID localeAsLCID;
char acp_name[6];
nsAutoString charset;
nsCAutoString charset;
nsAutoString localeAsNSString(localeName);
//
@ -165,13 +169,13 @@ nsPlatformCharset::Init()
}
nsresult
nsPlatformCharset::MapToCharset(short script, short region, nsAString& outCharset)
nsPlatformCharset::MapToCharset(short script, short region, nsACString& outCharset)
{
return NS_OK;
}
nsresult
nsPlatformCharset::InitGetCharset(nsAString &oString)
nsPlatformCharset::InitGetCharset(nsACString &oString)
{
return NS_OK;
}
@ -183,7 +187,7 @@ nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& loc
}
nsresult
nsPlatformCharset::VerifyCharset(nsString &aCharset)
nsPlatformCharset::VerifyCharset(nsCString &aCharset)
{
return NS_OK;
}

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

@ -38,9 +38,10 @@
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsUCSupport.h"
#include "nsString.h"
#include "nsIStringEnumerator.h"
#include "nsVoidArray.h"
//----------------------------------------------------------------------------
// Global functions and data [declaration]
@ -133,7 +134,7 @@ private:
nsresult TestTempBug();
nsresult Encode(PRUnichar ** aSrc, PRUnichar * aSrcEnd, char ** aDest,
char * aDestEnd, nsString * aCharset);
char * aDestEnd, const nsAFlatCString& aCharset);
/**
* Bridge methods between the new argument style (poiters) and the old one
@ -153,8 +154,6 @@ private:
void PrintSpaces(int aCount);
nsresult AddArray(nsISupportsArray * aDest, nsISupportsArray * aSrc);
public:
/**
@ -212,17 +211,25 @@ nsresult nsTestUConv::TestEncoders()
mLog.AddTrace(trace);
nsresult res = NS_OK;
nsCOMPtr<nsICharsetConverterManager2> ccMan =
nsCOMPtr<nsICharsetConverterManager> ccMan =
do_GetService(kCharsetConverterManagerCID, &res);
if (NS_FAILED(res)) return res;
nsCOMPtr<nsISupportsArray> encoders;
nsCOMPtr<nsIUTF8StringEnumerator> encoders;
res = ccMan->GetEncoderList(getter_AddRefs(encoders));
if (NS_FAILED(res)) return res;
PRUint32 encoderCount;
encoders->Count(&encoderCount);
printf("There are %d encoders\n", encoderCount);
PRUint32 encoderCount=0;
PRBool hasMore;
encoders->HasMore(&hasMore);
nsCAutoString charset;
while (hasMore) {
encoders->GetNext(charset);
encoders->HasMore(&hasMore);
}
mLog.DelTrace(trace);
return res;
@ -248,48 +255,13 @@ nsresult nsTestUConv::TestCharsetManager()
nsAutoString name;
nsCOMPtr<nsIAtom> csAtom;
nsCOMPtr<nsICharsetConverterManager2> ccMan =
nsCOMPtr<nsICharsetConverterManager> ccMan =
do_GetService(kCharsetConverterManagerCID, &res);
if (NS_FAILED(res)) {
mLog.PrintError("NS_WITH_SERVICE", res);
return res;
}
// test alias resolving capability
nsAutoString csAlias(NS_LITERAL_STRING("iso-10646-ucs-basic"));
nsAutoString csName(NS_LITERAL_STRING("UTF-16BE"));
res = ccMan->GetCharsetAtom(csAlias.get(), getter_AddRefs(csAtom));
if (NS_FAILED(res)) {
mLog.PrintError("GetCharsetAtom()", res);
return res;
}
res = csAtom->ToString(name);
if (NS_FAILED(res)) {
mLog.PrintError("get()", res);
return res;
}
if (!csName.Equals(name)) {
mLog.PrintError("Equals()", "unexpected charset name");
return NS_ERROR_UNEXPECTED;
}
// test self returning if alias was not found
nsAutoString csAlias2(NS_LITERAL_STRING("Totally_dummy_charset_name"));
res = ccMan->GetCharsetAtom(csAlias2.get(), getter_AddRefs(csAtom));
if (NS_FAILED(res)) {
mLog.PrintError("GetCharsetAtom()", res);
return res;
}
res = csAtom->ToString(name);
if (NS_FAILED(res)) {
mLog.PrintError("get()", res);
return res;
}
if (!csAlias2.Equals(name)) {
mLog.PrintError("Equals()", "unexpected charset name");
return NS_ERROR_UNEXPECTED;
}
mLog.DelTrace(trace);
return res;
}
@ -300,7 +272,7 @@ nsresult nsTestUConv::DisplayDetectors()
mLog.AddTrace(trace);
nsresult res = NS_OK;
nsCOMPtr<nsICharsetConverterManager2> ccMan =
nsCOMPtr<nsICharsetConverterManager> ccMan =
do_GetService(kCharsetConverterManagerCID, &res);
if (NS_FAILED(res)) {
mLog.PrintError("NS_WITH_SERVICE", res);
@ -308,48 +280,33 @@ nsresult nsTestUConv::DisplayDetectors()
}
// charset detectors
nsCOMPtr<nsISupportsArray> array;
nsCOMPtr<nsIUTF8StringEnumerator> detectors;
res = ccMan->GetCharsetDetectorList(getter_AddRefs(array));
res = ccMan->GetCharsetDetectorList(getter_AddRefs(detectors));
if (NS_FAILED(res)) {
mLog.PrintError("GetCharsetDetectorList()", res);
return res;
}
PRUint32 count;
res = array->Count(&count);
if (NS_FAILED(res)) {
mLog.PrintError("Count()", res);
return res;
}
printf("***** Character Set Detectors *****\n");
printf("***** Character Set Detectors [%d] *****\n", count);
for (PRUint32 i = 0; i < count; i++) {
nsCOMPtr<nsIAtom> cs;
nsAutoString str;
res = array->GetElementAt(i, getter_AddRefs(cs));
PRBool hasMore;
detectors->HasMore(&hasMore);
while (hasMore) {
nsCAutoString detectorName;
res = detectors->GetNext(detectorName);
if (NS_FAILED(res)) {
mLog.PrintError("GetElementAt()", res);
mLog.PrintError("GetNext()", res);
return res;
}
nsAutoString name;
res = cs->ToString(name);
if (NS_FAILED(res)) {
mLog.PrintError("get()", res);
return res;
}
printf("%s", detectorName.get());
PrintSpaces(36 - detectorName.Length()); // align to hard coded column number
str.Assign(name);
NS_LossyConvertUCS2toASCII buff(str);
printf("%s", buff.get());
PrintSpaces(36 - buff.Length()); // align to hard coded column number
res = ccMan->GetCharsetTitle2(cs, &str);
if (NS_FAILED(res)) str.SetLength(0);
printf("\"%s\"\n", NS_LossyConvertUCS2toASCII(str).get());
nsAutoString title;
res = ccMan->GetCharsetTitle(detectorName.get(), title);
if (NS_FAILED(res)) title.SetLength(0);
printf("\"%s\"\n", NS_LossyConvertUCS2toASCII(title).get());
}
mLog.DelTrace(trace);
@ -362,69 +319,58 @@ nsresult nsTestUConv::DisplayCharsets()
mLog.AddTrace(trace);
nsresult res = NS_OK;
nsCOMPtr<nsICharsetConverterManager2> ccMan =
nsCOMPtr<nsICharsetConverterManager> ccMan =
do_GetService(kCharsetConverterManagerCID, &res);
if (NS_FAILED(res)) {
mLog.PrintError("NS_WITH_SERVICE", res);
return res;
}
nsCOMPtr<nsISupportsArray> array;
nsCOMPtr<nsISupportsArray> encArray;
nsCOMPtr<nsIUTF8StringEnumerator> decoders;
nsCOMPtr<nsIUTF8StringEnumerator> encoders;
res = ccMan->GetDecoderList(getter_AddRefs(array));
res = ccMan->GetDecoderList(getter_AddRefs(decoders));
if (NS_FAILED(res)) {
mLog.PrintError("GetDecoderList()", res);
return res;
}
res = ccMan->GetEncoderList(getter_AddRefs(encArray));
res = ccMan->GetEncoderList(getter_AddRefs(encoders));
if (NS_FAILED(res)) {
mLog.PrintError("GetEncoderList()", res);
return res;
}
res = AddArray(array, encArray);
if (NS_FAILED(res)) return res;
PRUint32 count;
res = array->Count(&count);
if (NS_FAILED(res)) {
mLog.PrintError("Count()", res);
return res;
}
printf("***** Character Sets [%d] *****\n", count);
printf("***** Character Sets *****\n");
PRUint32 encCount = 0, decCount = 0;
PRUint32 basicEncCount = 0, basicDecCount = 0;
nsCStringArray allCharsets;
nsCAutoString charset;
PRBool hasMore;
encoders->HasMore(&hasMore);
while (hasMore) {
res = encoders->GetNext(charset);
if (NS_SUCCEEDED(res))
allCharsets.AppendCString(charset);
encoders->HasMore(&hasMore);
}
nsAutoString prop, str;
PRUint32 count = allCharsets.Count();
for (PRUint32 i = 0; i < count; i++) {
nsCOMPtr<nsIAtom> cs;
nsAutoString str;
nsAutoString prop;
res = array->GetElementAt(i, getter_AddRefs(cs));
if (NS_FAILED(res)) {
mLog.PrintError("GetElementAt()", res);
return res;
}
nsAutoString name;
res = cs->ToString(name);
if (NS_FAILED(res)) {
mLog.PrintError("get()", res);
return res;
}
str.Assign(name);
NS_LossyConvertUCS2toASCII buff(str);
printf("%s", buff.get());
PrintSpaces(24 - buff.Length()); // align to hard coded column number
const nsCString* charset = allCharsets[i];
printf("%s", charset->get());
PrintSpaces(24 - charset->Length()); // align to hard coded column number
nsCOMPtr<nsIUnicodeDecoder> dec = NULL;
res = ccMan->GetUnicodeDecoder(cs, getter_AddRefs(dec));
res = ccMan->GetUnicodeDecoder(charset->get(), getter_AddRefs(dec));
if (NS_FAILED(res)) printf (" ");
else {
printf("D");
@ -444,7 +390,7 @@ nsresult nsTestUConv::DisplayCharsets()
#endif
nsCOMPtr<nsIUnicodeEncoder> enc = NULL;
res = ccMan->GetUnicodeEncoder(cs, getter_AddRefs(enc));
res = ccMan->GetUnicodeEncoder(charset->get(), getter_AddRefs(enc));
if (NS_FAILED(res)) printf (" ");
else {
printf("E");
@ -466,27 +412,27 @@ nsresult nsTestUConv::DisplayCharsets()
printf(" ");
prop.Assign(NS_LITERAL_STRING(".notForBrowser"));
res = ccMan->GetCharsetData2(cs, prop.get(), &str);
res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
if ((dec != NULL) && (NS_FAILED(res))) printf ("B");
else printf("X");
prop.Assign(NS_LITERAL_STRING(".notForComposer"));
res = ccMan->GetCharsetData2(cs, prop.get(), &str);
res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
if ((enc != NULL) && (NS_FAILED(res))) printf ("C");
else printf("X");
prop.Assign(NS_LITERAL_STRING(".notForMailView"));
res = ccMan->GetCharsetData2(cs, prop.get(), &str);
res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
if ((dec != NULL) && (NS_FAILED(res))) printf ("V");
else printf("X");
prop.Assign(NS_LITERAL_STRING(".notForMailEdit"));
res = ccMan->GetCharsetData2(cs, prop.get(), &str);
res = ccMan->GetCharsetData(charset->get(), prop.get(), str);
if ((enc != NULL) && (NS_FAILED(res))) printf ("E");
else printf("X");
printf("(%3d, %3d) ", encCount, decCount);
res = ccMan->GetCharsetTitle2(cs, &str);
res = ccMan->GetCharsetTitle(charset->get(), str);
if (NS_FAILED(res)) str.SetLength(0);
NS_LossyConvertUCS2toASCII buff2(str);
printf(" \"%s\"\n", buff2.get());
@ -507,7 +453,7 @@ nsresult nsTestUConv::TestTempBug()
mLog.AddTrace(trace);
nsresult res = NS_OK;
nsAutoString charset(NS_LITERAL_STRING("ISO-2022-JP"));
NS_NAMED_LITERAL_CSTRING(charset, "ISO-2022-JP");
PRUnichar src[] = {0x0043, 0x004e, 0x0045, 0x0054, 0x0020, 0x004A, 0x0061,
0x0070, 0x0061, 0x006E, 0x0020, 0x7DE8, 0x96C6, 0x5C40};
PRUnichar * srcEnd = src + ARRAY_SIZE(src);
@ -516,7 +462,7 @@ nsresult nsTestUConv::TestTempBug()
PRUnichar * p = src;
char * q = dest;
res = Encode(&p, srcEnd, &q, destEnd, &charset);
res = Encode(&p, srcEnd, &q, destEnd, charset);
mLog.DelTrace(trace);
return res;
@ -524,7 +470,7 @@ nsresult nsTestUConv::TestTempBug()
nsresult nsTestUConv::Encode(PRUnichar ** aSrc, PRUnichar * aSrcEnd,
char ** aDest, char * aDestEnd,
nsString * aCharset)
const nsAFlatCString& aCharset)
{
char * trace = "Encode";
mLog.AddTrace(trace);
@ -538,7 +484,7 @@ nsresult nsTestUConv::Encode(PRUnichar ** aSrc, PRUnichar * aSrcEnd,
}
nsCOMPtr<nsIUnicodeEncoder> enc;
res = ccMan->GetUnicodeEncoder(aCharset, getter_AddRefs(enc));
res = ccMan->GetUnicodeEncoder(aCharset.get(), getter_AddRefs(enc));
if (NS_FAILED(res)) {
mLog.PrintError("GetUnicodeEncoder()", res);
return res;
@ -593,30 +539,6 @@ void nsTestUConv::PrintSpaces(int aCount)
for (int i = 0; i < aCount; i++) printf(" ");
}
nsresult nsTestUConv::AddArray(nsISupportsArray * aDest,
nsISupportsArray * aSrc)
{
nsresult res = NS_OK;
PRUint32 count, i;
res = aSrc->Count(&count);
if (NS_FAILED(res)) return res;
for (i = 0; i < count; i++) {
nsCOMPtr<nsISupports> elem;
res = aSrc->GetElementAt(i, getter_AddRefs(elem));
if (NS_FAILED(res)) return res;
PRInt32 index;
res = aDest->GetIndexOf(elem, &index);
if (NS_FAILED(res)) return res;
if (index < 0) res = aDest->AppendElement(elem);
}
return NS_OK;
}
nsresult nsTestUConv::Main(int aArgC, char ** aArgV)
{
char * trace = "Main";

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

@ -130,8 +130,7 @@ int main(int argc, const char** argv)
if(strcmp(argv[i], "-f") == 0)
{
tocodeind = i+1;
nsAutoString str; str.AssignWithConversion(argv[tocodeind]);
res = ccMain->GetUnicodeDecoder(&str, &decoder);
res = ccMain->GetUnicodeDecoder(argv[tocodeind], &decoder);
if(NS_FAILED(res)) {
fprintf(stderr, "Cannot get Unicode decoder %s %x\n",
argv[tocodeind],res);
@ -142,8 +141,7 @@ int main(int argc, const char** argv)
if(strcmp(argv[i], "-t") == 0)
{
fromcodeind = i+1;
nsAutoString str; str.AssignWithConversion(argv[fromcodeind]);
res = ccMain->GetUnicodeEncoder(&str, &encoder);
res = ccMain->GetUnicodeEncoderRaw(argv[fromcodeind], &encoder);
if(NS_FAILED(res)) {
fprintf(stderr, "Cannot get Unicode encoder %s %x\n",
argv[fromcodeind],res);

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

@ -112,11 +112,11 @@ int main(int argc, const char** argv)
if(strcmp(argv[i], "-f") == 0)
{
// User has specified the charset to convert from
nsAutoString str;
nsCAutoString str;
// First check if a charset alias was given,
// and convert to the canonical name
res = aliasmgr->GetPreferred(NS_ConvertASCIItoUCS2(argv[i+1]), str);
res = aliasmgr->GetPreferred(nsDependentCString(argv[i+1]), str);
if (NS_FAILED(res))
{
fprintf(stderr, "Cannot get charset alias for %s %x\n",
@ -125,7 +125,7 @@ int main(int argc, const char** argv)
}
// Finally create the decoder
res = ccMain->GetUnicodeDecoder(&str, &decoder);
res = ccMain->GetUnicodeDecoder(str.get(), &decoder);
if(NS_FAILED(res)) {
fprintf(stderr, "Cannot get Unicode decoder %s %x\n",
argv[i+1],res);
@ -137,11 +137,11 @@ int main(int argc, const char** argv)
if(strcmp(argv[i], "-t") == 0)
{
// User has specified which charset to convert to
nsAutoString str;
nsCAutoString str;
// First check if a charset alias was given,
// and convert to the canonical name
res = aliasmgr->GetPreferred(NS_ConvertASCIItoUCS2(argv[i+1]), str);
res = aliasmgr->GetPreferred(nsDependentCString(argv[i+1]), str);
if (NS_FAILED(res))
{
fprintf(stderr, "Cannot get charset alias for %s %x\n",
@ -150,7 +150,7 @@ int main(int argc, const char** argv)
}
// Finally create the encoder
res = ccMain->GetUnicodeEncoder(&str, &encoder);
res = ccMain->GetUnicodeEncoderRaw(str.get(), &encoder);
if(NS_FAILED(res)) {
fprintf(stderr, "Cannot get Unicode encoder %s %x\n",
argv[i+1],res);

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

@ -48,16 +48,12 @@ NS_IMETHODIMP nsISO2022CNToUnicode::GB2312_To_Unicode(unsigned char *aSrc, PRInt
if(!mGB2312_Decoder) {
// creating a delegate converter (GB2312)
nsAutoString tmpCharset;
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(kCharsetConverterManagerCID, &rv);
if(NS_FAILED(rv))
return NS_ERROR_UNEXPECTED;
tmpCharset.Assign(NS_LITERAL_STRING("GB2312"));
rv = ccm->GetUnicodeDecoder(&tmpCharset, getter_AddRefs(mGB2312_Decoder));
rv = ccm->GetUnicodeDecoderRaw("GB2312", getter_AddRefs(mGB2312_Decoder));
if(NS_FAILED(rv))
return NS_ERROR_UNEXPECTED;
}
@ -75,16 +71,12 @@ NS_IMETHODIMP nsISO2022CNToUnicode::EUCTW_To_Unicode(unsigned char *aSrc, PRInt3
if(!mEUCTW_Decoder) {
// creating a delegate converter (x-euc-tw)
nsAutoString tmpCharset;
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(kCharsetConverterManagerCID, &rv);
if(NS_FAILED(rv))
return NS_ERROR_UNEXPECTED;
tmpCharset.Assign(NS_LITERAL_STRING("x-euc-tw"));
rv = ccm->GetUnicodeDecoder(&tmpCharset, getter_AddRefs(mEUCTW_Decoder));
rv = ccm->GetUnicodeDecoderRaw("x-euc-tw", getter_AddRefs(mEUCTW_Decoder));
if(NS_FAILED(rv))
return NS_ERROR_UNEXPECTED;
}

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

@ -704,12 +704,10 @@ NS_IMETHODIMP nsISO2022JPToUnicodeV2::Convert(
if (!mGB2312Decoder) {
// creating a delegate converter (GB2312)
nsresult rv;
nsString tmpCharset;
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
tmpCharset.Assign(NS_LITERAL_STRING("GB2312"));
rv = ccm->GetUnicodeDecoder(&tmpCharset, &mGB2312Decoder);
rv = ccm->GetUnicodeDecoderRaw("GB2312", &mGB2312Decoder);
}
}
if (!mGB2312Decoder) {// failed creating a delegate converter
@ -758,12 +756,10 @@ NS_IMETHODIMP nsISO2022JPToUnicodeV2::Convert(
if (!mEUCKRDecoder) {
// creating a delegate converter (EUC-KR)
nsresult rv;
nsString tmpCharset;
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
tmpCharset.Assign(NS_LITERAL_STRING("EUC-KR"));
rv = ccm->GetUnicodeDecoder(&tmpCharset, &mEUCKRDecoder);
rv = ccm->GetUnicodeDecoderRaw("EUC-KR", &mEUCKRDecoder);
}
}
if (!mEUCKRDecoder) {// failed creating a delegate converter
@ -833,12 +829,10 @@ NS_IMETHODIMP nsISO2022JPToUnicodeV2::Convert(
if (!mISO88597Decoder) {
// creating a delegate converter (ISO-8859-7)
nsresult rv;
nsString tmpCharset;
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
tmpCharset.Assign(NS_LITERAL_STRING("ISO-8859-7"));
rv = ccm->GetUnicodeDecoder(&tmpCharset, &mISO88597Decoder);
rv = ccm->GetUnicodeDecoderRaw("ISO-8859-7", &mISO88597Decoder);
}
}
if (!mISO88597Decoder) {// failed creating a delegate converter

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

@ -142,12 +142,10 @@ NS_IMETHODIMP nsISO2022KRToUnicode::Convert(const char * aSrc, PRInt32 * aSrcLen
if (!mEUCKRDecoder) {
// creating a delegate converter (EUC-KR)
nsresult rv;
nsString tmpCharset;
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
tmpCharset.Assign(NS_LITERAL_STRING("EUC-KR"));
rv = ccm->GetUnicodeDecoder(&tmpCharset, &mEUCKRDecoder);
rv = ccm->GetUnicodeDecoderRaw("EUC-KR", &mEUCKRDecoder);
}
}

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

@ -58,7 +58,6 @@
#include "nsIUnicodeDecoder.h"
#include "nsIServiceManagerUtils.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsICharRepresentable.h"
#include <string.h>
@ -759,13 +758,10 @@ nsresult GetDecoder(nsIUnicodeDecoder** aDecoder)
return NS_OK;
}
nsCOMPtr<nsICharsetConverterManager2> charsetConverterManager;
nsCOMPtr<nsIAtom> charsetAtom;
nsCOMPtr<nsICharsetConverterManager> charsetConverterManager;
charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = charsetConverterManager->GetCharsetAtom2("EUC-KR", getter_AddRefs(charsetAtom));
NS_ENSURE_SUCCESS(rv,rv);
rv = charsetConverterManager->GetUnicodeDecoder(charsetAtom, getter_AddRefs(gDecoder));
rv = charsetConverterManager->GetUnicodeDecoderRaw("EUC-KR", getter_AddRefs(gDecoder));
NS_ENSURE_SUCCESS(rv,rv);
*aDecoder = gDecoder.get();

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

@ -46,6 +46,8 @@
#include "nsIGenericFactory.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICategoryManager.h"
#include "nsEncoderDecoderUtils.h"
#include "nsIModule.h"
#include "nsUCvMathCID.h"
#include "nsUCvMathDll.h"

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

@ -43,6 +43,7 @@
#include "nsIServiceManagerUtils.h"
#include "nsXPIDLString.h"
#include "nsICharsetConverterManager.h"
#include "nsEncoderDecoderUtils.h"
#include "nsCRT.h"
#include "prprf.h"

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

@ -42,7 +42,7 @@
#include "prprf.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsICharsetConverterManager.h"
#include "nsSaveAsCharset.h"
#include "nsCRT.h"
#include "nsUnicharUtils.h"
@ -361,14 +361,10 @@ nsresult nsSaveAsCharset::SetupUnicodeEncoder(const char* charset)
nsresult rv;
// set up unicode encoder
nsCOMPtr <nsICharsetConverterManager2> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr <nsIAtom> charsetAtom;
rv = ccm->GetCharsetAtom(NS_ConvertASCIItoUCS2(charset).get(), getter_AddRefs(charsetAtom));
NS_ENSURE_SUCCESS(rv, rv);
return ccm->GetUnicodeEncoder(charsetAtom, getter_AddRefs(mEncoder));
return ccm->GetUnicodeEncoder(charset, getter_AddRefs(mEncoder));
}
nsresult nsSaveAsCharset::SetupCharsetList(const char *charsetList)

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

@ -707,7 +707,8 @@ void
nsPresContext::UpdateCharSet(const PRUnichar* aCharSet)
{
if (mLangService) {
mLangService->LookupCharSet(aCharSet, getter_AddRefs(mLanguage));
mLangService->LookupCharSet(NS_LossyConvertUCS2toASCII(aCharSet).get(),
getter_AddRefs(mLanguage));
GetFontPreferences();
if (mLanguage) {
nsCOMPtr<nsIAtom> langGroupAtom;

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

@ -707,7 +707,8 @@ void
nsPresContext::UpdateCharSet(const PRUnichar* aCharSet)
{
if (mLangService) {
mLangService->LookupCharSet(aCharSet, getter_AddRefs(mLanguage));
mLangService->LookupCharSet(NS_LossyConvertUCS2toASCII(aCharSet).get(),
getter_AddRefs(mLanguage));
GetFontPreferences();
if (mLanguage) {
nsCOMPtr<nsIAtom> langGroupAtom;

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

@ -499,9 +499,9 @@ nsIsIndexFrame::OnSubmit(nsIPresContext* aPresContext)
return result;
}
void nsIsIndexFrame::GetSubmitCharset(nsString& oCharset)
void nsIsIndexFrame::GetSubmitCharset(nsCString& oCharset)
{
oCharset.Assign(NS_LITERAL_STRING("UTF-8")); // default to utf-8
oCharset.Assign(NS_LITERAL_CSTRING("UTF-8")); // default to utf-8
nsresult rv;
// XXX
// We may want to get it from the HTML 4 Accept-Charset attribute first
@ -511,7 +511,9 @@ void nsIsIndexFrame::GetSubmitCharset(nsString& oCharset)
nsIDocument* doc = nsnull;
mContent->GetDocument(doc);
if( nsnull != doc ) {
rv = doc->GetDocumentCharacterSet(oCharset);
nsAutoString docCharset;
rv = doc->GetDocumentCharacterSet(docCharset);
CopyUCS2toASCII(docCharset, oCharset);
NS_RELEASE(doc);
}
@ -520,7 +522,7 @@ void nsIsIndexFrame::GetSubmitCharset(nsString& oCharset)
NS_IMETHODIMP nsIsIndexFrame::GetEncoder(nsIUnicodeEncoder** encoder)
{
*encoder = nsnull;
nsAutoString charset;
nsCAutoString charset;
nsresult rv = NS_OK;
GetSubmitCharset(charset);
@ -530,7 +532,7 @@ NS_IMETHODIMP nsIsIndexFrame::GetEncoder(nsIUnicodeEncoder** encoder)
NS_GET_IID(nsICharsetConverterManager),
(nsISupports**)&ccm);
if(NS_SUCCEEDED(rv) && (nsnull != ccm)) {
rv = ccm->GetUnicodeEncoder(&charset, encoder);
rv = ccm->GetUnicodeEncoderRaw(charset.get(), encoder);
nsServiceManager::ReleaseService( kCharsetConverterManagerCID, ccm);
if (nsnull == encoder) {
rv = NS_ERROR_FAILURE;

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

@ -149,7 +149,7 @@ private:
NS_IMETHOD GetInputValue(nsIPresContext* aPresContext, nsString& oString);
NS_IMETHOD SetInputValue(nsIPresContext* aPresContext, const nsString aString);
void GetSubmitCharset(nsString& oCharset);
void GetSubmitCharset(nsCString& oCharset);
NS_IMETHOD GetEncoder(nsIUnicodeEncoder** encoder);
char* UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen, nsIUnicodeEncoder* encoder);
void URLEncode(const nsString& aString, nsIUnicodeEncoder* encoder, nsString& oString);

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

@ -499,9 +499,9 @@ nsIsIndexFrame::OnSubmit(nsIPresContext* aPresContext)
return result;
}
void nsIsIndexFrame::GetSubmitCharset(nsString& oCharset)
void nsIsIndexFrame::GetSubmitCharset(nsCString& oCharset)
{
oCharset.Assign(NS_LITERAL_STRING("UTF-8")); // default to utf-8
oCharset.Assign(NS_LITERAL_CSTRING("UTF-8")); // default to utf-8
nsresult rv;
// XXX
// We may want to get it from the HTML 4 Accept-Charset attribute first
@ -511,7 +511,9 @@ void nsIsIndexFrame::GetSubmitCharset(nsString& oCharset)
nsIDocument* doc = nsnull;
mContent->GetDocument(doc);
if( nsnull != doc ) {
rv = doc->GetDocumentCharacterSet(oCharset);
nsAutoString docCharset;
rv = doc->GetDocumentCharacterSet(docCharset);
CopyUCS2toASCII(docCharset, oCharset);
NS_RELEASE(doc);
}
@ -520,7 +522,7 @@ void nsIsIndexFrame::GetSubmitCharset(nsString& oCharset)
NS_IMETHODIMP nsIsIndexFrame::GetEncoder(nsIUnicodeEncoder** encoder)
{
*encoder = nsnull;
nsAutoString charset;
nsCAutoString charset;
nsresult rv = NS_OK;
GetSubmitCharset(charset);
@ -530,7 +532,7 @@ NS_IMETHODIMP nsIsIndexFrame::GetEncoder(nsIUnicodeEncoder** encoder)
NS_GET_IID(nsICharsetConverterManager),
(nsISupports**)&ccm);
if(NS_SUCCEEDED(rv) && (nsnull != ccm)) {
rv = ccm->GetUnicodeEncoder(&charset, encoder);
rv = ccm->GetUnicodeEncoderRaw(charset.get(), encoder);
nsServiceManager::ReleaseService( kCharsetConverterManagerCID, ccm);
if (nsnull == encoder) {
rv = NS_ERROR_FAILURE;

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

@ -149,7 +149,7 @@ private:
NS_IMETHOD GetInputValue(nsIPresContext* aPresContext, nsString& oString);
NS_IMETHOD SetInputValue(nsIPresContext* aPresContext, const nsString aString);
void GetSubmitCharset(nsString& oCharset);
void GetSubmitCharset(nsCString& oCharset);
NS_IMETHOD GetEncoder(nsIUnicodeEncoder** encoder);
char* UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen, nsIUnicodeEncoder* encoder);
void URLEncode(const nsString& aString, nsIUnicodeEncoder* encoder, nsString& oString);

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

@ -363,8 +363,8 @@ CSSLoaderImpl::RecycleParser(nsICSSParser* aParser)
// XXX We call this function a good bit. Consider caching the service
// in a static global or something?
static nsresult ResolveCharset(const nsAString& aCharsetAlias,
nsAString& aCharset)
static nsresult ResolveCharset(const nsACString& aCharsetAlias,
nsACString& aCharset)
{
nsresult rv = NS_ERROR_NOT_AVAILABLE;
if (! aCharsetAlias.IsEmpty()) {
@ -382,7 +382,7 @@ static const char kCharsetSym[] = "@charset";
static nsresult GetCharsetFromData(const unsigned char* aStyleSheetData,
PRUint32 aDataLength,
nsAString& aCharset)
nsACString& aCharset)
{
aCharset.Truncate();
if (aDataLength <= sizeof(kCharsetSym) - 1)
@ -544,7 +544,8 @@ static nsresult GetCharsetFromData(const unsigned char* aStyleSheetData,
break;
}
aCharset.Append(PRUnichar(aStyleSheetData[pos]));
// casting to avoid ambiguities
aCharset.Append(char(aStyleSheetData[pos]));
pos += step;
}
@ -584,18 +585,15 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
* default (document charset or ISO-8859-1 if we have no document
* charset)
*/
nsAutoString charset;
nsAutoString charsetCandidate;
nsCAutoString charset, charsetCandidate;
if (channel) {
nsCAutoString charsetVal;
channel->GetContentCharset(charsetVal);
CopyASCIItoUCS2(charsetVal, charsetCandidate);
channel->GetContentCharset(charsetCandidate);
}
result = NS_ERROR_NOT_AVAILABLE;
if (! charsetCandidate.IsEmpty()) {
#ifdef DEBUG_bzbarsky
fprintf(stderr, "Setting from HTTP to: %s\n", NS_ConvertUCS2toUTF8(charsetCandidate).get());
fprintf(stderr, "Setting from HTTP to: %s\n", charsetCandidate.get());
#endif
result = ResolveCharset(charsetCandidate, charset);
}
@ -608,7 +606,7 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
if (NS_SUCCEEDED(result)) {
#ifdef DEBUG_bzbarsky
fprintf(stderr, "Setting from @charset rule: %s\n",
NS_ConvertUCS2toUTF8(charsetCandidate).get());
charsetCandidate.get());
#endif
result = ResolveCharset(charsetCandidate, charset);
}
@ -618,11 +616,13 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
// Now try the charset on the <link> or processing instruction
// that loaded us
if (mOwningElement) {
mOwningElement->GetCharset(charsetCandidate);
nsAutoString elementCharset;
mOwningElement->GetCharset(elementCharset);
CopyUCS2toASCII(elementCharset, charsetCandidate);
if (! charsetCandidate.IsEmpty()) {
#ifdef DEBUG_bzbarsky
fprintf(stderr, "Setting from property on element: %s\n",
NS_ConvertUCS2toUTF8(charsetCandidate).get());
charsetCandidate.get());
#endif
result = ResolveCharset(charsetCandidate, charset);
}
@ -632,19 +632,21 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
if (NS_FAILED(result) && mLoader->mDocument) {
// no useful data on charset. Try the document charset.
// That needs no resolution, since it's already fully resolved
mLoader->mDocument->GetDocumentCharacterSet(charset);
nsAutoString docCharset;
mLoader->mDocument->GetDocumentCharacterSet(docCharset);
CopyUCS2toASCII(docCharset, charset);
#ifdef DEBUG_bzbarsky
fprintf(stderr, "Set from document: %s\n",
NS_ConvertUCS2toUTF8(charset).get());
charset.get());
#endif
}
if (charset.IsEmpty()) {
NS_WARNING("Unable to determine charset for sheet, using ISO-8859-1!");
charset = NS_LITERAL_STRING("ISO-8859-1");
charset = NS_LITERAL_CSTRING("ISO-8859-1");
}
aCharset = NS_ConvertUCS2toUTF8(charset);
aCharset = charset;
return NS_OK;
}
@ -1284,7 +1286,7 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
// 8192 is a nice magic number that happens to be what a lot of
// other things use for buffer sizes.
rv = converterStream->Init(stream, NS_LITERAL_STRING("UTF-8").get(),
rv = converterStream->Init(stream, "UTF-8",
8192, PR_TRUE);
if (NS_FAILED(rv)) {

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

@ -101,7 +101,7 @@ interface nsIMessenger : nsISupports {
void Undo(in nsIMsgWindow msgWindow);
void Redo(in nsIMsgWindow msgWindow);
void sendUnsentMessages(in nsIMsgIdentity aIdentity, in nsIMsgWindow aMsgWindow);
void SetDocumentCharset(in wstring characterSet);
void SetDocumentCharset(in string characterSet);
void saveAs(in string aURI, in boolean aAsFile, in nsIMsgIdentity aIdentity, in nsIMsgWindow aMsgWindow);
void openAttachment(in string contentTpe, in string url, in string displayName, in string messageUri);
void saveAttachment(in string contentTpe, in string url, in string displayName, in string messageUri);

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

@ -329,7 +329,7 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne
/**
* the charset of this folder
*/
attribute wstring charset;
attribute string charset;
attribute boolean charsetOverride;
attribute unsigned long biffState;

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

@ -141,9 +141,9 @@ interface nsIMsgMessageUrl : nsISupports {
[scriptable, uuid(D71E0785-2862-11d4-98C1-001083010E9B)]
interface nsIMsgI18NUrl : nsISupports {
// the charset associated with a folder for this url.....
readonly attribute wstring folderCharset;
readonly attribute string folderCharset;
readonly attribute boolean folderCharsetOverride;
// the charsetOverRide is a charset the user may have specified via the menu for
// a particular message
attribute wstring charsetOverRide;
attribute string charsetOverRide;
};

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

@ -95,7 +95,7 @@ interface nsIMsgMessageService : nsISupports {
in nsISupports aDisplayConsumer,
in nsIMsgWindow aMsgWindow,
in nsIUrlListener aUrlListener,
in wstring aCharsetOverride,
in string aCharsetOverride,
out nsIURI aURL);
/////////////////////////////////////////////////////////////////////

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

@ -73,7 +73,7 @@ interface nsIMsgWindow : nsISupports {
readonly attribute nsIPrompt promptDialog;
readonly attribute nsIAuthPrompt authPromptDialog;
attribute wstring mailCharacterSet;
attribute string mailCharacterSet;
// Remember the message's charaset was overridden, so it can be inherited (e.g for quoting).
attribute boolean charsetOverride;

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше