Back to index

lightning-sunbird  0.9+nobinonly
nsSpellCheckUtils.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Mozilla browser.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications, Inc.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsSpellCheckUtils_h__
00040 #define nsSpellCheckUtils_h__
00041 
00042 #include "nsString.h"
00043 #include "nsCRT.h"
00044 #include "nsICharsetConverterManager.h"
00045 
00046 class nsISpellChecker;
00047 class nsITextServicesDocument;
00048 class nsIWordBreaker;
00049 
00050 class CharBuffer
00051 {
00052 public:
00053 
00054   PRInt32 mCapacity;
00055   char *mData;
00056   PRInt32 mDataLength;
00057 
00058   CharBuffer() : mCapacity(0), mData(0), mDataLength(0) {}
00059 
00060   ~CharBuffer()
00061   {
00062     if (mData)
00063       delete []mData;
00064 
00065     mData       = 0;
00066     mCapacity   = 0;
00067     mDataLength = 0;
00068   }
00069 
00070   nsresult AssureCapacity(PRInt32 aLength)
00071   {
00072     if (aLength >  mCapacity)
00073     {
00074       if (mData)
00075         delete []mData;
00076 
00077       mData = new char[aLength];
00078 
00079       if (!mData)
00080         return NS_ERROR_OUT_OF_MEMORY;
00081 
00082       mCapacity = aLength;
00083     }
00084 
00085     return NS_OK;
00086   }
00087 };
00088 
00092 class nsSpellCheckUtils 
00093 {
00094 public:
00095   static nsresult ReadStringIntoBuffer(nsIUnicodeEncoder* aUnicodeEncoder,
00096                                        const PRUnichar*   aStr, 
00097                                        CharBuffer*        aBuf);
00098 
00099   static nsresult ReadStringIntoBuffer(nsIUnicodeEncoder* aUnicodeEncoder,
00100                                        const nsString*    aStr, 
00101                                        CharBuffer*        aBuf);
00102 
00103 
00104   static nsresult CreateUnicodeConverters(const PRUnichar*    aCharset,
00105                                           nsIUnicodeEncoder** aUnicodeEncoder,
00106                                           nsIUnicodeDecoder** aUnicodeDecoder);
00107 
00108   static nsresult LoadTextBlockIntoBuffer(nsITextServicesDocument* aTxtSvcDoc,
00109                                           nsISpellChecker* aSpellChecker,
00110                                           CharBuffer&          aCharBuf,
00111                                           nsString&            aText, 
00112                                           PRUint32&            aOffset);
00113 
00114   // helper
00115   static nsresult GetWordBreaker(nsIWordBreaker** aResult);
00116 
00117 #ifdef NS_DEBUG
00118   static nsresult DumpWords(nsIWordBreaker*  aWordBreaker, 
00119                             const PRUnichar* aText, 
00120                             const PRUint32&  aTextLen);
00121 #define DUMPWORDS(_wb, _txt, _txtLen) nsSpellCheckUtils::DumpWords(_wb, _txt, _txtLen);
00122 #else
00123 #define DUMPWORDS(_wb, _txt, _txtLen)
00124 #endif
00125 
00126 private:
00127 
00130   nsSpellCheckUtils() {}
00131 
00134   virtual ~nsSpellCheckUtils() {}
00135 
00136 };
00137 
00138 #endif // nsSpellCheckUtils_h__