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 #include <sstream>
41 
42 #ifdef WIN32
43 #define snprintf _snprintf
44 #endif
45 
46 //====================================================================================
47 // class: moText
48 // derivada de:
49 // descripcion: clase original de manejo de strings en moldeo
50 // author: Gustavo Lado
51 // fecha: ?
52 //====================================================================================
53 
54 #define MO_TXT_COMPLETE 65534
55 #define MO_TXT_NOT_FOUND 65534
56 
59 
60 typedef char* CHARP;
61 typedef int MOINT;
62 typedef unsigned int MOUINT;
63 
64 class moTextArray;
65 
67 
70 #ifndef USE_MOTEXT0
71 #define USE_MOTEXT0 1
72 #endif
73 #ifdef USE_MOTEXT0
74 
76 {
77 public:
78  moText0();
79  moText0(const moText0&);
80  moText0( char*);
81  moText0( const char*);
82  moText0( wchar_t*);
83 
84  moText0( int );
85  moText0( unsigned int );
86  moText0( long );
87  moText0( unsigned long );
88  moText0( long long );
89  moText0( unsigned long long );
90  moText0( float );
91  moText0( double );
92 
93  virtual ~moText0();
94 
95  MOuint Length() const; // devuelve el length del text sin contar el null del final.
96 
97  // operadores que usan solo objetos de la clase //
98  moText0& operator = ( const moText0& txt);
99  moText0& operator +=( const moText0& txt);
100  //friend moText0 operator + ( const moText0& txt, );
101 
102  int operator < ( const moText0& txt) const;
103  int operator > ( const moText0& txt) const;
104  int operator <=( const moText0& txt) const;
105  int operator >=( const moText0& txt) const;
106  int operator ==( const moText0& txt) const;
107  int operator !=( const moText0& txt) const;
108 
109  // operadores que usan c-strings //
110  moText0& operator = ( const char* txt);
111  moText0& operator = ( const short* txt);
112  moText0& operator +=( const char* txt);
113 
114  friend LIBMOLDEO_API moText0 operator +( const moText0& txt1, const moText0& txt2);
115  friend LIBMOLDEO_API moText0 operator +( const moText0& txt1, const char* txt2);
116  friend LIBMOLDEO_API moText0 operator +( const char* txt1, const moText0& txt2);
117 
118  int operator < ( const char* txt) const;
119  int operator > ( const char* txt) const;
120  int operator <=( const char* txt) const;
121  int operator >=( const char* txt) const;
122  int operator ==( const char* txt) const;
123  int operator !=( const char* txt) const;
124 
125  //char operator [](MOuint pos) { return text[pos]; }
126 
127  // operadores de conversion para poder usar c-strings //
128  virtual operator char*() const { return text; }
129  wchar_t* Unicode() const {
130  std::wstring wc( 1024, L'#' );
131  mbstowcs( &wc[0], text, 1024 );
132  return (wchar_t*)wc.c_str();
133  }
134 
135 
136  // metodos comunes en una clase string//
137  moText0& Left( MOuint); // devuelve el comienzo de un text.
138  moText0& Right( MOuint); // devuelve el final de un text.
139  moText0& Mid( MOuint, MOuint); // devuelve un fragmento intermedio del text.(comienzo, cant de carac)
140  moText0& SubText( MOuint, MOuint); // devuelve un fragmento intermedio del text.(comienzo, final)
141 
142  moText0& Insert( char*, MOuint); // inserta un text dentro de otro.
143  moText0& Delete( MOuint, MOuint); // borra una parte del text.
144 
145  moText0 Scan( char*); // saca y devuelve el primer fragmento de text que este separado por alguno de los caracteres de un cjto.
146  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.
147 
148  moText0& LTrim(); // saca los espacios del comienzo.
149  moText0& RTrim(); // saca los espacios del final.
150  moText0& Trim(); // saca los espacios del comienzo y del final.
151 
152  unsigned short* Short();
153  void ToUpper(); // convierte el text a mayusculas.
154  void ToLower(); // convierte el text a minusculas.
155 
156  moTextArray Explode( char* separator ) const;
157  int Find( const moText0& target );
158  void ReplaceChar( const char* target, const char* replacement );
159  void Replace( const moText0& target, const moText0& replacement );
160 
161 private:
162  char* text;
163  MOuint length;
164 
165  // Estos metodos son el motor de la clase. Contienen toda la logica
166  // de como se maneja moText0. Todos los metodos publicos las usan.
167 public:
168  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)
169  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)
170 private:
171  txtcval txtcomp( const char* txt, MOuint com1 = 0, MOuint com2 = 0) const;
172  MOuint txtfind( const char* txt, txtpert pert = MO_TXT_BELONG, MOuint com = 0, int dir = 1) const;
173 };
174 #endif
175 
176 /*
177 //====================================================================================
178 // class: moString
179 // derivada de: string
180 // descripcion: clase que agrega al string del STL las funciones del moText original.
181 // author: Andres Colubri
182 // fecha: 01/20/2007
183 //====================================================================================
184 
185 class LIBMOLDEO_API moString : public std::string
186 {
187 public:
188  // Constructors.
189  moString() : std::string() {}
190  moString(MOuint length, const char& ch) : std::string(length, ch) {}
191  moString(const char* str) : std::string(str) {}
192  moString(const char* str, MOuint length) : std::string(str, length) {}
193  moString(const std::string& s) : std::string(s) {}
194  moString(const moString& s) : std::string((std::string)s) {}
195  moString(const std::string& str, MOuint index, MOuint length) : std::string(str, index, length) {}
196  moString(const moString& str, MOuint index, MOuint length) : std::string((std::string)str, index, length) {}
197 
198  // Moldeo functions.
199  moString& Left(MOuint nchar); // Sets the string to the first nchar characters in the string.
200  moString& Right(MOuint nchar); // Sets the string to the last nchar characters in the string.
201  moString& Mid(MOuint first, MOuint nchar); // Sets the string to an intermediate substring.
202  moString& SubText(MOuint first, MOuint last); // Sets the string to an intermediate substring.
203 
204  moString& Insert(char *str, MOuint pos); // Inserts s at position pos.
205  moString& Delete(MOuint first, MOuint nchar); // Deletes a part of the string.
206 
207  moString Scan(char *set); // Returns the first substring separated by some of the characters in the set.
208  moString ScanEx(char *set); // Returns the first substring separated by some of the characters in the set and between commas.
209 
210  moString& LTrim(); // Removes the spaces at the beginning of the string.
211  moString& RTrim(); // Removes the spaces at the end of the string.
212  moString& Trim(); // Removes the spaces at both ends of the string.
213 
214  unsigned short* Short(); // Converts the string to an array of shorts.
215  void ToUpper(); // Converts the string to uppercase.
216  void ToLower(); // Converts the string to lowercase.
217 
218  MOuint Length() { return MOuint(length()); }
219 
220  // String functions.
221  moString& assign(const moString& str) { std::string::assign((std::string)str); return *this; }
222  moString& assign(const char* str) { std::string::assign(str); return *this; }
223  moString& assign(const char* str, MOuint num) { std::string::assign(str, num); return *this; }
224  moString& assign(const moString& str, MOuint index, MOuint len) { std::string::assign(str, index, len); return *this; }
225  moString& assign(MOuint num, const char& ch) { std::string::assign(num, ch); return *this; }
226 
227  moString& append(const moString& str) { std::string::append((std::string)str); return *this; }
228  moString& append(const char* str) { std::string::append(str); return *this; }
229  moString& append(const moString& str, MOuint index, MOuint len) { std::string::append(str, index, len); return *this; }
230  moString& append(const char* str, MOuint num) { std::string::append(str, num); return *this; }
231  moString& append(MOuint num, char ch) { std::string::append(num, ch); return *this; }
232 
233  moString substr(MOuint index, MOuint num = npos) { return std::string::substr(index, num); }
234  moString& erase(MOuint index = 0, MOuint num = npos) { std::string::erase(index, num); return *this; }
235 
236  MOuint find(const moString& str, MOuint index) { return std::string::find((std::string)str, index); }
237  MOuint find(const char* str, MOuint index) { return std::string::find(str, index); }
238  MOuint find(const char* str, MOuint index, MOuint length) { return std::string::find(str, index, length); }
239  MOuint find(char ch, MOuint index) { return std::string::find(ch, index); }
240 
241  MOuint rfind(const moString& str, MOuint index) { return std::string::rfind((std::string)str, index); }
242  MOuint rfind(const char* str, MOuint index) { return std::string::rfind(str, index); }
243  MOuint rfind(const char* str, MOuint index, MOuint length) { return std::string::rfind(str, index, length); }
244  MOuint rfind(char ch, MOuint index) { return std::string::rfind(ch, index); }
245 
246  int compare(const moString& str) { return std::string::compare((std::string)str); }
247  int compare(const char* str) { return std::string::compare(str); }
248  int compare(MOuint index, MOuint length, const moString& str) { return std::string::compare(index, length, (std::string)str); }
249  int compare(MOuint index, MOuint length, const moString& str, MOuint index2, MOuint length2) { return std::string::compare(index, length, (std::string)str, index2, length2); }
250 
251  moString& insert(MOuint index, const moString& str) { std::string::insert(index, (std::string)str); return *this; }
252  moString& insert(MOuint index, const char* str) { std::string::insert(index, str); return *this; }
253  moString& insert(MOuint index1, const moString& str, MOuint index2, MOuint num) { std::string::insert(index1, (std::string)str, index2, num); return *this; }
254  moString& insert(MOuint index, const char* str, MOuint num) { std::string::insert(index, str, num); return *this; }
255  moString& insert(MOuint index, MOuint num, char ch) { std::string::insert(index, num, ch); return *this; }
256 
257  moString& replace(MOuint index, MOuint num, const moString& str) { std::string::replace(index, num, (std::string)str); return *this; }
258  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; }
259  moString& replace(MOuint index, MOuint num, const char* str) { std::string::replace(index, num, str); return *this; }
260  moString& replace(MOuint index, MOuint num1, const char* str, MOuint num2) { std::string::replace(index, num1, str, num2); return *this; }
261  moString& replace(MOuint index, MOuint num1, MOuint num2, char ch) { std::string::replace(index, num1, num2, ch); return *this; }
262 
263  // Operators.
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  friend LIBMOLDEO_API bool operator < (const moString& c1, const moString& c2) { return (std::string)c1 < (std::string)c2; }
267  friend LIBMOLDEO_API bool operator > (const moString& c1, const moString& c2) { return (std::string)c1 > (std::string)c2; }
268  friend LIBMOLDEO_API bool operator <= (const moString& c1, const moString& c2) { return (std::string)c1 <= (std::string)c2; }
269  friend LIBMOLDEO_API bool operator >= (const moString& c1, const moString& c2) { return (std::string)c1 >= (std::string)c2; }
270 
271  friend LIBMOLDEO_API moString operator + (const moString& s1, const moString& s2) { return (std::string)s1 + (std::string)s2; }
272  friend LIBMOLDEO_API moString operator + (const char* s, const moString& s2) { return s + (std::string)s2; }
273  friend LIBMOLDEO_API moString operator + (char c, const moString& s2) { return c + (std::string)s2; }
274  friend LIBMOLDEO_API moString operator + (const moString& s1, const char* s) { return (std::string)s1 + s; }
275  friend LIBMOLDEO_API moString operator + (const moString& s1, char c) { return (std::string)s1 + c; }
276 
277  moString& operator = (const std::string& str) { (std::string)(*this) = str; return *this; }
278  moString& operator = (const moString& str) { (std::string)(*this) = (std::string)str; return *this; }
279  moString& operator = (const char* s) { (std::string)(*this) = s; return *this; }
280  moString& operator = (char ch) { (std::string)(*this) = ch; return *this; }
281 
282  virtual operator const char* () { return c_str(); }
283 };
284 */
285 
286 #ifndef USE_MOTEXT0
287 typedef std::string moText;
288 #endif
289 
290 #ifdef USE_MOTEXT0
291 typedef moText0 moText;
292 #endif
293 
294 //====================================================================================
295 // class: moTextHeap
296 // derivada de:
297 // descripcion: heap de strings
298 // author: Fabricio Costa
299 // fecha: ?
300 //====================================================================================
301 
303 
307 
308  public:
309  moTextHeap();
310  moTextHeap( int max_heap );
311  moTextHeap( const moTextHeap& p_copy );
312  moTextHeap& operator =( const moTextHeap& p_src );
313  virtual ~moTextHeap();
314 
315  void Init( int max_heap = MO_MAX_DEBUG );
316  void Push( const moText& p_text ) {
317  if ( n>=1 && (n-1-count)>=0 ) {array[n-1-count] = p_text;}
318  count++;
319  }
320  moText Pop();
321  const moText& Get( int x ) const;
322  int Count() const { return count; }
323  int GetMaxHeap() const { return n; }
324  void Set( int p_position , const moText& p_text );
325  void Clean();
326 
327  private:
328  moText *array;
329  int n;
330  int count;
331  moText m_NULL;
332 
333 };
334 
335 moDeclareExportedDynamicArray( moText, moTextArray );
336 
337 //===========================================
338 //
339 // Utilities
340 //
341 //===========================================
342 
344 LIBMOLDEO_API moText IntToStr( int a, int nzeros );
345 LIBMOLDEO_API moText IntToStr(unsigned int a);
347 LIBMOLDEO_API moText IntToStr(unsigned long a);
348 LIBMOLDEO_API moText IntToStr(long long a);
349 LIBMOLDEO_API moText IntToStr(unsigned long long a);
351 LIBMOLDEO_API moText FloatToStr(double a, int n);
352 LIBMOLDEO_API moText FloatToStr(double a, int nzeros, int ndecimals );
353 LIBMOLDEO_API int HexToInt( const moText& hex );
354 LIBMOLDEO_API long HexToLong( const moText& hex );
355 LIBMOLDEO_API float StrToFloat( const moText& hex );
356 LIBMOLDEO_API double StrToDouble( const moText& hex );
357 LIBMOLDEO_API int StrToInt( const moText& hex );
358 LIBMOLDEO_API long StrToLong( const moText& hex );
359 
360 #endif
361 
bool operator<=(const moMatrix3 &rkM) const
Definition: moMathMatrix.h:960
LIBMOLDEO_API long HexToLong(const moText &hex)
Definition: moText.cpp:1190
bool operator>(const moMatrix3 &rkM) const
Definition: moMathMatrix.h:966
LIBMOLDEO_API float StrToFloat(const moText &hex)
Definition: moText.cpp:1202
LIBMOLDEO_API long StrToLong(const moText &hex)
Definition: moText.cpp:1206
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
int GetMaxHeap() const
Definition: moText.h:323
moText0 moText
Definition: moText.h:291
LIBMOLDEO_API double StrToDouble(const moText &hex)
Definition: moText.cpp:1198
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
LIBMOLDEO_API int HexToInt(const moText &hex)
Definition: moText.cpp:1182
txtcval
Definition: moText.h:57
lista de textos
Definition: moText.h:306
void Push(const moText &p_text)
Definition: moText.h:316
#define MO_TXT_COMPLETE
Definition: moText.h:54
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
int Count() const
Definition: moText.h:322
wchar_t * Unicode() const
Definition: moText.h:129
LIBMOLDEO_API moText IntToStr(int a)
Definition: moText.cpp:1070
moMatrix3 operator+(const moMatrix3 &rkM) const
#define MO_MAX_DEBUG
Definition: moTypes.h:381
moMatrix3 & operator+=(const moMatrix3 &rkM)
moDeclareExportedDynamicArray(moText, moTextArray)
txtpert
Definition: moText.h:58
LIBMOLDEO_API int StrToInt(const moText &hex)
Definition: moText.cpp:1210
int MOINT
Definition: moText.h:61