Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
nsEntityConverter Class Reference

#include <nsEntityConverter.h>

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

List of all members.

Public Member Functions

 nsEntityConverter ()
virtual ~nsEntityConverter ()
NS_DECL_ISUPPORTS NS_IMETHOD ConvertUTF32ToEntity (PRUint32 character, PRUint32 entityVersion, char **_retval)
NS_IMETHOD ConvertToEntity (PRUnichar character, PRUint32 entityVersion, char **_retval)
NS_IMETHOD ConvertToEntities (const PRUnichar *inString, PRUint32 entityVersion, PRUnichar **_retval)
string ConvertUTF32ToEntity (in unsigned long character, in unsigned long entityVersion)
string ConvertToEntity (in wchar character, in unsigned long entityVersion)
wstring ConvertToEntities (in wstring inString, in unsigned long entityVersion)

Public Attributes

const unsigned long entityNone = 0
const unsigned long html40Latin1 = 1
const unsigned long html40Symbols = 2
const unsigned long html40Special = 4
const unsigned long transliterate = 8
const unsigned long mathml20 = 16
const unsigned long html32 = html40Latin1
const unsigned long html40 = html40Latin1+html40Symbols+html40Special
const unsigned long entityW3C = html40+mathml20

Protected Member Functions

NS_IMETHOD LoadVersionPropertyFile ()
const PRUnicharGetVersionName (PRUint32 versionNumber)
nsIStringBundleGetVersionBundleInstance (PRUint32 versionNumber)
already_AddRefed< nsIStringBundleLoadEntityBundle (PRUint32 version)

Protected Attributes

nsEntityVersionListmVersionList
PRUint32 mVersionListLength

Detailed Description

Definition at line 57 of file nsEntityConverter.h.


Constructor & Destructor Documentation

Definition at line 52 of file nsEntityConverter.cpp.

Definition at line 58 of file nsEntityConverter.cpp.

{
  if (NULL != mVersionList) delete [] mVersionList;
}

Member Function Documentation

wstring nsIEntityConverter::ConvertToEntities ( in wstring  inString,
in unsigned long  entityVersion 
) [inherited]
NS_IMETHODIMP nsEntityConverter::ConvertToEntities ( const PRUnichar inString,
PRUint32  entityVersion,
PRUnichar **  _retval 
)

Definition at line 221 of file nsEntityConverter.cpp.

{
  NS_ASSERTION(inString, "null ptr- inString");
  NS_ASSERTION(_retval, "null ptr- _retval");
  if((nsnull == inString) || (nsnull == _retval))
    return NS_ERROR_NULL_POINTER;
  *_retval = NULL;

  const PRUnichar *entity = NULL;
  nsString outString;

  // per character look for the entity
  PRUint32 len = nsCRT::strlen(inString);
  for (PRUint32 i = 0; i < len; i++) {
    nsAutoString key(NS_LITERAL_STRING("entity."));
    if (IS_HIGH_SURROGATE(inString[i]) &&
        i + 2 < len &&
        IS_LOW_SURROGATE(inString[i + 1])) {
      key.AppendInt(SURROGATE_TO_UCS4(inString[i], inString[++i]), 10);
    }
    else {
      key.AppendInt(inString[i],10);
    }
    
    nsXPIDLString value;
    
    entity = NULL;
    for (PRUint32 mask = 1, mask2 = 0xFFFFFFFFL; (0!=(entityVersion & mask2)); mask<<=1, mask2<<=1) {
      if (0 == (entityVersion & mask)) 
         continue;
      nsIStringBundle* entities = GetVersionBundleInstance(entityVersion & mask);
      NS_ASSERTION(entities, "Cannot get the property file");

      if (NULL == entities) 
          continue;

      nsresult rv = entities->GetStringFromName(key.get(),
                                                getter_Copies(value));
      if (NS_SUCCEEDED(rv)) {
        entity = value.get();
        break;
      }
    }
    if (NULL != entity) {
      outString.Append(entity);
    }
    else {
      outString.Append(&inString[i], 1);
    }
  }

  *_retval = ToNewUnicode(outString);
  if (NULL == *_retval) 
    return NS_ERROR_OUT_OF_MEMORY;

  return NS_OK;
}

Here is the call graph for this function:

string nsIEntityConverter::ConvertToEntity ( in wchar  character,
in unsigned long  entityVersion 
) [inherited]
NS_IMETHODIMP nsEntityConverter::ConvertToEntity ( PRUnichar  character,
PRUint32  entityVersion,
char **  _retval 
)

Definition at line 182 of file nsEntityConverter.cpp.

{ 
  return ConvertUTF32ToEntity((PRUint32)character, entityVersion, _retval);
}
string nsIEntityConverter::ConvertUTF32ToEntity ( in unsigned long  character,
in unsigned long  entityVersion 
) [inherited]
NS_IMETHODIMP nsEntityConverter::ConvertUTF32ToEntity ( PRUint32  character,
PRUint32  entityVersion,
char **  _retval 
)

Definition at line 188 of file nsEntityConverter.cpp.

