mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Changed to return a result code for conversions so the caller can try fallback,
also changed convert from Unicode to try keyscript in addition to the system default, bug 108029, r=pinkerton, sr=sfraser, a=asa.
This commit is contained in:
parent
d29e68ff5c
commit
731a9d29c2
@ -128,12 +128,12 @@ nsPrimitiveHelpers :: CreateDataFromPrimitive ( const char* aFlavor, nsISupports
|
||||
// string, not the # of bytes in the buffer. The |outPlainTextData| is null terminated,
|
||||
// but its length parameter, |outPlainTextLen|, does not reflect that.
|
||||
//
|
||||
void
|
||||
nsresult
|
||||
nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode, PRInt32 inUnicodeLen,
|
||||
char** outPlainTextData, PRInt32* outPlainTextLen )
|
||||
{
|
||||
if ( !outPlainTextData || !outPlainTextLen )
|
||||
return;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// Get the appropriate unicode encoder. We're guaranteed that this won't change
|
||||
// through the life of the app so we can cache it.
|
||||
@ -147,22 +147,36 @@ nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode,
|
||||
rv = platformCharsetService->GetCharset(kPlatformCharsetSel_PlainTextInClipboard, platformCharset);
|
||||
if (NS_FAILED(rv))
|
||||
platformCharset.Assign(NS_LITERAL_STRING("ISO-8859-1"));
|
||||
else {
|
||||
// also get a keyboard charset and use it as a fallback
|
||||
nsAutoString keyboardCharset;
|
||||
rv = platformCharsetService->GetCharset(kPlatformCharsetSel_KeyboardInput, keyboardCharset);
|
||||
if (NS_SUCCEEDED(rv) &&
|
||||
!keyboardCharset.Equals(platformCharset)) {
|
||||
platformCharset.Append((PRUnichar)',');
|
||||
platformCharset.Append(keyboardCharset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// use transliterate to convert things like smart quotes to normal quotes for plain text
|
||||
nsCAutoString cPlatformCharset;
|
||||
cPlatformCharset.AssignWithConversion(platformCharset);
|
||||
|
||||
nsCOMPtr<nsISaveAsCharset> converter = do_CreateInstance("@mozilla.org/intl/saveascharset;1");
|
||||
converter->Init(cPlatformCharset.get(),
|
||||
rv = converter->Init(cPlatformCharset.get(),
|
||||
nsISaveAsCharset::attr_EntityAfterCharsetConv +
|
||||
nsISaveAsCharset::attr_FallbackQuestionMark,
|
||||
nsISaveAsCharset::attr_FallbackQuestionMark +
|
||||
nsISaveAsCharset::attr_CharsetFallback,
|
||||
nsIEntityConverter::transliterate);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
converter->Convert(inUnicode, outPlainTextData);
|
||||
rv = converter->Convert(inUnicode, outPlainTextData);
|
||||
*outPlainTextLen = *outPlainTextData ? strlen(*outPlainTextData) : 0;
|
||||
|
||||
NS_ASSERTION ( NS_SUCCEEDED(rv), "Error converting unicode to plain text" );
|
||||
|
||||
return rv;
|
||||
} // ConvertUnicodeToPlatformPlainText
|
||||
|
||||
|
||||
@ -174,12 +188,12 @@ nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode,
|
||||
// but its length parameter, |outUnicodeLen|, does not reflect that. |outUnicodeLen| is
|
||||
// the length of the string in characters, not bytes.
|
||||
//
|
||||
void
|
||||
nsresult
|
||||
nsPrimitiveHelpers :: ConvertPlatformPlainTextToUnicode ( const char* inText, PRInt32 inTextLen,
|
||||
PRUnichar** outUnicode, PRInt32* outUnicodeLen )
|
||||
{
|
||||
if ( !outUnicode || !outUnicodeLen )
|
||||
return;
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// Get the appropriate unicode decoder. We're guaranteed that this won't change
|
||||
// through the life of the app so we can cache it.
|
||||
@ -216,6 +230,7 @@ nsPrimitiveHelpers :: ConvertPlatformPlainTextToUnicode ( const char* inText, PR
|
||||
|
||||
NS_ASSERTION ( NS_SUCCEEDED(rv), "Error converting plain text to unicode" );
|
||||
|
||||
return rv;
|
||||
} // ConvertPlatformPlainTextToUnicode
|
||||
|
||||
|
||||
|
@ -50,14 +50,14 @@ public:
|
||||
// the appropriate platform charset encoding. |inUnicodeLen| is the length of the input
|
||||
// string, not the # of bytes in the buffer. |outPlainTextData| is null terminated,
|
||||
// but its length parameter, |outPlainTextLen|, does not reflect that.
|
||||
static void ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode, PRInt32 inUnicodeLen,
|
||||
static nsresult ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode, PRInt32 inUnicodeLen,
|
||||
char** outPlainTextData, PRInt32* outPlainTextLen ) ;
|
||||
|
||||
// Given a char buffer (flavor text/plaikn), this converts it to unicode using
|
||||
// the appropriate platform charset encoding. |outUnicode| is null terminated,
|
||||
// but its length parameter, |outUnicodeLen|, does not reflect that. |outUnicodeLen| is
|
||||
// the length of the string in characters, not bytes.
|
||||
static void ConvertPlatformPlainTextToUnicode ( const char* inText, PRInt32 inTextLen,
|
||||
static nsresult ConvertPlatformPlainTextToUnicode ( const char* inText, PRInt32 inTextLen,
|
||||
PRUnichar** outUnicode, PRInt32* outUnicodeLen ) ;
|
||||
|
||||
}; // class nsPrimitiveHelpers
|
||||
|
Loading…
Reference in New Issue
Block a user