libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Amigas 'defines' Grupos Páginas
moText.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moText.cpp
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 "moText.h"
33 
34 
35 #include "moArray.h"
36 
37 moDefineDynamicArray( moTextArray )
38 
39 
40 #ifdef USE_MOTEXT0
41 
42 //===========================================
43 //
44 // moText0
45 //
46 //===========================================
47 
49 // Construction/Destruction
51 
53 {
54  text = NULL;;
55  length = 0;
56  txtcopy("");
57 }
58 
59 moText0::moText0(const moText0& txt)
60 {
61  text = NULL;
62  length = 0;
63  txtcopy( txt.text);
64 }
65 
66 moText0::moText0( const char* txt)
67 {
68  text = NULL;
69  length = 0;
70  txtcopy( txt);
71 }
72 
73 moText0::moText0( char* txt)
74 {
75  text = NULL;
76  length = 0;
77  txtcopy( txt);
78 }
79 
80 moText0::moText0( wchar_t* wtxt)
81 {
82  char txt[1024];
83  wcstombs ( txt, wtxt, sizeof(txt) );
84 
85  text = NULL;
86  length = 0;
87  txtcopy( txt);
88 }
89 
90 
91 moText0::moText0( int p_num) {
92  text = NULL;
93  length = 0;
94  (*this) = IntToStr(p_num);
95  }
96 
97  moText0::moText0( unsigned int p_num) {
98  text = NULL;
99  length = 0;
100  (*this) = IntToStr(p_num);
101  }
102 
103  moText0::moText0( long p_num) {
104  text = NULL;
105  length = 0;
106  (*this) = IntToStr(p_num);
107  }
108  moText0::moText0( unsigned long p_num) {
109  text = NULL;
110  length = 0;
111  (*this) = IntToStr(p_num);
112  }
113  moText0::moText0( long long p_num) {
114  text = NULL;
115  length = 0;
116  (*this) = IntToStr(p_num);
117  }
118  moText0::moText0( unsigned long long p_num) {
119  text = NULL;
120  length = 0;
121  (*this) = IntToStr(p_num);
122  }
123  moText0::moText0( float p_num) {
124  text = NULL;
125  length = 0;
126  (*this) = FloatToStr(p_num);
127  }
128  moText0::moText0( double p_num) {
129  text = NULL;
130  length = 0;
131  (*this) = FloatToStr(p_num);
132  }
133 
134 
135 
137 {
138  if(text != NULL)
139  delete [] text;
140  text = NULL;
141 }
142 
144 // Metodos privados
146 
147 // txtcopy copy del c-string [txt] desde la posicion [com] hasta [fin]
148 // a la posicion [pos] de moText0 sobreescribiendo y siempre agregando
149 // un null al final.
150 
151 void moText0::txtcopy( const char* txt, MOuint pos, MOuint com, MOuint fin)
152 {
153  MOuint i;
154  char *finaltxt;
155 
156  if (txt==NULL) txt = ""; //cadena vacia
157 
158  if(pos >= length) // si pide copyr mas all�al final concatena
159  pos = length;
160 
161  if(fin == MO_TXT_COMPLETE) // si se pide copyr todo el string en necesario
162  { // saber cuantos caracteres son.
163  fin = com;
164  while( txt[fin]!='\0')
165  fin++;
166  }
167 
168  if(fin < com) // si el final esta antes del comienzo al menos
169  fin = com; // un caracter es copydo.
170 
171 
172  finaltxt = new char[pos+(fin-com+1)+1]; // pido memoria para la parte del text original
173  // + el nuevo text + el null.
174 
175  i = 0;
176  while( i<pos) // copio la parte del text original.
177  {
178  finaltxt[i] = text[i];
179  i++;
180  }
181 
182  i = com;
183  while( i<=fin && txt[i]!='\0') // copio la parte del nuevo text.
184  {
185  finaltxt[pos+i-com] = txt[i];
186  i++;
187  }
188  finaltxt[pos+i-com] = '\0'; // pongo el null al final.
189 
190  if(text != NULL) // actualizo el objeto moText0.
191  delete text;
192  text = finaltxt;
193  length = pos+i-com;
194 
195  //return finaltxt;
196 }
197 
198 
199 void moText0::txtcopy( const short* txt, MOuint pos, MOuint com, MOuint fin)
200 {
201  MOuint i;
202  char *finaltxt;
203 
204  if(pos >= length) // si pide copyr mas all�al final concatena
205  pos = length;
206 
207  if(fin == MO_TXT_COMPLETE) // si se pide copyr todo el string en necesario
208  { // saber cuantos caracteres son.
209  fin = com;
210  while( txt[fin]!='\0')
211  fin++;
212  }
213 
214  if(fin < com) // si el final esta antes del comienzo al menos
215  fin = com; // un caracter es copydo.
216 
217 
218  finaltxt = new char[pos+(fin-com+1)+1]; // pido memoria para la parte del text original
219  // + el nuevo text + el null.
220 
221  i = 0;
222  while( i<pos) // copio la parte del text original.
223  {
224  finaltxt[i] = text[i];
225  i++;
226  }
227 
228  i = com;
229  while( i<=fin && txt[i]!='\0') // copio la parte del nuevo text.
230  {
231  finaltxt[pos+i-com] =(char)txt[i];
232  i++;
233  }
234  finaltxt[pos+i-com] = '\0'; // pongo el null al final.
235 
236  if(text != NULL) // actualizo el objeto moText0.
237  delete text;
238  text = finaltxt;
239  length = pos+i-com;
240 
241  //return finaltxt;
242 }
243 
244 // txtcomp compara caracter a caracter [text] con [txt] a partir de las posiciones
245 // [com1] y [com2] respectivamente. Es CASE-SENSITIVE.
246 
247 txtcval moText0::txtcomp( const char* txt, MOuint com1, MOuint com2) const
248 {
249  MOuint i1, i2;
250 
251  if(com1 > length) // si el comienzo supera el length del text empieza
252  com1 = length - 1; // por el last caracter.
253 
254  i1 = com1;
255  i2 = com2;
256  while( text[i1]!='\0' && txt[i2]!='\0')
257  {
258  if(text[i1] < txt[i2]) // para que devuelva IGUAL ambos texts tienen
259  return MO_TXT_LESSER; // que tener los mismos caracteres y la misma
260  else // longitud,
261  if(text[i1] > txt[i2])
262  return MO_TXT_GREATER; // si primero aparece una diferencia en los ca_
263  else // racteres es menos el que este primero en la
264  { // tabla ASCII.
265  i1++;
266  i2++;
267  }
268  }
269 
270  if(text[i1] == '\0' && txt[i2] != '\0') // si tienen los mismos caracteres
271  return MO_TXT_LESSER; // pero uno es mas corto, entonces
272  else // ese es el menor.
273  if(text[i1] != '\0' && txt[i2] == '\0')
274  return MO_TXT_GREATER;
275 
276  return MO_TXT_EQUAL;
277 }
278 
279 
280 // txtfind busca en [text] desde la posicion [com] la pertenencia de los caracteres
281 // de [cjto]. Si [pert] es PERTENECE devuelve la posicion del primer caracter de
282 // [text] perteneciente a [cjto], si es NOT_BELONG la posicion del primer caracter
283 // de [text] no perteneciente a [cjto]. La busqueda se realiza en la direccion [dir].
284 
285 MOuint moText0::txtfind( const char* cjto, txtpert pert, MOuint com, int dir) const
286 {
287  MOuint i, j, found;
288 
289  if(dir > 1) // si la direccion es distinta de 1 o -1 es corregida.
290  dir = 1;
291 
292  if(dir <= 0)
293  dir = -1;
294 
295  if(com >= length) // si el comienzo supera el length del text comienza
296  com = length - 1; // por el last caracter.
297 
298  switch(pert)
299  {
300  case MO_TXT_BELONG:
301  i = com;
302  while( i<length) // recorre el text.
303  {
304  j = 0;
305  while( cjto[j] != '\0') // recorre el cjto de caracteres.
306  {
307  if(text[i] == cjto[j]) // si encuentra un caracter...
308  return i; // devuelve la posicion...
309  j++;
310  }
311  i += dir; // sino sigue buscando.
312  }
313  break;
314 
315  case MO_TXT_NOT_BELONG:
316  i = com;
317  while( i<length) // recorre el text.
318  {
319  found = 0;
320  j = 0;
321  while( cjto[j] != '\0') // recorre el cjto de caracteres.
322  {
323  if(text[i] == cjto[j]) // si encuentra un caracter..
324  found = 1; // va a seguir buscando...
325  j++;
326  }
327  if(!found) // sino devuelve la posicion.
328  return i;
329  i += dir;
330  }
331  break;
332  }
333 
334  return MO_TXT_NOT_FOUND;
335 }
336 
337 
339 // Metodos publicos
341 
342 MOuint moText0::Length() const
343 {
344  return length;
345 }
346 
347 moText0& moText0::operator =( const moText0& txt)
348 {
349  txtcopy( txt.text, 0, 0, txt.length);
350  return *this;
351 }
352 
354 {
355  txtcopy( txt.text, MO_TXT_COMPLETE, 0, txt.length);
356  return *this;
357 }
358 
359 
360 int moText0::operator <( const moText0& txt) const
361 {
362  return( txtcomp(txt.text) == MO_TXT_LESSER);
363 }
364 
365 int moText0::operator >( const moText0& txt) const
366 {
367  return( txtcomp(txt.text) == MO_TXT_GREATER);
368 }
369 
370 int moText0::operator <=( const moText0& txt) const
371 {
372  return( txtcomp(txt.text)==MO_TXT_LESSER || txtcomp(txt.text)==MO_TXT_EQUAL);
373 }
374 
375 int moText0::operator >=( const moText0& txt) const
376 {
377  return( txtcomp(txt.text)==MO_TXT_GREATER || txtcomp(txt.text)==MO_TXT_EQUAL);
378 }
379 
380 int moText0::operator ==( const moText0& txt) const
381 {
382  return( txtcomp(txt.text) == MO_TXT_EQUAL);
383 }
384 
385 int moText0::operator !=( const moText0& txt) const
386 {
387  return( txtcomp(txt.text) != MO_TXT_EQUAL);
388 }
389 
390 
391 moText0& moText0::operator =( const char* txt)
392 {
393  txtcopy(txt);
394  return *this;
395 }
396 
397 moText0& moText0::operator =( const short* txt)
398 {
399  txtcopy(txt);
400  return *this;
401 }
402 
403 moText0& moText0::operator +=( const char* txt)
404 {
406  return *this;
407 }
408 
409 
410 LIBMOLDEO_API moText0 operator +( const moText0& txt1, const moText0& txt2 )
411 {
412  moText0 txtres(txt1);
413  txtres+= txt2;
414  return txtres;
415 }
416 
417 LIBMOLDEO_API moText0 operator +( const moText0& txt1, const char* txt2)
418 {
419  moText0 txtres(txt1);
420  txtres.txtcopy( txt2, MO_TXT_COMPLETE);
421  return txtres;
422 }
423 
424 LIBMOLDEO_API moText0 operator +( const char* txt1, const moText0& txt2)
425 {
426  moText0 txtres(txt1);
427  txtres+= txt2;
428  return txtres;
429 }
430 
431 
432 int moText0::operator < ( const char* txt) const
433 {
434  return( txtcomp(txt) == MO_TXT_LESSER);
435 }
436 
437 int moText0::operator > ( const char* txt) const
438 {
439  return( txtcomp(txt) == MO_TXT_GREATER);
440 }
441 
442 int moText0::operator <=( const char* txt) const
443 {
444  return( txtcomp(txt)==MO_TXT_LESSER || txtcomp(txt)==MO_TXT_EQUAL);
445 }
446 
447 int moText0::operator >=( const char* txt) const
448 {
449  return( txtcomp(txt)==MO_TXT_GREATER || txtcomp(txt)==MO_TXT_EQUAL);
450 }
451 
452 int moText0::operator ==( const char* txt) const
453 {
454  return( txtcomp(txt) == MO_TXT_EQUAL);
455 }
456 
457 int moText0::operator !=( const char* txt) const
458 {
459  return( txtcomp(txt) != MO_TXT_EQUAL);
460 }
461 
462 unsigned short* moText0::Short() {
463 
464  unsigned short *txtshort;
465  MOuint i = 0;
466 
467  txtshort = new unsigned short [length+1];
468 
469  while( i < length ) // copio la parte del text original.
470  {
471  txtshort[i] =(char)text[i];
472  i++;
473  }
474  txtshort[length] = '\0';
475 
476  return txtshort;
477 }
478 
480 {
481  if (cant<length)
482  txtcopy( text, 0, 0, cant);
483  return *this;
484 }
485 
487 {
488  if ( length > cant)
489  txtcopy( text, 0, length-cant, MO_TXT_COMPLETE);
490  return *this;
491 }
492 
493 moText0& moText0::Mid( MOuint com, MOuint cant)
494 {
495  txtcopy( text, 0, com, com+cant-1);
496  return *this;
497 }
498 
500 {
501  txtcopy( text, 0, com, fin);
502  return *this;
503 }
504 
505 
506 moText0& moText0::Insert( char* txt, MOuint pos)
507 {
508  moText0 tmp( text+pos);
509  txtcopy( txt, pos);
510  txtcopy( tmp.text, MO_TXT_COMPLETE);
511  return *this;
512 }
513 
515 {
516  txtcopy( text, pos, pos+cant, MO_TXT_COMPLETE);
517  return *this;
518 }
519 
520 
521 // Scan devuelve un nuevo text que contiene todos los caracteres de [text] desde el
522 // primer caracter no perteneciente a [cjto] hasta el next caracter perteneciente
523 // a [cjto] y saca esta parte de [text].
524 
525 moText0 moText0::Scan( char* cjto)
526 {
527  moText0 newtxt;
528  MOuint pos1 = txtfind( cjto, MO_TXT_NOT_BELONG);
529  MOuint pos2 = txtfind( cjto, MO_TXT_BELONG, pos1);
530  if(pos1 == MO_TXT_NOT_FOUND) pos1 = 0;
531  if(pos2 == MO_TXT_NOT_FOUND) pos2 = length;
532  if ( (pos1+1) < pos2 ) newtxt.txtcopy( text, 0, pos1, pos2-1);
533  else newtxt = "";
534  txtcopy( text, 0, pos2);
535  return newtxt;
536 }
537 
538 moText0 moText0::ScanEx( char* cjto)
539 {
540  moText0 newtxt;
541  MOuint pos2;
542  MOuint pos1;
543 
544  pos1 = txtfind( cjto, MO_TXT_NOT_BELONG);
545 
546  if(pos1 == MO_TXT_NOT_FOUND) {
547  pos1 = 0;
548  pos2 = txtfind( cjto, MO_TXT_BELONG, pos1);
549  } else if ( text[pos1] == '\"') {//empieza por una comilla
550  if ( (pos1+1) < length ) {
551  pos2 = txtfind( "\"", MO_TXT_BELONG, pos1+1);//buscamos la q cierra
552  } else pos2 = pos1+1;
553 
554  if ( pos2 == MO_TXT_NOT_FOUND ) {//sino buscamos el separador mas cercano
555  pos1 = pos1+1;
556  pos2 = txtfind( cjto, MO_TXT_BELONG, pos1);
557  } else {
558  //texto entre comillas
559  pos1 = pos1+1;
560  pos2 = pos2;
561  if ( (pos1+1) < pos2 ) newtxt.txtcopy( text, 0, pos1, pos2-1);
562  else newtxt = "";
563  txtcopy( text, 0, pos2+1);
564  return newtxt;
565  }
566 
567  } else {
568  pos2 = txtfind( cjto, MO_TXT_BELONG, pos1);
569  }
570 
571  if(pos2 == MO_TXT_NOT_FOUND) pos2 = length;
572 
573  if ( (pos1+1) < pos2 ) newtxt.txtcopy( text, 0, pos1, pos2-1);
574  else newtxt = "";
575  txtcopy( text, 0, pos2);
576  return newtxt;
577 }
578 
580 {
581  MOuint pos = txtfind( " \t\n", MO_TXT_NOT_BELONG);
582  if(pos != MO_TXT_NOT_FOUND)
583  Right( length-pos);
584  else if(txtfind( " \t\n", MO_TXT_BELONG) != MO_TXT_NOT_FOUND)
585  txtcopy("");
586  return *this;
587 }
588 
590 {
591  MOuint pos = txtfind( " \t\n", MO_TXT_NOT_BELONG, length, -1);
592  if(pos != MO_TXT_NOT_FOUND)
593  Left( pos);
594  else if(txtfind( " \t\n", MO_TXT_BELONG, length, -1) != MO_TXT_NOT_FOUND)
595  txtcopy("");
596  return *this;
597 }
598 
600 {
601  LTrim();
602  RTrim();
603  return *this;
604 }
605 
606 void moText0::ToUpper()
607 {
608  // Revisar... en Linux los caracteres de inicializacion de interchar1, interchar2 eran ilegibles.
609  moText0 interchar1(" ");
610  moText0 interchar2(" ");
611 
612  char tmp[2] = " ";
613  MOuint i, pos;
614 
615  for( i=0; i<length; i++)
616  if(text[i] >= 'a' && text[i] <= 'z')
617  text[i] = text[i] -('a'-'A');
618  else
619  {
620  tmp[0] = text[i];
621  pos = interchar1.txtfind(tmp);
622  if(pos != MO_TXT_NOT_FOUND)
623  text[i] = interchar2[pos];
624  }
625 }
626 
627 void moText0::ToLower()
628 {
629  // Revisar... en Linux los caracteres de inicializacion de interchar1, interchar2 eran ilegibles.
630  moText0 interchar1(" ");
631  moText0 interchar2(" ");
632 
633  char tmp[2] = " ";
634  MOuint i, pos;
635 
636  for( i=0; i<length; i++)
637  if(text[i] >= 'A' && text[i] <= 'Z')
638  text[i] = text[i] +('a'-'A');
639  else
640  {
641  tmp[0] = text[i];
642  pos = interchar2.txtfind(tmp);
643  if(pos != MO_TXT_NOT_FOUND)
644  text[i] = interchar1[pos];
645  }
646 }
647 
648 
649 moTextArray
650 moText0::Explode( char* separator ) const
651 {
652 
653  moTextArray Tarray;
654  moText0 Ltext, Rtext;
655 
656  //std::string txtstr = text;
657  Rtext = (*this);
658 
659  MOuint posa, posb;
660  posa = 0;
661  posb = 0;
662 
663  Ltext = Rtext.Scan(separator);
664 
665  while ( Ltext.Length() > 0 ) {
666 
667  if (Ltext.Length())
668  Tarray.Add( Ltext );
669 
670  Ltext = Rtext.Scan(separator);
671 
672  }
673 
674  return Tarray;
675 }
676 
677 int
678 moText0::Find( const moText0& target ) {
679 
680  moText0 newone;
681  int founded,i,j;
682  moText0 mLeft;
683  moText0 mRight = (*this);
684 
685  i = 0;
686  founded = -1;
687 
688  while( mRight.Length()>0 ) {
689 
690  bool cmp = false;
691 
692  founded = -1;
693 
694  for(j =0; j<(int)target.Length(); j++ ) {
695 
696  if ( target.text[j] == mRight.text[i+j] ) {
697  cmp = true;
698  if ((j+1)==(int)target.Length()) {
699  founded = i;
700  }
701  } else {
702  cmp = false;
703  break;
704  }
705 
706  }
707 
708  i++;
709 
710  //if founded first occurance
711  if (founded>-1) {
712  return founded;
713  }
714 
715  }
716  return founded;
717 
718 }
719 
720 
721 void
722 moText0::Replace( const moText0& target, const moText0& replacement ) {
723 
724  moText0 newone;
725  int toreplace,i,j;
726  moText0 mLeft;
727  moText0 mRight = (*this);
728 
729  i = 0;
730 
731  while( mRight.Length()>0 ) {
732 
733  bool cmp = false;
734 
735  toreplace = -1;
736 
737  for(j =0; j<(int)target.Length(); j++ ) {
738 
739  if ( target.text[j] == mRight.text[i+j] ) {
740  cmp = true;
741  if ((j+1)==(int)target.Length()) {
742  toreplace = i;
743  }
744  } else {
745  cmp = false;
746  break;
747  }
748 
749  }
750 
751  i++;
752 
753  if (toreplace>-1) {
754  mLeft = mRight;
755  mLeft.Left(toreplace);
756  mRight.Right( Length() - (toreplace+target.Length()));
757  newone+= mLeft;
758  newone+= replacement;
759  i = 0;
760  }
761 
762 
763 
764  }
765 
766 }
767 
768 void
769 moText0::ReplaceChar( const char* target, const char* replacement ) {
770 
771  moText tt = (char*)target;
772  moText tr = (char*)replacement;
773  if ( tt.Length()==1 && tr.Length()==1 )
774  for( int i=0; i<(int)Length(); i++) {
775  char c = target[0];
776  if (text[i]==c) {
777  text[i] = replacement[0];
778  }
779  }
780 
781 }
782 
783 #endif
784 
785 /*
786 //===========================================
787 //
788 // moString
789 //
790 //===========================================
791 
792 moString& moString::Left(MOuint nchar)
793 {
794  erase(nchar, length() - 1);
795  return *this;
796 }
797 
798 moString& moString::Right(MOuint nchar)
799 {
800  erase(0, length() - 1 - nchar);
801  return *this;
802 }
803 
804 moString& moString::Mid(MOuint first, MOuint nchar)
805 {
806  MOuint last = first + nchar - 1;
807  return SubText(first, last);
808 }
809 
810 moString& moString::SubText(MOuint first, MOuint last)
811 {
812  erase(last + 1, length() - 1);
813  erase(0, first - 1);
814  return *this;
815 }
816 
817 moString& moString::Insert(char *str, MOuint pos)
818 {
819  insert(pos, str);
820  return *this;
821 }
822 
823 moString& moString::Delete(MOuint first, MOuint nchar)
824 {
825  erase(first, first + nchar - 1);
826  return *this;
827 }
828 
829 moString moString::Scan(char *set)
830 {
831  moString new_str;
832  if (set != NULL)
833  {
834  char c;
835  int j = 0;
836  std::string::size_type p0, p1;
837  while(set[j] != '\0')
838  {
839  c = set[j];
840  p0 = find(c, 0);
841  if (std::string::npos != p0)
842  {
843  p1 = find(c, p0 + 1);
844  if (std::string::npos == p1) p1 = length() - 1;
845  new_str = substr(p0, p1 - p0 + 1);
846  return new_str;
847  }
848  j++;
849  }
850  }
851  return new_str;
852 }
853 
854 moString moString::ScanEx(char *set)
855 {
856  moString new_str0;
857  if (set != NULL)
858  {
859  char c;
860  int j = 0;
861  std::string::size_type p0, p1;
862  while(set[j] != '\0')
863  {
864  c = set[j];
865  p0 = find(c, 0);
866  if (std::string::npos != p0)
867  {
868  moString new_str;
869 
870  p1 = find(c, p0 + 1);
871  if (std::string::npos == p1) p1 = length() - 1;
872  new_str0 = substr(p0, p1 - p0 + 1);
873 
874  // Getting substring between commas in new_str0.
875  p0 = new_str0.find_first_not_of('\"');
876  if (std::string::npos == p0) p0 = 0;
877  p1 = new_str0.find_last_not_of('\"');
878  if (std::string::npos == p1) p0 = new_str0.length() - 1;
879 
880  new_str = new_str0.substr(p0, p1 - p0 + 1);
881  return new_str;
882  }
883  j++;
884  }
885  }
886  return new_str0;
887 }
888 
889 moString& moString::LTrim()
890 {
891  erase(0, find_first_not_of(' '));
892  return *this;
893 }
894 
895 moString& moString::RTrim()
896 {
897  erase(find_last_not_of(' ') + 1);
898  return *this;
899 }
900 
901 moString& moString::Trim()
902 {
903  LTrim();
904  RTrim();
905  return *this;
906 }
907 
908 unsigned short* moString::Short()
909 {
910  unsigned short *str_short;
911  str_short = new unsigned short [length() +1];
912 
913  for (MOuint i = 0; i < length(); i++) str_short[i] = (unsigned short)(*this)[i];
914  str_short[length()] = '\0';
915 
916  return str_short;
917 }
918 
919 void moString::ToUpper()
920 {
921  char c;
922  for (MOuint i = 0; i < length(); i++)
923  {
924  c = (*this)[i];
925  if (c >= 'A' && c <= 'Z') (*this)[i] = c - ('a' - 'A');
926  }
927 }
928 
929 void moString::ToLower()
930 {
931  char c;
932  for (MOuint i = 0; i < length(); i++)
933  {
934  c = (*this)[i];
935  if (c >= 'A' && c <= 'Z') (*this)[i] = c + ('a' - 'A');
936  }
937 }
938 */
939 
940 //===========================================
941 //
942 // moTextHeap
943 //
944 //===========================================
945 
947  n = MO_MAX_DEBUG;
948  array = new moText [n];
949  count = 0;
950 }
951 
952 moTextHeap::moTextHeap(int m) {
953  n = m;
954  array = new moText [n];
955 }
956 
957 
959  if(array!=NULL) delete[] array;
960  array = NULL;
961 }
962 
963 
964 void
966  if ( n>=1 && (n-1-count)>=0 ) {array[n-1-count] = T;}
967  count++;
968 }
969 
970 
971 moText
972 moTextHeap::Pop() {
973  int i;
974  moText ret;
975  if(n>=1) {ret = array[n-1];}
976  if(n>=2) {for(i=(n-1);i>0;i--) array[i] = array[i-1];}
977  if (count>0) count--;
978  return ret;
979 }
980 
981 
982 moText
984  moText ret;
985  if(0<=x && x<n) {
986  ret = array[x];
987  return ret;
988  }
989  else printf("moTextHeap:: Error");
990  return moText("");
991 }
992 
993 void
995  if(x<n) { array[x] = T; }
996  else printf("moTextHeap:: Error");
997 }
998 
999 //===========================================
1000 //
1001 // Utilities
1002 //
1003 //===========================================
1004 
1005 #ifdef USE_MOTEXT0
1006 
1008 {
1009  char buffer[100];
1010  snprintf(buffer, 100, "%i", a); // Memory-safe version of sprintf.
1011 
1012  moText str = buffer;
1013  return str;
1014 }
1015 
1016 LIBMOLDEO_API moText0 IntToStr( int a, int nzeros )
1017 {
1018  char buffer[100];
1019  nzeros = 2;
1020  snprintf(buffer, 100, "%02d", a); // Memory-safe version of sprintf.
1021 
1022  moText str = buffer;
1023  return str;
1024 }
1025 
1027 {
1028  char buffer[100];
1029  snprintf(buffer, 100, "%i", a); // Memory-safe version of sprintf.
1030 
1031  moText str = buffer;
1032  return str;
1033 }
1034 
1036 {
1037  char buffer[100];
1038  snprintf(buffer, 100, "%ld", a); // Memory-safe version of sprintf.
1039 
1040  moText str = buffer;
1041  return str;
1042 }
1043 
1045 {
1046  char buffer[100];
1047  snprintf(buffer, 100, "%lu", a); // Memory-safe version of sprintf.
1048 
1049  moText str = buffer;
1050  return str;
1051 }
1052 
1054 {
1055  char buffer[100];
1056  snprintf(buffer, 100, "%lld", a); // Memory-safe version of sprintf.
1057 
1058  moText str = buffer;
1059  return str;
1060 }
1061 
1062 LIBMOLDEO_API moText0 IntToStr(unsigned long long a)
1063 {
1064  char buffer[100];
1065  snprintf(buffer, 100, "%llu", a); // Memory-safe version of sprintf.
1066 
1067  moText str = buffer;
1068  return str;
1069 }
1070 
1072 {
1073  char buffer[100];
1074  snprintf(buffer, 100, "%f", a); // Memory-safe version of sprintf.
1075 
1076  moText str = buffer;
1077 
1078  str.ReplaceChar( ",", "." );
1079 
1080  return str;
1081 }
1082 
1084 {
1085  char *buffer;
1086  buffer = new char[100];
1087 
1088  snprintf(buffer, n, "%f", a); // Memory-safe version of sprintf.
1089 
1090  moText str = buffer;
1091 
1092  delete buffer;
1093 
1094  str.ReplaceChar( ",", "." );
1095 
1096  return str;
1097 }
1098 
1099 LIBMOLDEO_API moText0 FloatToStr(double a, int nzeros, int ndecimals )
1100 {
1101  char *buffer;
1102  buffer = new char[100];
1103 
1104  nzeros = 2;
1105  ndecimals = 2;
1106 
1107  snprintf(buffer, 100, "%02.3f", a); // Memory-safe version of sprintf.
1108 
1109  moText str = buffer;
1110 
1111  delete buffer;
1112 
1113  str.ReplaceChar( ",", "." );
1114 
1115  return str;
1116 }
1117 
1118 #endif
1119 
int operator<(const moText0 &txt) const
Definition: moText.cpp:365
moText0 & LTrim()
Definition: moText.cpp:584
moTextArray Explode(char *separator) const
Definition: moText.cpp:655
void ToLower()
Definition: moText.cpp:632
moText0 & Insert(char *, MOuint)
Definition: moText.cpp:511
var c
Definition: jquery.js:29
LIBMOLDEO_API moText0 FloatToStr(double a)
Definition: moText.cpp:1134
moText0 & operator=(const moText0 &txt)
Definition: moText.cpp:352
function a
Definition: jquery.js:41
moText0 & Left(MOuint)
Definition: moText.cpp:484
function x(bx)
Definition: jquery.js:30
void Replace(const moText0 &target, const moText0 &replacement)
Definition: moText.cpp:729
moText0 & operator+=(const moText0 &txt)
Definition: moText.cpp:358
moText0 & Delete(MOuint, MOuint)
Definition: moText.cpp:519
#define LIBMOLDEO_API
Definition: moTypes.h:180
void ReplaceChar(const char *target, const char *replacement)
Definition: moText.cpp:796
clase de para manejar textos
Definition: moText.h:75
void Set(int p_position, const moText &p_text)
Definition: moText.cpp:1056
moDefineDynamicArray(moTextArray) moText0
Definition: moText.cpp:37
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
moText0 & Trim()
Definition: moText.cpp:604
moText0 moText
Definition: moText.h:291
moText0 & Right(MOuint)
Definition: moText.cpp:491
moText0 ScanEx(char *)
Definition: moText.cpp:543
moText0 & Mid(MOuint, MOuint)
Definition: moText.cpp:498
unsigned short * Short()
Definition: moText.cpp:467
moText Pop()
Definition: moText.cpp:1032
moTextHeap()
Definition: moText.cpp:973
LIBMOLDEO_API moText0 operator+(const moText0 &txt1, const moText0 &txt2)
Definition: moText.cpp:415
const moText & Get(int x) const
Definition: moText.cpp:1048
moText0 Scan(char *)
Definition: moText.cpp:530
int operator==(const moText0 &txt) const
Definition: moText.cpp:385
MOuint Length() const
Definition: moText.cpp:347
txtcval
Definition: moText.h:57
int operator!=(const moText0 &txt) const
Definition: moText.cpp:390
void Push(const moText &p_text)
Definition: moText.h:316
#define MO_TXT_NOT_FOUND
Definition: moText.h:55
virtual ~moTextHeap()
Definition: moText.cpp:1013
#define MO_TXT_COMPLETE
Definition: moText.h:54
int operator>=(const moText0 &txt) const
Definition: moText.cpp:380
#define MOuint
Definition: moTypes.h:387
void txtcopy(const char *txt, MOuint pos=0, MOuint com=0, MOuint fin=MO_TXT_COMPLETE)
Definition: moText.cpp:154
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
int operator<=(const moText0 &txt) const
Definition: moText.cpp:375
int operator>(const moText0 &txt) const
Definition: moText.cpp:370
void ToUpper()
Definition: moText.cpp:611
int Find(const moText0 &target)
divide el texto separado por el caracter especificado
Definition: moText.cpp:683
moText0 & SubText(MOuint, MOuint)
Definition: moText.cpp:504
#define MO_MAX_DEBUG
Definition: moTypes.h:381
moText0 & RTrim()
Definition: moText.cpp:594
txtpert
Definition: moText.h:58
virtual ~moText0()
Definition: moText.cpp:139