Click here to Skip to main content
15,892,927 members
Articles / Programming Languages / C++

A Spell Checking Engine

Rate me:
Please Sign up or sign in to vote.
4.88/5 (16 votes)
5 Feb 2001 267.4K   7K   108  
A free spell checking engine for use in your C++ applications. Includes the current US English dictionary
/*

  Copyright:		2000
  Author:			Matthew T Gullett
  Email:			gullettm@yahoo.com
  Name:				CFPSDictionary
  Part of:			Spell Checking Engine 
  Requires:			

  DESCRIPTION
  ----------------------------------------------------------
  This class is designed to implement dictionary support for
  the spell checking engine.


  INFO:
  ----------------------------------------------------------
  This class is provided -as is-.  No warranty as to the
  function or performance of this class is provided either 
  written or implied.  
  
  You may freely use this code and modify it as necessary,
  as long as this header is unmodified and credit is given
  to the author in the application(s) in which it is
  incorporated.

*/

#if !defined(AFX_FPSDICTIONARY_H__54D2A5E8_8E69_4533_937F_2AFFD0EF1E41__INCLUDED_)
#define AFX_FPSDICTIONARY_H__54D2A5E8_8E69_4533_937F_2AFFD0EF1E41__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define CFPSDictionary_ERROR_INVLD_HDR				FPSSPELLCHECK_ERROR_CUSTOM+1
#define	CFPSDictionary_ERROR_DIC_OPEN_FAILED		FPSSPELLCHECK_ERROR_CUSTOM+2
#define CFPSDictionary_ERROR_DIC_ALREADY_OPEN		FPSSPELLCHECK_ERROR_CUSTOM+3
#define CFPSDictionary_ERROR_WORD_OPEN_FAILED		FPSSPELLCHECK_ERROR_CUSTOM+4
#define CFPSDictionary_ERROR_WORD_TOOLONG			FPSSPELLCHECK_ERROR_CUSTOM+5
#define CFPSDictionary_ERROR_NOMATCH				FPSSPELLCHECK_ERROR_CUSTOM+6
#define CFPSDictionary_ERROR_NOT_OPEN				FPSSPELLCHECK_ERROR_CUSTOM+7


class CFPSDictionary  
{
public:
	virtual int CreateNew();
	virtual void SetWords(LPCSTR lpszWords);
	virtual CString GetWords();
	CFPSDictionary();
	virtual ~CFPSDictionary();

	virtual int Close();
	virtual int Save(LPCSTR lpszDicFile);
	virtual int Open(LPCSTR lpszDicFile);
	virtual BOOL IsWordInDictionary(LPCSTR lpszWord);
	virtual BOOL FindMatches(LPCSTR lpszWord, CStringList& Matches);
	virtual long GetWordCount() {return (m_lRecordCount+m_ExtraWords.GetCount());}
	virtual int BuildFromWordList(LPCSTR lpszWordFile, LPCSTR lpszDicFile);
	virtual int AddWord(LPCSTR lpszWord);
	virtual int RemoveWord(LPCSTR lpszWord);

protected:
	virtual void CacheWordLocations();
	virtual BOOL IsInOrder();
	virtual void PrepareHeader(FPSDICHEADER& Header);
	virtual BOOL IsValidHeader(FPSDICHEADER& Header);
	virtual BOOL FindWord (LPCSTR lpszWord, int iMin, int iMax);
	virtual void RemoveExtraWords();

	FPSDICWORD*	m_pWords;
	CTypedPtrList<CPtrList, FPSDICWORD*>	m_ExtraWords;
	long		m_lRecordCount;

	FPSDICHEADER m_FileHeader;

	CString m_strFileName;

	int m_iRecords[255];
private:
	char GetUpperChar(char cInput);
};

#endif // !defined(AFX_FPSDICTIONARY_H__54D2A5E8_8E69_4533_937F_2AFFD0EF1E41__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions