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