2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* copyright (c) 1994,1995,1996 FUJITSU LIMITED */
24 /* All Rights Reserved */
27 * $XConsortium: QueryTerm.cc /main/6 1996/07/05 16:16:19 rws $
29 * Copyright (c) 1992 HAL Computer Systems International, Ltd.
30 * All rights reserved. Unpublished -- rights reserved under
31 * the Copyright Laws of the United States. USE OF A COPYRIGHT
32 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
35 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
36 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
37 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
38 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
41 * RESTRICTED RIGHTS LEGEND
42 * Use, duplication, or disclosure by the Government is subject
43 * to the restrictions as set forth in subparagraph (c)(l)(ii)
44 * of the Rights in Technical Data and Computer Software clause
45 * at DFARS 252.227-7013.
47 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
71 #if defined(UseWideChars)
73 # define wslen(a) wcslen(a)
76 # define mbstowcs(a,b,c) Xmbstowcs(a,b,c)
77 # define wcstombs(a,b,c) Xwcstombs(a,b,c)
78 # elif defined(_IBMR2)
84 #if defined(USL) || defined(linux) || defined(CSRG_BASED)
88 #define TML_CHAR_TYPE wchar_t
92 unsigned int QueryTerm::f_caps = 0;
94 // /////////////////////////////////////////////////////////////////
96 // /////////////////////////////////////////////////////////////////
98 QueryTerm::QueryTerm (QueryGroup *parent, QueryTerm *previous, QueryTerm *next)
99 : f_parent (parent), f_previous (previous), f_next (next),
100 f_prefix (PFX_CONTAIN), f_connective (C_NONE),
101 f_weight (strdup("")), f_proximity (strdup("")),
102 f_term_string_fixed (TRUE),
105 f_term_string = strdup("");
106 // Link it into the list.
107 if (previous != NULL)
108 f_previous->f_next = this;
110 parent->f_term_list = this;
112 f_next->f_previous = this;
116 // /////////////////////////////////////////////////////////////////
118 // /////////////////////////////////////////////////////////////////
120 QueryTerm::~QueryTerm()
122 if (f_previous != NULL)
123 f_previous->f_next = f_next;
125 f_parent->f_term_list = f_next;
127 f_next->f_previous = f_previous;
130 if (f_type == TYPE_GROUP)
133 free (f_term_string);
137 // /////////////////////////////////////////////////////////////////
138 // cleanup_term_string - parse out leading and trailing spaces
139 // /////////////////////////////////////////////////////////////////
142 QueryTerm::cleanup_term_string()
145 // NOTE: full-text search is a major feature of QSearch, so do not
146 // cut off surrounding spaces - 9/22/94 kamiya
148 char* p = f_term_string;
152 for (char* last = p + strlen(p); p < last; p += n_bytes) {
153 n_bytes = mblen(p, MB_CUR_MAX);
154 assert( n_bytes > 0 );
155 if (n_bytes == 1 && isspace(*p))
162 // NOTE: this used to be done in place, but is now done in separate buffer
163 // for wide char support
164 TML_CHAR_TYPE *first, *last;
165 TML_CHAR_TYPE *wcbuf;
167 length = strlen(f_term_string);
169 wcbuf = new TML_CHAR_TYPE[length + 1];
172 wclen = mbstowcs(wcbuf, f_term_string, length + 1);
173 assert( *(wcbuf + wclen) == (TML_CHAR_TYPE)'\0' );
175 strcpy((char *) wcbuf, f_term_string);
181 // Strip leading white space
182 while (iswspace (*first))
185 // Skip to the end of the string if not already there.
186 last = wcbuf + wclen - 1;
187 while ((last > first ) && iswspace (*last)) // strip trailing spaces
190 // Truncate whitespace if there was any.
191 if (last < wcbuf + wclen -1)
193 last++; // advance to first trailing space
194 *last = (TML_CHAR_TYPE)'\0'; // truncate it
197 // Copy back over space, if any.
198 if ((first != wcbuf) || (last != wcbuf + wclen))
201 wcstombs(f_term_string, first, length + 1);
203 strcpy(f_term_string, (const char *) first);
207 f_term_string_fixed = TRUE;