{
  NS_ASSERTION(_retval, "null ptr- _retval");
  if(nsnull == _retval)
    return NS_ERROR_NULL_POINTER;
  *_retval = NULL;

  for (PRUint32 mask = 1, mask2 = 0xFFFFFFFFL; (0!=(entityVersion & mask2)); mask<<=1, mask2<<=1) {
    if (0 == (entityVersion & mask)) 
      continue;
    nsIStringBundle* entities = GetVersionBundleInstance(entityVersion & mask);
    NS_ASSERTION(entities, "Cannot get the property file");

    if (NULL == entities) 
      continue;

    nsAutoString key(NS_LITERAL_STRING("entity."));
    key.AppendInt(character,10);

    nsXPIDLString value;
    nsresult rv = entities->GetStringFromName(key.get(), getter_Copies(value));
    if (NS_SUCCEEDED(rv)) {
      *_retval = ToNewCString(value);
      if(nsnull == *_retval)
        return NS_ERROR_OUT_OF_MEMORY;
      else
        return NS_OK;
    }
  }
       return NS_ERROR_ILLEGAL_VALUE;
}

Here is the call graph for this function:

Definition at line 146 of file nsEntityConverter.cpp.

{
  if (NULL == mVersionList) {
    // load the property file which contains available version names
    // and generate a list of version/name pair
    nsresult rv = LoadVersionPropertyFile();
    if (NS_FAILED(rv)) return NULL;
  }

  PRUint32 i;
  for (i = 0; i < mVersionListLength; i++) {
    if (versionNumber == mVersionList[i].mVersion) {
      if (!mVersionList[i].mEntities)
      { // not loaded
        // load the property file
        mVersionList[i].mEntities = LoadEntityBundle(versionNumber);
        NS_ASSERTION(mVersionList[i].mEntities, "LoadEntityBundle failed");
      }
      return mVersionList[i].mEntities.get();
    }
  }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const PRUnichar * nsEntityConverter::GetVersionName ( PRUint32  versionNumber) [protected]

Definition at line 135 of file nsEntityConverter.cpp.

{
  for (PRUint32 i = 0; i < mVersionListLength; i++) {
    if (versionNumber == mVersionList[i].mVersion)
      return mVersionList[i].mEntityListName;
  }

  return NULL;
}

Here is the caller graph for this function:

Definition at line 109 of file nsEntityConverter.cpp.

{
  nsCAutoString url(NS_LITERAL_CSTRING("resource://gre/res/entityTables/"));
  const PRUnichar *versionName = NULL;
  nsresult rv;

  nsCOMPtr<nsIStringBundleService> bundleService =
      do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return NULL;
  
  versionName = GetVersionName(version);
  if (NULL == versionName) return NULL;

  // all property file names are ASCII, like "html40Latin1" so this is safe
  LossyAppendUTF16toASCII(versionName, url);
  url.Append(".properties");

  nsIStringBundle* bundle;
  rv = bundleService->CreateBundle(url.get(), &bundle);
  if (NS_FAILED(rv)) return NULL;
  
  // does this addref right?
  return bundle;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 64 of file nsEntityConverter.cpp.

{
    NS_NAMED_LITERAL_CSTRING(url, "resource://gre/res/entityTables/htmlEntityVersions.properties");
       nsresult rv;
    nsCOMPtr<nsIStringBundleService> bundleService =
        do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);

    if (NS_FAILED(rv)) return rv;
    
    nsCOMPtr<nsIStringBundle> entities;
    rv = bundleService->CreateBundle(url.get(), getter_AddRefs(entities));
    if (NS_FAILED(rv)) return rv;
    
    PRInt32   result;

    nsAutoString key;
    nsXPIDLString value;
    rv = entities->GetStringFromName(NS_LITERAL_STRING("length").get(),
                                     getter_Copies(value));
    NS_ASSERTION(NS_SUCCEEDED(rv),"nsEntityConverter: malformed entity table\n");
    if (NS_FAILED(rv)) return rv;
      
    mVersionListLength = nsAutoString(value).ToInteger(&result);
    NS_ASSERTION(32 >= mVersionListLength,"nsEntityConverter: malformed entity table\n");
    if (32 < mVersionListLength) return NS_ERROR_FAILURE;
    
    mVersionList = new nsEntityVersionList[mVersionListLength];
    if (!mVersionList) return NS_ERROR_OUT_OF_MEMORY;

    for (PRUint32 i = 0; i < mVersionListLength && NS_SUCCEEDED(rv); i++) {
        key.SetLength(0);
        key.AppendInt(i+1, 10);
        rv = entities->GetStringFromName(key.get(), getter_Copies(value));
        PRUint32 len = value.Length();
        if (kVERSION_STRING_LEN < len) return NS_ERROR_UNEXPECTED;
        
        memcpy(mVersionList[i].mEntityListName, value.get(), len*sizeof(PRUnichar));
        mVersionList[i].mEntityListName[len] = 0;
        mVersionList[i].mVersion = (1 << i);
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const unsigned long nsIEntityConverter::entityNone = 0 [inherited]

Definition at line 49 of file nsIEntityConverter.idl.

Definition at line 57 of file nsIEntityConverter.idl.

Definition at line 55 of file nsIEntityConverter.idl.

Definition at line 56 of file nsIEntityConverter.idl.

const unsigned long nsIEntityConverter::html40Latin1 = 1 [inherited]

Definition at line 50 of file nsIEntityConverter.idl.

const unsigned long nsIEntityConverter::html40Special = 4 [inherited]

Definition at line 52 of file nsIEntityConverter.idl.

const unsigned long nsIEntityConverter::html40Symbols = 2 [inherited]

Definition at line 51 of file nsIEntityConverter.idl.

const unsigned long nsIEntityConverter::mathml20 = 16 [inherited]

Definition at line 54 of file nsIEntityConverter.idl.

Definition at line 95 of file nsEntityConverter.h.

Definition at line 96 of file nsEntityConverter.h.

const unsigned long nsIEntityConverter::transliterate = 8 [inherited]

Definition at line 53 of file nsIEntityConverter.idl.


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