source: trunk/mgpp/text/words.cpp@ 8692

Last change on this file since 8692 was 8692, checked in by kjdon, 19 years ago

Added the changes from Emanuel Dejanu (Simple Words) - mostly efficiency changes. For example, changing i++ to ++i, delete xxx to delete []xxx, some stuff to do with UCArrays...

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/**************************************************************************
2 *
3 * words.cpp -- Functions for parsing out words from the source text
4 * Copyright (C) 1999 Rodger McNab
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 **************************************************************************/
21
22// need this to avoid bizarre compiler problems under VC++ 6.0
23#if defined (__WIN32__) && !defined (GSDL_USE_IOS_H)
24# include <iostream>
25#endif
26
27#include "words.h"
28
29
30/* Takes the place of the old INAWORD macro. It determines
31 whether a given place in a UTF-8 encoded Unicode string
32 is part of a word. */
33int inaword (const u_char *here, const u_char *end) {
34 unsigned short c;
35 if (parse_utf8_char(here, end, &c) > 0) return is_unicode_letdig (c);
36 return 0;
37}
38
39/* It determines whether a given place in a UTF-8 encoded Unicode string is a unicode space. */
40int isaspace (const u_char *here, const u_char *end)
41{
42 unsigned short c;
43 if (parse_utf8_char(here, end, &c) > 0) return is_unicode_space(c);
44 return 0;
45}
46
47/* Return a the UTF-8 encoded Unicode string with begining
48 unicode spaces skippend. */
49u_char *skipspace(u_char *here, u_char *end)
50{
51 unsigned short c;
52 int length;
53 while(here != end) {
54 length = parse_utf8_char(here, end, &c);
55 if (length == 0 || !is_unicode_space(c)) break;
56 here += length;
57 }
58 return here;
59}
60
61const unsigned char *ParseIndexWord (const unsigned char *textHere,
62 const unsigned char *textEnd,
63 UCArray &word) {
64 word.erase (word.begin(), word.end());
65
66 register int charlength = 0;
67 register int length = 0;
68 register int numeric = 0;
69 unsigned short c;
70
71 charlength = parse_utf8_char (textHere, textEnd, &c);
72
73 while (length+charlength <= MAXSTEMLEN && charlength > 0 &&
74 (is_unicode_letter(c) || (is_unicode_digit(c) &&
75 ++numeric <= MAXNUMERIC))) {
76 while (charlength-- > 0) {
77 word.push_back (*textHere++); ++length;
78 }
79 charlength = parse_utf8_char (textHere, textEnd, &c);
80 }
81
82 return textHere;
83}
84
85const unsigned char *ParseIndexMGWord (const unsigned char *textHere,
86 const unsigned char *textEnd,
87 unsigned char *mgWord) {
88 register int charlength = 0;
89 register int length = 0;
90 register int numeric = 0;
91 unsigned short c;
92
93 charlength = parse_utf8_char (textHere, textEnd, &c);
94
95 while (length+charlength <= MAXSTEMLEN && charlength > 0 &&
96 (is_unicode_letter(c) || (is_unicode_digit(c) &&
97 ++numeric <= MAXNUMERIC))) {
98 while (charlength-- > 0) {
99 mgWord[++length] = *textHere++;
100 }
101 charlength = parse_utf8_char (textHere, textEnd, &c);
102 }
103
104 mgWord[0] = length;
105
106 return textHere;
107}
108
109const unsigned char *ParseNonindexWord (const unsigned char *textHere,
110 const unsigned char *textEnd) {
111 register int charlength = 0;
112 unsigned short c;
113
114 charlength = parse_utf8_char(textHere, textEnd, &c);
115
116 while (charlength > 0 && !is_unicode_letdig(c)) {
117 textHere += charlength;
118 charlength = parse_utf8_char (textHere, textEnd, &c);
119 }
120
121 return textHere;
122}
Note: See TracBrowser for help on using the repository browser.