Back to index

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

implementation of a text services object. More...

#include <nsSpellCheckUtils.h>

List of all members.

Static Public Member Functions

static nsresult ReadStringIntoBuffer (nsIUnicodeEncoder *aUnicodeEncoder, const PRUnichar *aStr, CharBuffer *aBuf)
static nsresult ReadStringIntoBuffer (nsIUnicodeEncoder *aUnicodeEncoder, const nsString *aStr, CharBuffer *aBuf)
static nsresult CreateUnicodeConverters (const PRUnichar *aCharset, nsIUnicodeEncoder **aUnicodeEncoder, nsIUnicodeDecoder **aUnicodeDecoder)
static nsresult LoadTextBlockIntoBuffer (nsITextServicesDocument *aTxtSvcDoc, nsISpellChecker *aSpellChecker, CharBuffer &aCharBuf, nsString &aText, PRUint32 &aOffset)
static nsresult GetWordBreaker (nsIWordBreaker **aResult)

Private Member Functions

 nsSpellCheckUtils ()
 The default constructor.
virtual ~nsSpellCheckUtils ()
 The default destructor.

Detailed Description

implementation of a text services object.

Definition at line 92 of file nsSpellCheckUtils.h.


Constructor & Destructor Documentation

nsSpellCheckUtils::nsSpellCheckUtils ( ) [inline, private]

The default constructor.

Definition at line 130 of file nsSpellCheckUtils.h.

{}
virtual nsSpellCheckUtils::~nsSpellCheckUtils ( ) [inline, private, virtual]

The default destructor.

Definition at line 134 of file nsSpellCheckUtils.h.

{}

Member Function Documentation

nsresult nsSpellCheckUtils::CreateUnicodeConverters ( const PRUnichar aCharset,
nsIUnicodeEncoder **  aUnicodeEncoder,
nsIUnicodeDecoder **  aUnicodeDecoder 
) [static]

Definition at line 128 of file nsSpellCheckUtils.cpp.

{
  NS_ENSURE_ARG_POINTER(aCharset);
  NS_ENSURE_ARG_POINTER(aUnicodeEncoder);
  NS_ENSURE_ARG_POINTER(aUnicodeDecoder);

  nsresult rv;

  nsCOMPtr <nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  NS_LossyConvertUCS2toASCII charset(aCharset);

  rv = ccm->GetUnicodeDecoder(charset.get(), aUnicodeDecoder);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = ccm->GetUnicodeEncoder(charset.get(), aUnicodeEncoder);
  NS_ENSURE_SUCCESS(rv, rv);

  // Set the error behavior, in case a character cannot be mapped.
  rv = (*aUnicodeEncoder)->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, ' ');

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 202 of file nsSpellCheckUtils.cpp.

{
  NS_ENSURE_ARG_POINTER(aResult);

  // no line breaker, find a default one
  nsresult result;
  nsCOMPtr<nsIWordBreakerFactory> wbf(do_GetService(NS_LWBRK_CONTRACTID, &result));
  if (NS_SUCCEEDED(result)) 
  {
    nsAutoString wbarg;
    result = wbf->GetBreaker(wbarg, aResult);
    NS_IF_ADDREF(*aResult);
  }
  return result;
}

Here is the call graph for this function:

nsresult nsSpellCheckUtils::LoadTextBlockIntoBuffer ( nsITextServicesDocument aTxtSvcDoc,
nsISpellChecker aSpellChecker,
CharBuffer aCharBuf,
nsString aText,
PRUint32 aOffset 
) [static]

Definition at line 156 of file nsSpellCheckUtils.cpp.

{
  NS_ENSURE_ARG_POINTER(aTxtSvcDoc);
  NS_ENSURE_ARG_POINTER(aSpellChecker);

  nsCOMPtr<nsIUnicodeEncoder> unicodeEncoder;
  nsXPIDLString charSet;
  nsresult result = aSpellChecker->GetCharset(getter_Copies(charSet));
  if (NS_SUCCEEDED(result)) 
  {
    nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
    result = nsSpellCheckUtils::CreateUnicodeConverters(charSet, 
                                                        getter_AddRefs(unicodeEncoder), 
                                                        getter_AddRefs(unicodeDecoder));
    NS_ENSURE_TRUE(unicodeEncoder, NS_ERROR_NULL_POINTER);
  }

  if (aCharBuf.mData)
    aCharBuf.mData[0]  = '\0';

  nsString str;
  aCharBuf.mDataLength = 0;

  result = aTxtSvcDoc->GetCurrentTextBlock(&str);
  NS_ENSURE_SUCCESS(result, result);

  result = nsSpellCheckUtils::ReadStringIntoBuffer(unicodeEncoder, &str, &aCharBuf);
  NS_ENSURE_SUCCESS(result, result);

  if (aCharBuf.mDataLength < 1)
  {
    // The document could be empty, so return
    // NS_OK!
    return NS_OK;
  }

  aText.AssignWithConversion(aCharBuf.mData);

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsSpellCheckUtils::ReadStringIntoBuffer ( nsIUnicodeEncoder aUnicodeEncoder,
const PRUnichar aStr,
CharBuffer aBuf 
) [static]

Definition at line 70 of file nsSpellCheckUtils.cpp.

{
  NS_ENSURE_ARG_POINTER(aUnicodeEncoder);
  NS_ENSURE_ARG_POINTER(aBuf);

  if (!aStr || !*aStr) {
    return NS_OK;
  }

  aBuf->mDataLength = 0;

  PRInt32 unicodeLength = nsCRT::strlen(aStr);

  // Estimate a string length after the conversion.
  PRInt32 estimatedLength, stringLength;
  nsresult result = aUnicodeEncoder->GetMaxLength(aStr, unicodeLength, &estimatedLength);
  NS_ENSURE_SUCCESS(result, result);

  result = aBuf->AssureCapacity(estimatedLength + 1);
  NS_ENSURE_SUCCESS(result, result);

  // Convert from unicode.
  stringLength = estimatedLength;
  result = aUnicodeEncoder->Convert(aStr, &unicodeLength, aBuf->mData, &stringLength);
  NS_ENSURE_SUCCESS(result, result);

  // Terminate the conversion (e.g. put escape sequence for JIS).
  PRInt32 finLen = estimatedLength - stringLength;
  if (finLen)
  {
    NS_ENSURE_TRUE(finLen > 0, NS_ERROR_FAILURE);
    result = aUnicodeEncoder->Finish(&aBuf->mData[stringLength], &finLen);
    NS_ENSURE_SUCCESS(result, result);
  }

  aBuf->mDataLength = stringLength + finLen;
  aBuf->mData[aBuf->mDataLength] = '\0';
  for (unsigned char* p = (unsigned char*) aBuf->mData; *p ; p++)
    if( IS_NBSP_CHAR(*p) )  
      *p = ' '; 

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSpellCheckUtils::ReadStringIntoBuffer ( nsIUnicodeEncoder aUnicodeEncoder,
const nsString aStr,
CharBuffer aBuf 
) [static]

Definition at line 117 of file nsSpellCheckUtils.cpp.

{
  NS_ENSURE_ARG_POINTER(aUnicodeEncoder);
  NS_ENSURE_ARG_POINTER(aStr);
  NS_ENSURE_ARG_POINTER(aBuf);
  return ReadStringIntoBuffer(aUnicodeEncoder, aStr->get(), aBuf);
}

Here is the call graph for this function:


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