• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdespell2
 

tdespell2

  • tdespell2
  • plugins
  • ispell
hash.cpp
1/* enchant
2 * Copyright (C) 2003 Dom Lachowicz
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 * In addition, as a special exception, Dom Lachowicz
20 * gives permission to link the code of this program with
21 * non-LGPL Spelling Provider libraries (eg: a MSFT Office
22 * spell checker backend) and distribute linked combinations including
23 * the two. You must obey the GNU Lesser General Public License in all
24 * respects for all of the code used other than said providers. If you modify
25 * this file, you may extend this exception to your version of the
26 * file, but you are not obligated to do so. If you do not wish to
27 * do so, delete this exception statement from your version.
28 */
29
30/*
31 * hash.c - a simple hash function for ispell
32 *
33 * Pace Willisson, 1983
34 *
35 * Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All modifications to the source code must be clearly marked as
48 * such. Binary redistributions based on modified source code
49 * must be clearly marked as modified versions in the documentation
50 * and/or other materials provided with the distribution.
51 * 4. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgment:
53 * This product includes software developed by Geoff Kuenning and
54 * other unpaid contributors.
55 * 5. The name of Geoff Kuenning may not be used to endorse or promote
56 * products derived from this software without specific prior
57 * written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 */
71
72/*
73 * $Log$
74 * Revision 1.1 2004/01/31 16:44:12 zrusin
75 * ISpell plugin.
76 *
77 * Revision 1.4 2003/08/14 17:51:27 dom
78 * update license - exception clause should be Lesser GPL
79 *
80 * Revision 1.3 2003/07/28 20:40:26 dom
81 * fix up the license clause, further win32-registry proof some directory getting functions
82 *
83 * Revision 1.2 2003/07/16 22:52:39 dom
84 * LGPL + exception license
85 *
86 * Revision 1.1 2003/07/15 01:15:05 dom
87 * ispell enchant backend
88 *
89 * Revision 1.2 2003/01/29 05:50:11 hippietrail
90 *
91 * Fixed my mess in EncodingManager.
92 * Changed many C casts to C++ casts.
93 *
94 * Revision 1.1 2003/01/24 05:52:33 hippietrail
95 *
96 * Refactored ispell code. Old ispell global variables had been put into
97 * an allocated structure, a pointer to which was passed to many functions.
98 * I have now made all such functions and variables private members of the
99 * ISpellChecker class. It was C OO, now it's C++ OO.
100 *
101 * I've fixed the makefiles and tested compilation but am unable to test
102 * operation. Please back out my changes if they cause problems which
103 * are not obvious or easy to fix.
104 *
105 * Revision 1.5 2002/09/19 05:31:15 hippietrail
106 *
107 * More Ispell cleanup. Conditional globals and DEREF macros are removed.
108 * K&R function declarations removed, converted to Doxygen style comments
109 * where possible. No code has been changed (I hope). Compiles for me but
110 * unable to test.
111 *
112 * Revision 1.4 2002/09/17 03:03:29 hippietrail
113 *
114 * After seeking permission on the developer list I've reformatted all the
115 * spelling source which seemed to have parts which used 2, 3, 4, and 8
116 * spaces for tabs. It should all look good with our standard 4-space
117 * tabs now.
118 * I've concentrated just on indentation in the actual code. More prettying
119 * could be done.
120 * * NO code changes were made *
121 *
122 * Revision 1.3 2002/09/13 17:20:13 mpritchett
123 * Fix more warnings for Linux build
124 *
125 * Revision 1.2 2001/05/12 16:05:42 thomasf
126 * Big pseudo changes to ispell to make it pass around a structure rather
127 * than rely on all sorts of gloabals willy nilly here and there. Also
128 * fixed our spelling class to work with accepting suggestions once more.
129 * This code is dirty, gross and ugly (not to mention still not supporting
130 * multiple hash sized just yet) but it works on my machine and will no
131 * doubt break other machines.
132 *
133 * Revision 1.1 2001/04/15 16:01:24 tomas_f
134 * moving to spell/xp
135 *
136 * Revision 1.3 1998/12/29 14:55:33 eric
137 *
138 * I've doctored the ispell code pretty extensively here. It is now
139 * warning-free on Win32. It also *works* on Win32 now, since I
140 * replaced all the I/O calls with ANSI standard ones.
141 *
142 * Revision 1.2 1998/12/28 23:11:30 eric
143 *
144 * modified spell code and integration to build on Windows.
145 * This is still a hack.
146 *
147 * Actually, it doesn't yet WORK on Windows. It just builds.
148 * SpellCheckInit is failing for some reason.
149 *
150 * Revision 1.1 1998/12/28 18:04:43 davet
151 * Spell checker code stripped from ispell. At this point, there are
152 * two external routines... the Init routine, and a check-a-word routine
153 * which returns a boolean value, and takes a 16 bit char string.
154 * The code resembles the ispell code as much as possible still.
155 *
156 * Revision 1.20 1994/01/25 07:11:34 geoff
157 * Get rid of all old RCS log lines in preparation for the 3.1 release.
158 *
159 */
160
161#include "ispell_checker.h"
162
163/*
164 * The following hash algorithm is due to Ian Dall, with slight modifications
165 * by Geoff Kuenning to reflect the results of testing with the English
166 * dictionaries actually distributed with ispell.
167 */
168#define HASHSHIFT 5
169
170#ifdef NO_CAPITALIZATION_SUPPORT
171#define HASHUPPER(c) c
172#else /* NO_CAPITALIZATION_SUPPORT */
173#define HASHUPPER(c) mytoupper(c)
174#endif /* NO_CAPITALIZATION_SUPPORT */
175
176/*
177 * \param s
178 * \param hashtblsize
179 */
180int ISpellChecker::hash (ichar_t *s, int hashtblsize)
181{
182 long h = 0;
183 int i;
184
185#ifdef ICHAR_IS_CHAR
186 for (i = 4; i-- && *s != 0; )
187 h = (h << 8) | HASHUPPER (*s++);
188#else /* ICHAR_IS_CHAR */
189 for (i = 2; i-- && *s != 0; )
190 h = (h << 16) | HASHUPPER (*s++);
191#endif /* ICHAR_IS_CHAR */
192 while (*s != 0)
193 {
194 /*
195 * We have to do circular shifts the hard way, since C doesn't
196 * have them even though the hardware probably does. Oh, well.
197 */
198 h = (h << HASHSHIFT)
199 | ((h >> (32 - HASHSHIFT)) & ((1 << HASHSHIFT) - 1));
200 h ^= HASHUPPER (*s++);
201 }
202 return static_cast<unsigned long>(h) % hashtblsize;
203}

tdespell2

Skip menu "tdespell2"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tdespell2

Skip menu "tdespell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdespell2 by doxygen 1.9.4
This website is maintained by Timothy Pearson.