Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes
nsCollation Struct Reference

#include <nsCollation.h>

Collaboration diagram for nsCollation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsCollation ()
 ~nsCollation ()
nsresult NormalizeString (const nsAString &stringIn, nsAString &stringOut)
nsresult SetCharset (const char *aCharset)
nsresult UnicodeToChar (const nsAString &aSrc, char **dst)

Protected Attributes

nsCOMPtr< nsICaseConversionmCaseConversion
nsCOMPtr< nsIUnicodeEncodermEncoder

Detailed Description

Definition at line 62 of file nsCollation.h.


Constructor & Destructor Documentation

Definition at line 74 of file nsCollation.cpp.

{
  MOZ_COUNT_CTOR(nsCollation);
  nsresult res;
  mCaseConversion = do_GetService(NS_UNICHARUTIL_CONTRACTID, &res);
  NS_ASSERTION(NS_SUCCEEDED(res), "CreateInstance failed for kCaseConversionIID");
}

Here is the call graph for this function:

Definition at line 82 of file nsCollation.cpp.


Member Function Documentation

nsresult nsCollation::NormalizeString ( const nsAString &  stringIn,
nsAString &  stringOut 
)

Definition at line 87 of file nsCollation.cpp.

{
  if (!mCaseConversion) {
    stringOut = stringIn;
  }
  else {
    PRInt32 aLength = stringIn.Length();

    if (aLength <= 64) {
      PRUnichar conversionBuffer[64];
      mCaseConversion->ToLower(PromiseFlatString(stringIn).get(), conversionBuffer, aLength);
      stringOut.Assign(conversionBuffer, aLength);
    }
    else {
      PRUnichar* conversionBuffer;
      conversionBuffer = new PRUnichar[aLength];
      if (!conversionBuffer) {
        return NS_ERROR_OUT_OF_MEMORY;
      }
      mCaseConversion->ToLower(PromiseFlatString(stringIn).get(), conversionBuffer, aLength);
      stringOut.Assign(conversionBuffer, aLength);
      delete [] conversionBuffer;
    }
  }
  return NS_OK;
}
nsresult nsCollation::SetCharset ( const char *  aCharset)

Definition at line 114 of file nsCollation.cpp.

{
  NS_ENSURE_ARG_POINTER(aCharset);

  nsresult rv;
  nsCOMPtr <nsICharsetConverterManager> charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
  if (NS_SUCCEEDED(rv)) {
    rv = charsetConverterManager->GetUnicodeEncoder(aCharset,
                                                    getter_AddRefs(mEncoder));
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCollation::UnicodeToChar ( const nsAString &  aSrc,
char **  dst 
)

Definition at line 127 of file nsCollation.cpp.

{
  NS_ENSURE_ARG_POINTER(dst);

  nsresult res = NS_OK;
  if (!mEncoder)
    res = SetCharset("ISO-8859-1");

  if (NS_SUCCEEDED(res)) {
    const nsPromiseFlatString& src = PromiseFlatString(aSrc);
    const PRUnichar *unichars = src.get();
    PRInt32 unicharLength = src.Length();
    PRInt32 dstLength;
    res = mEncoder->GetMaxLength(unichars, unicharLength, &dstLength);
    if (NS_SUCCEEDED(res)) {
      PRInt32 bufLength = dstLength + 1 + 32; // extra 32 bytes for Finish() call
      *dst = (char *) PR_Malloc(bufLength);
      if (*dst) {
        **dst = '\0';
        res = mEncoder->Convert(unichars, &unicharLength, *dst, &dstLength);

        if (NS_SUCCEEDED(res) || (NS_ERROR_UENC_NOMAPPING == res)) {
          // Finishes the conversion. The converter has the possibility to write some 
          // extra data and flush its final state.
          PRInt32 finishLength = bufLength - dstLength; // remaining unused buffer length
          if (finishLength > 0) {
            res = mEncoder->Finish((*dst + dstLength), &finishLength);
            if (NS_SUCCEEDED(res)) {
              (*dst)[dstLength + finishLength] = '\0';
            }
          }
        }
        if (NS_FAILED(res)) {
          PR_Free(*dst);
          *dst = nsnull;
        }
      }
      else {
        res = NS_ERROR_OUT_OF_MEMORY;
      }
    }
  }

  return res;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 78 of file nsCollation.h.

Definition at line 79 of file nsCollation.h.


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