source: main/tags/2.80/indexers/mgpp/text/UCArray.h@ 24540

Last change on this file since 24540 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: 4.0 KB
Line 
1/**************************************************************************
2 *
3 * UCArray.h -- vector based string class
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#ifndef UCARRAY_H
23#define UCARRAY_H
24
25#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
26#pragma warning(disable:4786)
27#endif
28
29// need this to avoid bizarre compiler problems under VC++ 6.0
30#if !defined (GSDL_NAMESPACE_BROKEN) && !defined (GSDL_USE_IOS_H)
31# include <iostream>
32using namespace std;
33#endif
34
35#if defined(GSDL_USE_OBJECTSPACE)
36# include <ospace\std\vector>
37# include <ospace\std\set>
38#elif defined(GSDL_USE_STL_H)
39# include <vector.h>
40# include <set.h>
41#else
42# include <vector>
43# include <set>
44#endif
45
46#if defined(GSDL_USE_OBJECTSPACE)
47# include <ospace\std\iostream>
48#elif defined(GSDL_USE_IOS_H)
49# include <iostream.h>
50#else
51# include <iostream>
52#endif
53
54#include <stdio.h>
55
56
57typedef vector<unsigned char> UCArray;
58
59// functions to manipulate UCArrays
60void SetCStr (UCArray &text, const char *cStr);
61// same as SetCStr but first tries to allocate nSizeHint space (only if needed)
62void SetCStr (UCArray &text, const char *cStr, size_t nSizeHint);
63char * GetCStr(const UCArray& text);
64inline void UCArrayClear (UCArray &a) {
65 a.erase (a.begin(), a.end());
66}
67bool UCArrayCStrEquals(const UCArray &text, const unsigned char *cStr);
68inline bool UCArrayCStrEquals(const UCArray &text, const char *cStr) { return UCArrayCStrEquals(text, (const unsigned char *)cStr); }
69
70// stream operator to print UCArray
71ostream &operator<<(ostream &s, const UCArray &a);
72
73// used for reading and writing unsigned characters
74inline bool ReadUC (FILE *f, unsigned char &c) {
75 return (fread (&c, sizeof (unsigned char), 1, f) == 1);
76}
77inline bool WriteUC (FILE *f, unsigned char c) {
78 return (fwrite (&c, sizeof (unsigned char), 1, f) == 1);
79}
80
81// used for reading and writing variable length unsigned longs
82bool ReadVarLenUL (FILE *f, unsigned long &n);
83bool WriteVarLenUL (FILE *f, unsigned long n);
84
85// used for reading and writing unsigned longs
86bool ReadUL (FILE *f, unsigned long &n);
87bool WriteUL (FILE *f, unsigned long n);
88
89// used for reading and writing floats
90bool ReadF (FILE *f, float &n);
91bool WriteF (FILE *f, float n);
92
93// used for reading and writing doubles
94bool ReadD (FILE *f, double &n);
95bool WriteD (FILE *f, double n);
96
97// used for reading and writing arrays to files
98bool ReadUCArray (FILE *f, UCArray &a);
99bool WriteUCArray (FILE *f, const UCArray &a);
100
101
102// compares the two strings in dictionary order
103int DictCompare (const UCArray &a1, const UCArray &a2);
104
105// does the first string start with the second?
106bool StartsWith(const UCArray &a1, const UCArray &a2);
107// does the first string start with the second, ignoring case?
108bool StartsWithCasefold(const UCArray &a1, const UCArray &a2);
109
110struct LTUCArray {
111 bool operator()(const UCArray &a1, const UCArray &a2) const
112 { return (a1 < a2); }
113};
114
115struct DictLTUCArray {
116 bool operator() (const UCArray &a1, const UCArray &a2) const
117 { return (DictCompare (a1, a2) < 0); }
118};
119
120
121typedef set<UCArray, LTUCArray> UCArraySet;
122typedef vector<UCArray> UCArrayVector;
123
124unsigned long PrefixLen (const UCArray &a1, const UCArray &a2);
125
126// prev == NULL if no previous string
127bool WritePreSufStr (FILE *f, const UCArray *prev, const UCArray &a);
128bool ReadPreSufStr (FILE *f, UCArray &a); // a also used for prev
129
130
131#endif
Note: See TracBrowser for help on using the repository browser.