Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Private Attributes
nsCaseConversionImp2 Class Reference

#include <nsCaseConversionImp2.h>

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

List of all members.

Public Member Functions

 nsCaseConversionImp2 ()
virtual ~nsCaseConversionImp2 ()
NS_IMETHOD ToUpper (PRUnichar aChar, PRUnichar *aReturn)
NS_IMETHOD ToLower (PRUnichar aChar, PRUnichar *aReturn)
NS_IMETHOD ToTitle (PRUnichar aChar, PRUnichar *aReturn)
NS_IMETHOD ToUpper (const PRUnichar *anArray, PRUnichar *aReturn, PRUint32 aLen)
NS_IMETHOD ToLower (const PRUnichar *anArray, PRUnichar *aReturn, PRUint32 aLen)
NS_IMETHOD ToTitle (const PRUnichar *anArray, PRUnichar *aReturn, PRUint32 aLen, PRBool aStartInWordBoundary=PR_TRUE)
NS_IMETHOD CaseInsensitiveCompare (const PRUnichar *aLeft, const PRUnichar *aRight, PRUint32 aLength, PRInt32 *aResult)

Static Private Attributes

static nsrefcnt gInit = 0

Detailed Description

Definition at line 48 of file nsCaseConversionImp2.h.


Constructor & Destructor Documentation

Definition at line 400 of file nsCaseConversionImp2.cpp.

{
  if (--gInit == 0) {
    delete gUpperMap;
    gUpperMap = nsnull;
    delete gLowerMap;
    gLowerMap = nsnull;
  }
}

Member Function Documentation

NS_IMETHODIMP nsCaseConversionImp2::CaseInsensitiveCompare ( const PRUnichar aLeft,
const PRUnichar aRight,
PRUint32  aLength,
PRInt32 aResult 
) [virtual]

Implements nsICaseConversion.

Definition at line 360 of file nsCaseConversionImp2.cpp.

{
  if (!aLeft || !aRight)
    return NS_ERROR_INVALID_POINTER;

  // assume equality. We bail early if no equality
  *aResult = 0;
  
  if (aCount) {
    do {
      PRUnichar c1 = *aLeft++;
      PRUnichar c2 = *aRight++;
      
      if (c1 != c2) {
        c1 = FastToLower(c1);
        c2 = FastToLower(c2);
        if (c1 != c2) {
          if (c1 < c2) {
            *aResult = -1;
            return NS_OK;
          }
          *aResult = 1;
          return NS_OK;
        }
      }
    } while (--aCount != 0);
  }
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsCaseConversionImp2::ToLower ( PRUnichar  aChar,
PRUnichar aReturn 
) [virtual]

Implements nsICaseConversion.

Definition at line 228 of file nsCaseConversionImp2.cpp.

{
  *aReturn = FastToLower(aChar);
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsCaseConversionImp2::ToLower ( const PRUnichar anArray,
PRUnichar aReturn,
PRUint32  aLen 
) [virtual]

Implements nsICaseConversion.

Definition at line 305 of file nsCaseConversionImp2.cpp.

{
  PRUint32 i;
  for(i=0;i<aLen;i++) 
    aReturn[i] = FastToLower(anArray[i]);
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsCaseConversionImp2::ToTitle ( PRUnichar  aChar,
PRUnichar aReturn 
) [virtual]

Implements nsICaseConversion.

Definition at line 235 of file nsCaseConversionImp2.cpp.

{
  if( IS_ASCII(aChar)) // optimize for ASCII
  {
    return this->ToUpper(aChar, aReturn);
  }
  else if( IS_NOCASE_CHAR(aChar)) // optimize for block which have no case
  {
    *aReturn = aChar;
  } 
  else
  {
    // First check for uppercase characters whose titlecase mapping is
    //  different, like U+01F1 DZ: they must remain unchanged.
    if( 0x01C0 == ( aChar & 0xFFC0)) // 0x01Cx - 0x01Fx
    {
      for(PRUint32 i = 0 ; i < gUpperToTitleItems; i++) {
        if ( aChar == gUpperToTitle[(i*2)+kUpperIdx]) {
          *aReturn = aChar;
          return NS_OK;
        }
      }
    }

    PRUnichar upper;
    upper = gUpperMap->Map(aChar);
    
    if( 0x01C0 == ( upper & 0xFFC0)) // 0x01Cx - 0x01Fx
    {
      for(PRUint32 i = 0 ; i < gUpperToTitleItems; i++) {
        if ( upper == gUpperToTitle[(i*2)+kUpperIdx]) {
           *aReturn = gUpperToTitle[(i*2)+kTitleIdx];
           return NS_OK;
        }
      }
    }
    *aReturn = upper;
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCaseConversionImp2::ToTitle ( const PRUnichar anArray,
PRUnichar aReturn,
PRUint32  aLen,
PRBool  aStartInWordBoundary = PR_TRUE 
) [virtual]

Implements nsICaseConversion.

Definition at line 317 of file nsCaseConversionImp2.cpp.

{
  if(0 == aLen)
    return NS_OK;

  //
  // We need to replace this implementation to a real one
  // Currently, it only do the right thing for ASCII
  // Howerver, we need a word breaker to do the right job
  //
  // this->ToLower(anArray, aReturn, aLen); 
  // CSS define Capitalize as 
  //  Uppercases the first character of each word
  // 
  
  PRBool bLastIsSpace =  IS_ASCII_SPACE(anArray[0]);
  if(aStartInWordBoundary)
  {
     this->ToTitle(anArray[0], &aReturn[0]);
  }

  PRUint32 i;
  for(i=1;i<aLen;i++)
  {
    if(bLastIsSpace)
    {
      this->ToTitle(anArray[i], &aReturn[i]);
    }
    else
    {
      aReturn[i] = anArray[i];
    }

    bLastIsSpace = IS_ASCII_SPACE(aReturn[i]);
  }
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsCaseConversionImp2::ToUpper ( PRUnichar  aChar,
PRUnichar aReturn 
) [virtual]

Implements nsICaseConversion.

Definition at line 183 of file nsCaseConversionImp2.cpp.

{
  if( IS_ASCII(aChar)) // optimize for ASCII
  {
     if(IS_ASCII_LOWER(aChar))
        *aReturn = aChar - 0x0020;
     else
        *aReturn = aChar;
  } 
  else if( IS_NOCASE_CHAR(aChar)) // optimize for block which have no case
  {
    *aReturn = aChar;
  } 
  else 
  {
    *aReturn = gUpperMap->Map(aChar);
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCaseConversionImp2::ToUpper ( const PRUnichar anArray,
PRUnichar aReturn,
PRUint32  aLen 
) [virtual]

Implements nsICaseConversion.

Definition at line 278 of file nsCaseConversionImp2.cpp.

{
  PRUint32 i;
  for(i=0;i<aLen;i++) 
  {
    PRUnichar aChar = anArray[i];
    if( IS_ASCII(aChar)) // optimize for ASCII
    {
       if(IS_ASCII_LOWER(aChar))
          aReturn[i] = aChar - 0x0020;
       else
          aReturn[i] = aChar;
    }
    else if( IS_NOCASE_CHAR(aChar)) // optimize for block which have no case
    {
          aReturn[i] = aChar;
    } 
    else 
    {
      aReturn[i] = gUpperMap->Map(aChar);
    }
  }
  return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

nsrefcnt nsCaseConversionImp2::gInit = 0 [static, private]

Definition at line 71 of file nsCaseConversionImp2.h.


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