libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moText.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moText.h
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28  Andres Colubri
29 
30 *******************************************************************************/
31 
32 #include "moTypes.h"
33 #include "moArray.h"
34 
35 #ifndef __MO_TEXT_H
36 #define __MO_TEXT_H
37 
38 #include <stdio.h>
39 #include <string.h>
40 
41 #ifdef WIN32
42 #define snprintf _snprintf
43 #endif
44 
45 //====================================================================================
46 // class: moText
47 // derivada de:
48 // descripcion: clase original de manejo de strings en moldeo
49 // author: Gustavo Lado
50 // fecha: ?
51 //====================================================================================
52 
53 #define MO_TXT_COMPLETE 65534
54 #define MO_TXT_NOT_FOUND 65534
55 
58 
59 typedef char* CHARP;
60 typedef int MOINT;
61 typedef unsigned int MOUINT;
62 
63 class moTextArray;
64 
66 
69 #ifdef USE_MOTEXT0
70 
72 {
73 public:
74  moText0();
75  moText0(const moText0&);
76  moText0( char*);
77  moText0( const char*);
78  moText0( wchar_t*);
79 
80  moText0( int );
81  moText0( unsigned int );
82  moText0( long );
83  moText0( unsigned long );
84  moText0( long long );
85  moText0( unsigned long long );
86  moText0( float );
87  moText0( double );
88 
89  virtual ~moText0();
90 
91  MOuint Length() const; // devuelve el length del text sin contar el null del final.
92 
93  // operadores que usan solo objetos de la clase //
94  moText0& operator = ( const moText0& txt);
95  moText0& operator +=( const moText0& txt);
96  //friend moText0 operator + ( const moText0& txt, );
97 
98  int operator < ( const moText0& txt) const;
99  int operator > ( const moText0& txt) const;
100  int operator <=( const moText0& txt) const;
101  int operator >=( const moText0& txt) const;
102  int operator ==( const moText0& txt) const;
103  int operator !=( const moText0& txt) const;
104 
105  // operadores que usan c-strings //
106  moText0& operator = ( const char* txt);
107  moText0& operator = ( const short* txt);
108  moText0& operator +=( const char* txt);
109 
110  friend LIBMOLDEO_API moText0 operator +( const moText0& txt1, const moText0& txt2);
111  friend LIBMOLDEO_API moText0 operator +( const moText0& txt1, const char* txt2);
112  friend LIBMOLDEO_API moText0 operator +( const char* txt1, const moText0& txt2);
113 
114  int operator < ( const char* txt) const;
115  int operator > ( const char* txt) const;
116  int operator <=( const char* txt) const;
117  int operator >=( const char* txt) const;
118  int operator ==( const char* txt) const;
119  int operator !=( const char* txt) const;
120 
121  //char operator [](MOuint pos) { return text[pos]; }
122 
123  // operadores de conversion para poder usar c-strings //
124  virtual operator char*() const { return text; }
125  wchar_t* Unicode() const {
126  std::wstring wc( 1024, L'#' );
127  mbstowcs( &wc[0], text, 1024 );
128  return (wchar_t*)wc.c_str();
129  }
130 
131 
132  // metodos comunes en una clase string//
133  moText0& Left( MOuint); // devuelve el comienzo de un text.
134  moText0& Right( MOuint); // devuelve el final de un text.
135  moText0& Mid( MOuint, MOuint); // devuelve un fragmento intermedio del text.(comienzo, cant de carac)
136  moText0& SubText( MOuint, MOuint); // devuelve un fragmento intermedio del text.(comienzo, final)
137 
138  moText0& Insert( char*, MOuint); // inserta un text dentro de otro.
139  moText0& Delete( MOuint, MOuint); // borra una parte del text.
140 
141  moText0 Scan( char*); // saca y devuelve el primer fragmento de text que este separado por alguno de los caracteres de un cjto.
142  moText0 ScanEx( char*); // saca y devuelve el primer fragmento de text que este separado por alguno de los caracteres de un cjto, y entre comillas.
143 
144  moText0& LTrim(); // saca los espacios del comienzo.
145  moText0& RTrim(); // saca los espacios del final.
146  moText0& Trim(); // saca los espacios del comienzo y del final.
147 
148  unsigned short* Short();
149  void ToUpper(); // convierte el text a mayusculas.
150  void ToLower(); // convierte el text a minusculas.
151 
152  moTextArray Explode( char* separator ) const;
153  int Find( const moText0& target );
154  void ReplaceChar( const char* target, const char* replacement );
155  void Replace( const moText0& target, const moText0& replacement );
156 
157 private:
158  char* text;
159  MOuint length;
160 
161  // Estos metodos son el motor de la clase. Contienen toda la logica
162  // de como se maneja moText0. Todos los metodos publicos las usan.
163 public:
164  void txtcopy( const char* txt, MOuint pos = 0, MOuint com = 0, MOuint fin = MO_TXT_COMPLETE); // copy c-strings(reserva la memoria y pone los nulls al final)
165  void txtcopy( const short* txt, MOuint pos = 0, MOuint com = 0, MOuint fin = MO_TXT_COMPLETE); // copy c-strings(reserva la memoria y pone los nulls al final)
166 private:
167  txtcval txtcomp( const char* txt, MOuint com1 = 0, MOuint com2 = 0) const;
168  MOuint txtfind( const char* txt, txtpert pert = MO_TXT_BELONG, MOuint com = 0, int dir = 1) const;
169 };
170 #endif
171 
172 /*
173 //====================================================================================
174 // class: moString
175 // derivada de: string
176 // descripcion: clase que agrega al string del STL las funciones del moText original.
177 // author: Andres Colubri
178 // fecha: 01/20/2007
179 //====================================================================================
180 
181 class LIBMOLDEO_API moString : public std::string
182 {
183 public:
184  // Constructors.
185  moString() : std::string() {}
186  moString(MOuint length, const char& ch) : std::string(length, ch) {}
187  moString(const char* str) : std::string(str) {}
188  moString(const char* str, MOuint length) : std::string(str, length) {}
189  moString(const std::string& s) : std::string(s) {}
190  moString(const moString& s) : std::string((std::string)s) {}
191  moString(const std::string& str, MOuint index, MOuint length) : std::string(str, index, length) {}
192  moString(const moString& str, MOuint index, MOuint length) : std::string((std::string)str, index, length) {}
193 
194  // Moldeo functions.
195  moString& Left(MOuint nchar); // Sets the string to the first nchar characters in the string.
196  moString& Right(MOuint nchar); // Sets the string to the last nchar characters in the string.
197  moString& Mid(MOuint first, MOuint nchar); // Sets the string to an intermediate substring.
198  moString& SubText(MOuint first, MOuint last); // Sets the string to an intermediate substring.
199 
200  moString& Insert(char *str, MOuint pos); // Inserts s at position pos.
201  moString& Delete(MOuint first, MOuint nchar); // Deletes a part of the string.
202 
203  moString Scan(char *set); // Returns the first substring separated by some of the characters in the set.
204  moString ScanEx(char *set); // Returns the first substring separated by some of the characters in the set and between commas.
205 
206  moString& LTrim(); // Removes the spaces at the beginning of the string.
207  moString& RTrim(); // Removes the spaces at the end of the string.
208  moString& Trim(); // Removes the spaces at both ends of the string.
209 
210  unsigned short* Short(); // Converts the string to an array of shorts.
211  void ToUpper(); // Converts the string to uppercase.
212  void ToLower(); // Converts the string to lowercase.
213 
214  MOuint Length() { return MOuint(length()); }
215 
216  // String functions.
217  moString& assign(const moString& str) { std::string::assign((std::string)str); return *this; }
218  moString& assign(const char* str) { std::string::assign(str); return *this; }
219  moString& assign(const char* str, MOuint num) { std::string::assign(str, num); return *this; }
220  moString& assign(const moString& str, MOuint index, MOuint len) { std::string::assign(str, index, len); return *this; }
221  moString& assign(MOuint num, const char& ch) { std::string::assign(num, ch); return *this; }
222 
223  moString& append(const moString& str) { std::string::append((std::string)str); return *this; }
224  moString& append(const char* str) { std::string::append(str); return *this; }
225  moString& append(const moString& str, MOuint index, MOuint len) { std::string::append(str, index, len); return *this; }
226  moString& append(const char* str, MOuint num) { std::string::append(str, num); return *this; }
227  moString& append(MOuint num, char ch) { std::string::append(num, ch); return *this; }
228 
229  moString substr(MOuint index, MOuint num = npos) { return std::string::substr(index, num); }
230  moString& erase(MOuint index = 0, MOuint num = npos) { std::string::erase(index, num); return *this; }
231 
232  MOuint find(const moString& str, MOuint index) { return std::string::find((std::string)str, index); }
233  MOuint find(const char* str, MOuint index) { return std::string::find(str, index); }
234  MOuint find(const char* str, MOuint index, MOuint length) { return std::string::find(str, index, length); }
235  MOuint find(char ch, MOuint index) { return std::string::find(ch, index); }
236 
237  MOuint rfind(const moString& str, MOuint index) { return std::string::rfind((std::string)str, index); }
238  MOuint rfind(const char* str, MOuint index) { return std::string::rfind(str, index); }
239  MOuint rfind(const char* str, MOuint index, MOuint length) { return std::string::rfind(str, index, length); }
240  MOuint rfind(char ch, MOuint index) { return std::string::rfind(ch, index); }
241 
242  int compare(const moString& str) { return std::string::compare((std::string)str); }
243  int compare(const char* str) { return std::string::compare(str); }
244  int compare(MOuint index, MOuint length, const moString& str) { return std::string::compare(index, length, (std::string)str); }
245  int compare(MOuint index, MOuint length, const moString& str, MOuint index2, MOuint length2) { return std::string::compare(index, length, (std::string)str, index2, length2); }
246 
247  moString& insert(MOuint index, const moString& str) { std::string::insert(index, (std::string)str); return *this; }
248  moString& insert(MOuint index, const char* str) { std::string::insert(index, str); return *this; }
249  moString& insert(MOuint index1, const moString& str, MOuint index2, MOuint num) { std::string::insert(index1, (std::string)str, index2, num); return *this; }
250  moString& insert(MOuint index, const char* str, MOuint num) { std::string::insert(index, str, num); return *this; }
251  moString& insert(MOuint index, MOuint num, char ch) { std::string::insert(index, num, ch); return *this; }
252 
253  moString& replace(MOuint index, MOuint num, const moString& str) { std::string::replace(index, num, (std::string)str); return *this; }
254  moString& replace(MOuint index1, MOuint num1, const moString& str, MOuint index2, MOuint num2) { std::string::replace(index1, num1, (std::string)str, index2, num2); return *this; }
255  moString& replace(MOuint index, MOuint num, const char* str) { std::string::replace(index, num, str); return *this; }
256  moString& replace(MOuint index, MOuint num1, const char* str, MOuint num2) { std::string::replace(index, num1, str, num2); return *this; }
257  moString& replace(MOuint index, MOuint num1, MOuint num2, char ch) { std::string::replace(index, num1, num2, ch); return *this; }
258 
259  // Operators.
260  friend LIBMOLDEO_API bool operator == (const moString& c1, const moString& c2) { return (std::string)c1 == (std::string)c2; }
261  friend LIBMOLDEO_API bool operator != (const moString& c1, const moString& c2) { return (std::string)c1 != (std::string)c2; }
262  friend LIBMOLDEO_API bool operator < (const moString& c1, const moString& c2) { return (std::string)c1 < (std::string)c2; }
263  friend LIBMOLDEO_API bool operator > (const moString& c1, const moString& c2) { return (std::string)c1 > (std::string)c2; }
264  friend LIBMOLDEO_API bool operator <= (const moString& c1, const moString& c2) { return (std::string)c1 <= (std::string)c2; }
265  friend LIBMOLDEO_API bool operator >= (const moString& c1, const moString& c2) { return (std::string)c1 >= (std::string)c2; }
266 
267  friend LIBMOLDEO_API moString operator + (const moString& s1, const moString& s2) { return (std::string)s1 + (std::string)s2; }
268  friend LIBMOLDEO_API moString operator + (const char* s, const moString& s2) { return s + (std::string)s2; }
269  friend LIBMOLDEO_API moString operator + (char c, const moString& s2) { return c + (std::string)s2; }
270  friend LIBMOLDEO_API moString operator + (const moString& s1, const char* s) { return (std::string)s1 + s; }
271  friend LIBMOLDEO_API moString operator + (const moString& s1, char c) { return (std::string)s1 + c; }
272 
273  moString& operator = (const std::string& str) { (std::string)(*this) = str; return *this; }
274  moString& operator = (const moString& str) { (std::string)(*this) = (std::string)str; return *this; }
275  moString& operator = (const char* s) { (std::string)(*this) = s; return *this; }
276  moString& operator = (char ch) { (std::string)(*this) = ch; return *this; }
277 
278  virtual operator const char* () { return c_str(); }
279 };
280 */
281 
282 #ifndef USE_MOTEXT0
283 typedef std::string moText;
284 #endif
285 
286 #ifdef USE_MOTEXT0
287 typedef moText0 moText;
288 #endif
289 
290 //====================================================================================
291 // class: moTextHeap
292 // derivada de:
293 // descripcion: heap de strings
294 // author: Fabricio Costa
295 // fecha: ?
296 //====================================================================================
297 
299 
303 public:
304  moText *array;
305  int n;
306  int count;
307 
308  moTextHeap();
309  moTextHeap(int);
310  ~moTextHeap();
311 
312  void Push(moText);
313  moText Pop();
314  moText Get( int x );
315  void Set(int,moText);
316 };
317 
318 moDeclareExportedDynamicArray( moText, moTextArray );
319 
320 //===========================================
321 //
322 // Utilities
323 //
324 //===========================================
325 
327 LIBMOLDEO_API moText IntToStr( int a, int nzeros );
328 LIBMOLDEO_API moText IntToStr(unsigned int a);
330 LIBMOLDEO_API moText IntToStr(unsigned long a);
331 LIBMOLDEO_API moText IntToStr(long long a);
332 LIBMOLDEO_API moText IntToStr(unsigned long long a);
334 LIBMOLDEO_API moText FloatToStr(double a, int n);
335 LIBMOLDEO_API moText FloatToStr(double a, int nzeros, int ndecimals );
336 
337 #endif
338 
bool operator<=(const moMatrix3 &rkM) const
Definition: moMathMatrix.h:960
#define MO_TXT_COMPLETE
Definition: moText.h:53
bool operator>(const moMatrix3 &rkM) const
Definition: moMathMatrix.h:966
LIBMOLDEO_API moText FloatToStr(double a)
Definition: moText.cpp:1134
#define LIBMOLDEO_API
Definition: moTypes.h:180
clase de para manejar textos
Definition: moText.h:75
moText0 moText
Definition: moText.h:291
bool operator==(const moMatrix3 &rkM) const
Definition: moMathMatrix.h:942
unsigned int MOUINT
Definition: moText.h:62
bool operator<(const moMatrix3 &rkM) const
Definition: moMathMatrix.h:954
txtcval
Definition: moText.h:57
lista de textos
Definition: moText.h:306
bool operator!=(const moMatrix3 &rkM) const
Definition: moMathMatrix.h:948
bool operator>=(const moMatrix3 &rkM) const
Definition: moMathMatrix.h:972
moMatrix3 & operator=(const moMatrix3 &rkM)
char * CHARP
Definition: moText.h:60
#define MOuint
Definition: moTypes.h:387
wchar_t * Unicode() const
Definition: moText.h:125
LIBMOLDEO_API moText IntToStr(int a)
Definition: moText.cpp:1070
moMatrix3 operator+(const moMatrix3 &rkM) const
moMatrix3 & operator+=(const moMatrix3 &rkM)
moDeclareExportedDynamicArray(moText, moTextArray)
txtpert
Definition: moText.h:58
int MOINT
Definition: moText.h:61