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

Last change on this file since 3365 was 3365, checked in by kjdon, 22 years ago

Initial revision

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 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
39const unsigned char *ParseIndexWord (const unsigned char *textHere,
40 const unsigned char *textEnd,
41 UCArray &word) {
42 word.erase (word.begin(), word.end());
43
44 register int charlength = 0;
45 register int length = 0;
46 register int numeric = 0;
47 unsigned short c;
48
49 charlength = parse_utf8_char (textHere, textEnd, &c);
50
51 while (length+charlength <= MAXSTEMLEN && charlength > 0 &&
52 (is_unicode_letter(c) || (is_unicode_digit(c) &&
53 ++numeric <= MAXNUMERIC))) {
54 while (charlength-- > 0) {
55 word.push_back (*textHere++); length++;
56 }
57 charlength = parse_utf8_char (textHere, textEnd, &c);
58 }
59
60 return textHere;
61}
62
63const unsigned char *ParseIndexMGWord (const unsigned char *textHere,
64 const unsigned char *textEnd,
65 unsigned char *mgWord) {
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 mgWord[++length] = *textHere++;
78 }
79 charlength = parse_utf8_char (textHere, textEnd, &c);
80 }
81
82 mgWord[0] = length;
83
84 return textHere;
85}
86
87const unsigned char *ParseNonindexWord (const unsigned char *textHere,
88 const unsigned char *textEnd) {
89 register int charlength = 0;
90 unsigned short c;
91
92 charlength = parse_utf8_char(textHere, textEnd, &c);
93
94 while (charlength > 0 && !is_unicode_letdig(c)) {
95 textHere += charlength;
96 charlength = parse_utf8_char (textHere, textEnd, &c);
97 }
98
99 return textHere;
100}
Note: See TracBrowser for help on using the repository browser.