Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions
nsTextToSubURI Class Reference

#include <nsTextToSubURI.h>

Inheritance diagram for nsTextToSubURI:
Inheritance graph
[legend]
Collaboration diagram for nsTextToSubURI:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsTextToSubURI ()
virtual ~nsTextToSubURI ()
string ConvertAndEscape (in string charset, in wstring text)
wstring UnEscapeAndConvert (in string charset, in string text)
AString unEscapeURIForUI (in ACString aCharset, in AUTF8String aURIFragment)
 Unescapes the given URI fragment (for UI purpose only) Note:
AString unEscapeNonAsciiURI (in ACString aCharset, in AUTF8String aURIFragment)
 Unescapes only non ASCII characters in the given URI fragment note: this method assumes the URI as UTF-8 and fallbacks to the given charset in case the data is not UTF-8.

Private Member Functions

nsresult convertURItoUnicode (const nsAFlatCString &aCharset, const nsAFlatCString &aURI, PRBool aIRI, nsAString &_retval)

Detailed Description

Definition at line 43 of file nsTextToSubURI.h.


Constructor & Destructor Documentation

Definition at line 52 of file nsTextToSubURI.cpp.

{
}

Definition at line 55 of file nsTextToSubURI.cpp.

{
}

Member Function Documentation

string nsITextToSubURI::ConvertAndEscape ( in string  charset,
in wstring  text 
) [inherited]
nsresult nsTextToSubURI::convertURItoUnicode ( const nsAFlatCString aCharset,
const nsAFlatCString aURI,
PRBool  aIRI,
nsAString &  _retval 
) [private]

Definition at line 171 of file nsTextToSubURI.cpp.

{
  nsresult rv = NS_OK;

  // check for 7bit encoding the data may not be ASCII after we decode
  PRBool isStatefulCharset = statefulCharset(aCharset.get());

  if (!isStatefulCharset && IsASCII(aURI)) {
    CopyASCIItoUTF16(aURI, _retval);
    return rv;
  }

  if (!isStatefulCharset && aIRI) {
    if (IsUTF8(aURI)) {
      CopyUTF8toUTF16(aURI, _retval);
      return rv;
    }
  }

  // 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<nsICharsetConverterManager> charsetConverterManager;

  charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
  rv = charsetConverterManager->GetUnicodeDecoder(aCharset.get(), 
                                                  getter_AddRefs(unicodeDecoder));
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 srcLen = aURI.Length();
  PRInt32 dstLen;
  rv = unicodeDecoder->GetMaxLength(aURI.get(), srcLen, &dstLen);
  NS_ENSURE_SUCCESS(rv, rv);

  PRUnichar *ustr = (PRUnichar *) nsMemory::Alloc(dstLen * sizeof(PRUnichar));
  NS_ENSURE_TRUE(ustr, NS_ERROR_OUT_OF_MEMORY);

  rv = unicodeDecoder->Convert(aURI.get(), &srcLen, ustr, &dstLen);

  if (NS_SUCCEEDED(rv))
    _retval.Assign(ustr, dstLen);
  
  nsMemory::Free(ustr);

  return rv;
}

Here is the call graph for this function:

wstring nsITextToSubURI::UnEscapeAndConvert ( in string  charset,
in string  text 
) [inherited]

Here is the caller graph for this function:

AString nsITextToSubURI::unEscapeNonAsciiURI ( in ACString  aCharset,
in AUTF8String  aURIFragment 
) [inherited]

Unescapes only non ASCII characters in the given URI fragment note: this method assumes the URI as UTF-8 and fallbacks to the given charset in case the data is not UTF-8.

Parameters:
aCharsetthe charset to convert from
aURIFragmentthe URI (or URI fragment) to unescape
Returns:
Unescaped aURIFragment converted to unicode
Exceptions:
NS_ERROR_UCONV_NOCONVwhen there is no decoder for aCharset or error code of nsIUnicodeDecoder in case of conversion failure
AString nsITextToSubURI::unEscapeURIForUI ( in ACString  aCharset,
in AUTF8String  aURIFragment 
) [inherited]

Unescapes the given URI fragment (for UI purpose only) Note:

  • escaping back the result (unescaped string) is not guaranteed to give the original escaped string
  • In case of a conversion error, the URI fragment (escaped) is assumed to be in UTF-8 and converted to AString (UTF-16)
  • Always succeeeds (callers don't need to do error checking)
Parameters:
aCharsetthe charset to convert from
aURIFragmentthe URI (or URI fragment) to unescape
Returns:
Unescaped aURIFragment converted to unicode

The documentation for this class was generated from the following files: