Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
nsHTMLEntities Class Reference

#include <nsHTMLEntities.h>

List of all members.

Static Public Member Functions

static nsresult AddRefTable (void)
static void ReleaseTable (void)
static PRInt32 EntityToUnicode (const nsAString &aEntity)
 Translate an entity string into it's unicode value.
static PRInt32 EntityToUnicode (const nsCString &aEntity)
static const char * UnicodeToEntity (PRInt32 aUnicode)
 Translate a unicode value into an entity string.

Detailed Description

Definition at line 42 of file nsHTMLEntities.h.


Member Function Documentation

Definition at line 134 of file nsHTMLEntities.cpp.

{
  if (!gTableRefCnt) {
    if (!PL_DHashTableInit(&gEntityToUnicode, &EntityToUnicodeOps,
                           nsnull, sizeof(EntityNodeEntry),
                           PRUint32(NS_HTML_ENTITY_COUNT / 0.75))) {
      gEntityToUnicode.ops = nsnull;
      return NS_ERROR_OUT_OF_MEMORY;
    }
    if (!PL_DHashTableInit(&gUnicodeToEntity, &UnicodeToEntityOps,
                           nsnull, sizeof(EntityNodeEntry),
                           PRUint32(NS_HTML_ENTITY_COUNT / 0.75))) {
      PL_DHashTableFinish(&gEntityToUnicode);
      gEntityToUnicode.ops = gUnicodeToEntity.ops = nsnull;
      return NS_ERROR_OUT_OF_MEMORY;
    }
    for (const EntityNode *node = gEntityArray,
                 *node_end = gEntityArray + NS_ARRAY_LENGTH(gEntityArray);
         node < node_end; ++node) {

      // add to Entity->Unicode table
      EntityNodeEntry* entry =
        NS_STATIC_CAST(EntityNodeEntry*,
                       PL_DHashTableOperate(&gEntityToUnicode,
                                            node->mStr,
                                            PL_DHASH_ADD));
      NS_ASSERTION(entry, "Error adding an entry");
      // Prefer earlier entries when we have duplication.
      if (!entry->node)
        entry->node = node;

      // add to Unicode->Entity table
      entry = NS_STATIC_CAST(EntityNodeEntry*,
                             PL_DHashTableOperate(&gUnicodeToEntity,
                                                  NS_INT32_TO_PTR(node->mUnicode),
                                                  PL_DHASH_ADD));
      NS_ASSERTION(entry, "Error adding an entry");
      // Prefer earlier entries when we have duplication.
      if (!entry->node)
        entry->node = node;
    }
  }
  ++gTableRefCnt;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsHTMLEntities::EntityToUnicode ( const nsAString &  aEntity) [static]

Translate an entity string into it's unicode value.

This call returns -1 if the entity cannot be mapped. Note that the string passed in must NOT have the leading "&" nor the trailing ";" in it.

Definition at line 225 of file nsHTMLEntities.cpp.

                                                        {
  nsCAutoString theEntity; theEntity.AssignWithConversion(aEntity);
  if(';'==theEntity.Last()) {
    theEntity.Truncate(theEntity.Length()-1);
  }

  return EntityToUnicode(theEntity);
}

Here is the caller graph for this function:

Definition at line 198 of file nsHTMLEntities.cpp.

{
  NS_ASSERTION(gEntityToUnicode.ops, "no lookup table, needs addref");
  if (!gEntityToUnicode.ops)
    return -1;

    //this little piece of code exists because entities may or may not have the terminating ';'.
    //if we see it, strip if off for this test...

    if(';'==aEntity.Last()) {
      nsCAutoString temp(aEntity);
      temp.Truncate(aEntity.Length()-1);
      return EntityToUnicode(temp);
    }
      
  EntityNodeEntry* entry = 
    NS_STATIC_CAST(EntityNodeEntry*,
                   PL_DHashTableOperate(&gEntityToUnicode, aEntity.get(), PL_DHASH_LOOKUP));

  if (!entry || PL_DHASH_ENTRY_IS_FREE(entry))
  return -1;
        
  return entry->node->mUnicode;
}

Here is the call graph for this function:

Definition at line 181 of file nsHTMLEntities.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const char * nsHTMLEntities::UnicodeToEntity ( PRInt32  aUnicode) [static]

Translate a unicode value into an entity string.

This call returns null if the entity cannot be mapped. Note that the string returned DOES NOT have the leading "&" nor the trailing ";" in it.

Definition at line 236 of file nsHTMLEntities.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


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