PageRenderTime 412ms CodeModel.GetById 32ms app.highlight 230ms RepoModel.GetById 100ms app.codeStats 1ms

/src/util_code/stringc.cpp

https://github.com/w601sxs/OpenVSP
C++ | 1074 lines | 753 code | 199 blank | 122 comment | 252 complexity | 7dc2556867c401cb585abd4e39987d15 MD5 | raw file
   1//
   2// This file is released under the terms of the NASA Open Source Agreement (NOSA)
   3// version 1.3 as detailed in the LICENSE file which accompanies this software.
   4//
   5
   6//********************************
   7// String Class
   8//
   9// Cathy D. Roberts
  10// Sterling Software
  11//
  12//********************************
  13
  14#include "stringc.h"

  15
  16//-------------------------- Constructors -----------------------------------
  17//----------------------------------------------------------------------------
  18
  19Stringc::Stringc()
  20{
  21    chunk_size = STRINGC_CHUNK_SIZE;
  22    total_size = 0;
  23    num_chars = 0;
  24    make_space();
  25    char_array[num_chars] = '\0';
  26}
  27
  28//----------------------------------------------------------------------------
  29
  30Stringc::Stringc(const char ch)
  31{
  32    chunk_size = STRINGC_CHUNK_SIZE;
  33    num_chars = 1;
  34    make_space();
  35    (*this)[0] = ch;
  36    (*this)[num_chars] = '\0';
  37}
  38
  39//----------------------------------------------------------------------------
  40
  41Stringc::Stringc(const char *ch_array)
  42{
  43    chunk_size = STRINGC_CHUNK_SIZE;
  44    if (ch_array)
  45      num_chars = strlen(ch_array);
  46    else
  47      num_chars = 0;
  48    make_space();
  49    for (int i=0;i<num_chars;i++)
  50         (*this)[i] = ch_array[i];
  51      (*this)[num_chars] = '\0';
  52}
  53
  54//----------------------------------------------------------------------------
  55
  56Stringc::Stringc(int ichar)
  57{
  58   chunk_size = STRINGC_CHUNK_SIZE;
  59   num_chars = ichar;
  60   make_space();
  61   for (int i=0; i<num_chars; i++)
  62      char_array[i] = ' ';
  63   char_array[num_chars] = '\0';
  64}
  65
  66//----------------------------------------------------------------------------
  67
  68Stringc::Stringc(const Stringc& str)
  69{
  70   num_chars = str.num_chars;
  71   chunk_size = str.chunk_size;
  72   make_space();
  73   for (int i=0; i< num_chars; i++)
  74      (*this)[i] = str[i];
  75   (*this)[num_chars] = '\0';
  76}
  77
  78//----------------------------- Destructor -----------------------------------
  79//----------------------------------------------------------------------------
  80
  81Stringc::~Stringc()
  82{
  83   clear_space();
  84}
  85
  86//--------------------------- Private functions ------------------------------
  87//----------------------------------------------------------------------------
  88
  89void Stringc::make_space()
  90{
  91
  92    int size_mult = (num_chars+1)/chunk_size+1;
  93    total_size = size_mult*chunk_size;
  94    char_array = new char[total_size];
  95}
  96
  97//----------------------------------------------------------------------------
  98
  99void Stringc::clear_space()
 100{
 101//    if ( num_chars >= 0 ) delete [] char_array;
 102
 103	if ( total_size >= 0 ) delete [] char_array;
 104}
 105
 106//----------------------------------------------------------------------------
 107
 108void Stringc::append(char ch)
 109{
 110   num_chars++;
 111   if ( (num_chars+1) >= total_size )
 112      {
 113      char* old_char_array = char_array;
 114      make_space();
 115      if ( old_char_array ) 
 116         {
 117         memcpy(char_array, old_char_array, num_chars*sizeof(char));
 118         delete [] old_char_array;
 119         }
 120      }
 121   char_array[num_chars-1] = ch;
 122   char_array[num_chars] = '\0';
 123}
 124
 125//----------------------------------------------------------------------------
 126
 127void Stringc::prepend(char ch)
 128{
 129   num_chars++;
 130   if ( (num_chars+1) >= total_size )
 131      {
 132      char* old_char_array = char_array;
 133      make_space();
 134      if ( old_char_array ) 
 135         {
 136         memcpy(char_array+1, old_char_array, num_chars*sizeof(char));
 137         delete [] old_char_array;
 138         }
 139      }
 140   else
 141   {
 142	   // shift chars
 143	   for (int i = num_chars-1; i > 0; i--)
 144		   char_array[i] = char_array[i-1];
 145   }
 146   char_array[0] = ch;
 147   char_array[num_chars] = '\0';
 148}
 149
 150//----------------------------------------------------------------------------
 151
 152void Stringc::rdelete(int istart, int iend)
 153{
 154  int i=0;
 155   if ((istart > -1)&&(istart < num_chars)&&(iend > -1)&&(iend < num_chars)
 156        &&(istart <= iend))
 157      {
 158      int new_num = num_chars - (iend-istart+1);
 159      int new_size = ((new_num+1)/chunk_size)*chunk_size;
 160      if (new_size == total_size)
 161         {
 162         for( i=istart; i<new_num; i++)
 163            char_array[i] = char_array[i+(iend-istart+1)];
 164         num_chars = new_num;
 165         char_array[num_chars] = '\0';
 166         }
 167      else
 168         {   
 169         int new_length = num_chars - (iend-istart+1);
 170         char *new_char = new char[new_length+1];
 171         for (i=0; i<istart; i++)
 172            new_char[i] = char_array[i];
 173         int j=istart;
 174         for (i=iend+1; i<num_chars; i++)
 175            {
 176            new_char[j] = char_array[i];
 177            j++;
 178            }
 179         clear_space();
 180         num_chars = new_length;
 181         make_space();
 182         for ( i=0; i<num_chars; i++)
 183            char_array[i] = new_char[i];
 184         char_array[num_chars] = '\0';
 185         delete [] new_char;
 186         }
 187      }
 188   else
 189      {
 190      cout << "num_chars = " << num_chars << "\n";
 191      cout << "Error in Stringc::delete routine.\n";
 192      cout << "   Bad range " << istart << " to " << iend;
 193      cout << "... Nothing will be deleted.\n";
 194      }
 195}
 196
 197//---------------------------- Public functions ------------------------------
 198//----------------------------------------------------------------------------
 199
 200void Stringc::print()
 201{
 202   cout << "\n<" << char_array << ">\n";
 203   cout << "Num_chars: " << num_chars << "\n";
 204   cout << "Chunk: " << chunk_size << "\n";
 205   cout << "Total_Size: " << total_size << "\n\n";
 206}
 207
 208//----------------------------------------------------------------------------
 209
 210double Stringc::convert_to_double()
 211{
 212   double data=0.0;
 213   data = atof(char_array);
 214   return data;
 215}
 216
 217//----------------------------------------------------------------------------
 218
 219int Stringc::count_words()
 220{
 221   int i = 0;
 222   int iword = 0;
 223   while ( i < num_chars )
 224      {
 225
 226//    Step through spaces
 227
 228      while ( i< num_chars &&
 229            (char_array[i] == ' ' || char_array[i] == '\t')) i++;
 230
 231//    Step through the word and increment the word counter, iword.
 232
 233      if ( i < num_chars )
 234         {
 235         while ( i < num_chars && char_array[i] != ' ' 
 236                               && char_array[i] != '\t') i++;
 237         iword++;
 238         }
 239      }
 240   return iword;
 241}
 242
 243//----------------------------------------------------------------------------
 244
 245Stringc Stringc::get_word(int iword)
 246{
 247   int i = 0;
 248   int iw = 0;
 249   int istart = 0;
 250   int iend = 0;
 251
 252// Find the start and end location of the desired iword'th word.
 253
 254   while ( i < num_chars && iw <= iword)
 255      {
 256
 257//    Step through spaces
 258
 259      while ( i< num_chars &&
 260            (char_array[i] == ' ' || char_array[i] == '\t')) i++;
 261
 262//    Step through a word and save its start and end location if it
 263//    is the desired iword.
 264
 265      if ( i < num_chars )
 266         {
 267         if ( iw == iword) istart = i;
 268         while ( i < num_chars && char_array[i] != ' ' 
 269                               && char_array[i] != '\t') 
 270            {
 271            if ( iw == iword) iend = i;
 272            i++;
 273            }
 274         iw++;
 275         }
 276      }
 277
 278// Extract the word string from the character array if iword exists.
 279
 280   if ( iword < iw && iword >= 0)
 281      {
 282      int word_size = iend-istart+1;
 283      Stringc sword(word_size);
 284      for ( i=0; i<word_size; i++)
 285         {
 286         sword[i] = char_array[istart+i];
 287         }
 288      sword[word_size] = '\0';
 289      return sword;
 290      }
 291   else
 292      {
 293      cout << "\nError in Stringc::get_word routine.\n";
 294      if ( iword < 0 ) 
 295         cout << "   Negative word index does not make sense.\n";
 296      else
 297         cout << "   Word index is greater than the number of words.\n";
 298      cout << "   Returning an empty string as word\n";
 299      Stringc sword(1);
 300      sword[0] = '\0';
 301      return sword;
 302      }
 303}
 304
 305//----------------------------------------------------------------------------
 306
 307void Stringc::delete_word(int iword)
 308{
 309   int i = 0;
 310   int iw = 0;
 311   int istart = 0;
 312   int iend = 0;
 313
 314// Find the start and end location of the desired iword word.
 315
 316   while ( i < num_chars && iw <= iword)
 317      {
 318
 319//    Step through spaces
 320
 321      while ( i< num_chars &&
 322            (char_array[i] == ' ' || char_array[i] == '\t')) i++;
 323
 324//    Step through a word and save its start and end location if it
 325//    is the desired iword.
 326
 327      if ( i < num_chars )
 328         {
 329         if ( iw == iword) istart = i;
 330         while ( i < num_chars && char_array[i] != ' ' 
 331                               && char_array[i] != '\t') 
 332            {
 333            if ( iw == iword) iend = i;
 334            i++;
 335            }
 336         iw++;
 337         }
 338      }
 339
 340// If iword exists delete it from the character array.
 341
 342   if ( iword < iw && iword >= 0)
 343      rdelete(istart,iend);
 344   else
 345      {
 346      cout << "Error in Stringc::delete_word routine.\n";
 347      if ( iword < 0 ) 
 348         cout << "   Negative word index does not make sense.\n";
 349      else
 350         cout << "   Word index is greater than the number of words.\n";
 351      }
 352}
 353
 354
 355//----------------------------------------------------------------------------
 356
 357int Stringc::count_lines()
 358{
 359   int i = 0;
 360   int iline = 0;
 361   while ( i < num_chars )
 362      {
 363
 364//    Step through empty lines
 365
 366      while ( i< num_chars &&
 367            (char_array[i] == '\n')) i++;
 368
 369//    Step through the lines and increment the line counter, iline.
 370
 371      if ( i < num_chars )
 372         {
 373         while ( i < num_chars && char_array[i] != '\n') i++;
 374         iline++;
 375         }
 376      }
 377   return iline;
 378}
 379
 380//----------------------------------------------------------------------------
 381
 382Stringc Stringc::get_line(int iline)
 383{
 384   int i = 0;
 385   int il = 0;
 386   int istart = 0;
 387   int iend = 0;
 388
 389// Find the start and end location of the desired iline'th line.
 390
 391   while ( i < num_chars && il <= iline)
 392      {
 393
 394//    Step through spaces
 395
 396      while ( i< num_chars && (char_array[i] == '\n')) i++;
 397
 398//    Step through a line and save its start and end location if it
 399//    is the desired iline.
 400
 401      if ( i < num_chars )
 402         {
 403         if ( il == iline) istart = i;
 404         while ( i < num_chars && char_array[i] != '\n' ) 
 405            {
 406            if ( il == iline) iend = i;
 407            i++;
 408            }
 409         il++;
 410         }
 411      }
 412
 413// Extract the line string from the character array if iline exists.
 414
 415   if ( iline < il && iline >= 0)
 416      {
 417      int line_size = iend-istart+1;
 418      Stringc sline(line_size);
 419      for ( i=0; i<line_size; i++)
 420         {
 421         sline[i] = char_array[istart+i];
 422         }
 423      sline[line_size] = '\0';
 424      return sline;
 425      }
 426   else
 427      {
 428      cout << "\nError in Stringc::get_line routine.\n";
 429      if ( iline < 0 ) 
 430         cout << "   Negative line index does not make sense.\n";
 431      else
 432         cout << "   Line index is greater than the number of lines.\n";
 433      cout << "   Returning an empty string as line\n";
 434      Stringc sline(1);
 435      sline[0] = '\0';
 436      return sline;
 437      }
 438}
 439
 440//----------------------------------------------------------------------------
 441
 442void Stringc::delete_line(int iline)
 443{
 444   int i = 0;
 445   int il = 0;
 446   int istart = 0;
 447   int iend = 0;
 448
 449// Find the start and end location of the desired iline line.
 450
 451   while ( i < num_chars && il <= iline)
 452      {
 453
 454//    Step through spaces
 455
 456      while ( i< num_chars && (char_array[i] == '\n')) i++;
 457
 458//    Step through a line and save its start and end location if it
 459//    is the desired iline.
 460
 461      if ( i < num_chars )
 462         {
 463         if ( il == iline) istart = i;
 464         while ( i < num_chars && char_array[i] != '\n') 
 465            {
 466            if ( il == iline) iend = i;
 467            i++;
 468            }
 469         il++;
 470         }
 471      }
 472
 473// If iline exists delete it from the character array.
 474
 475   if ( iline < il && iline >= 0)
 476      rdelete(istart,iend);
 477   else
 478      {
 479      cout << "Error in Stringc::delete_line routine.\n";
 480      if ( iline< 0 ) 
 481         cout << "   Negative line index does not make sense.\n";
 482      else
 483         cout << "   Line index is greater than the number of lines.\n";
 484      }
 485}
 486
 487//----------------------------------------------------------------------------
 488
 489void Stringc::get_rid_of_comments()
 490{
 491   int iend=-1;
 492   int i = 0;
 493
 494// Find location of comment
 495
 496   while ( iend < 0 && i < num_chars-1 ) 
 497      {
 498      if ((char_array[i] == '/' ) && (char_array[i+1] == '/'))
 499         iend = i;
 500      i++;
 501      }
 502
 503// Delete comment.
 504
 505   if ( iend >= 0 )
 506      rdelete(iend,num_chars-1);
 507}
 508
 509//----------------------------------------------------------------------------
 510
 511void Stringc::concatenate(const char ch)
 512{
 513    append(ch);
 514}
 515
 516//----------------------------------------------------------------------------
 517
 518void Stringc::concatenate(const char *cstring)
 519{
 520    for(int i=0; i < (int)strlen(cstring); i++)
 521       append(cstring[i]);
 522}
 523
 524//----------------------------------------------------------------------------
 525
 526void Stringc::concatenate(const Stringc cstring)
 527{
 528    for(int i=0; i<cstring.num_chars; i++)
 529       append(cstring[i]);
 530}
 531
 532//----------------------------------------------------------------------------
 533
 534void Stringc::underscore_to_space()
 535{
 536    for(int i=0; i<num_chars; i++)
 537       if (char_array[i] == '_') char_array[i] = ' ';
 538}
 539
 540//----------------------------------------------------------------------------
 541
 542void Stringc::space_to_underscore()
 543{
 544    for(int i=0; i<num_chars; i++)
 545       if (char_array[i] == ' ') char_array[i] = '_';
 546}
 547
 548//----------------------------------------------------------------------------
 549
 550void Stringc::change_from_to( const char f, const char t)
 551{
 552    for(int i=0; i<num_chars; i++)
 553       if (char_array[i] == f) char_array[i] = t;
 554}
 555
 556
 557//----------------------------------------------------------------------------
 558
 559int Stringc::search_for_substring( const char *substring )
 560   {
 561
 562// Use strstr to find out if substring is in char_array.
 563
 564   char *character = strstr( char_array, substring );
 565
 566// if a match was found, return the element position of the match
 567
 568   if ( character != NULL )
 569      {
 570      int i = 0;
 571      while ( &char_array[i] != character ) i++;
 572         return i;
 573      }
 574
 575// if no match was found, return minus 1
 576
 577   return -1;
 578   }
 579
 580//----------------------------------------------------------------------------
 581
 582void Stringc::insert_string_at (int position, const Stringc cstring)
 583{
 584
 585// check to see if position to insert string at makes sense
 586
 587   if (position > num_chars || position < 0)
 588      {
 589      cout << "Error in Stringc::insert_string_at routine.\n";
 590      cout << "  Bad position = " << position << "\n";
 591      cout << "  Postion should be >= 0 and < " << num_chars+1 <<"\n";
 592      return;
 593      }
 594   int len_char = cstring.num_chars;
 595   int new_size = num_chars+len_char;
 596   int num_save = num_chars;
 597   int i = 0;
 598
 599// If more room is needed in the char_array for the new string, 
 600// append spaces.
 601
 602   for ( i=0; i<len_char; i++) 
 603      append(' ');
 604
 605// Shift characters after position to make room for inserted string
 606
 607   for (i=0; i<num_save-position; i++) {
 608      char_array[new_size-i-1] = char_array[num_save-i-1];
 609      }
 610
 611// Insert string
 612
 613   for (i=position; i<position+len_char; i++)
 614      char_array[i] = cstring[i-position];
 615   num_chars = new_size;
 616   char_array[num_chars] = '\0';
 617}    
 618
 619//----------------------------------------------------------------------------
 620
 621void Stringc::insert_string_at (int position, const char *cstring)
 622{
 623
 624// check to see if position to insert string at makes sense
 625
 626   if (position > num_chars || position < 0)
 627      {
 628      cout << "Error in Stringc::insert_string_at routine.\n";
 629      cout << "  Bad position = " << position << "\n";
 630      cout << "  Postion should be >= 0 and < " << num_chars+1 <<"\n";
 631      return;
 632      }
 633   int len_char = strlen(cstring);
 634   int new_size = num_chars+len_char;
 635   int num_save = num_chars;
 636   int i = 0;
 637// Make room for character string.
 638
 639   for ( i=0; i<len_char; i++) 
 640      append(' ');
 641
 642// Shift characters after position to make room for inserted string
 643
 644   for (i=0; i<num_save-position; i++) {
 645        char_array[new_size-i-1] = char_array[num_save-i-1];
 646      }
 647
 648// Insert string
 649
 650   for (i=position; i<position+len_char; i++)
 651        char_array[i] = cstring[i-position];
 652//   num_chars = new_size;
 653//   char_array[num_chars] = '\0';
 654
 655}
 656
 657//----------------------------------------------------------------------------
 658
 659void Stringc::insert_string_at (int position, const char character)
 660{
 661   int num_save = num_chars;
 662   int new_size = num_chars+1;
 663
 664// Add room for a character.
 665
 666   append(' ');
 667
 668// Shift characters after position to make room for inserted string
 669
 670   for (int i=0; i<num_save-position; i++)
 671      char_array[new_size-i-1] = char_array[num_save-i-1];
 672
 673// Insert character
 674
 675   char_array[position] = character;
 676   num_chars = new_size;
 677   char_array[num_chars] = '\0';
 678}
 679
 680//----------------------------------------------------------------------------
 681
 682int Stringc::search_for_substring( int istart, char character )
 683{
 684
 685// search for the character
 686
 687   for ( int i = istart; i < num_chars; i++ )
 688      {
 689      if ( char_array[i] == character )
 690         {
 691         return i;
 692         }
 693      }
 694
 695// if no match was found, return minus 1
 696
 697   return -1;
 698}
 699
 700//----------------------------------------------------------------------------
 701
 702int Stringc::search_for_substring( char character )
 703{
 704	return search_for_substring( 0, character );
 705}
 706
 707//----------------------------------------------------------------------------
 708
 709int Stringc::matchwild(Stringc wildcardstring)
 710{
 711
 712	char *wild = wildcardstring();
 713	char *string = get_char_star();
 714
 715	char *cp, *mp;
 716	
 717	while ((*string) && (*wild != '*')) {
 718		if ((*wild != *string) && (*wild != '?')) {
 719			return 0;
 720		}
 721		wild++;
 722		string++;
 723	}
 724		
 725	while (*string) {
 726		if (*wild == '*') {
 727			if (!*++wild) {
 728				return 1;
 729			}
 730			mp = wild;
 731			cp = string+1;
 732		} else if ((*wild == *string) || (*wild == '?')) {
 733			wild++;
 734			string++;
 735		} else {
 736			wild = mp;
 737			string = cp++;
 738		}
 739	}
 740		
 741	while (*wild == '*') {
 742		wild++;
 743	}
 744	return !*wild;
 745
 746}
 747
 748//----------------------------------------------------------------------------
 749
 750void Stringc::delete_range(int istart, int iend)
 751{
 752   rdelete(istart,iend);
 753}
 754
 755//----------------------------------------------------------------------------
 756
 757Stringc Stringc::get_range(int istart, int iend)
 758{
 759   int str_len = iend-istart+2;
 760   char *new_char = new char[str_len];
 761   for (int i=istart; i<=iend; i++) 
 762      new_char[i-istart] = char_array[i];
 763   new_char[iend+1-istart] = '\0';
 764   Stringc new_string(new_char);
 765   delete [] new_char;
 766   return new_string;
 767}
 768
 769//----------------------------------------------------------------------------
 770
 771void Stringc::overwrite_at_position(int position, const char *cstring)
 772{
 773   int len_char = strlen(cstring);
 774   if (position < 0)
 775      {
 776      cout << "Error in Stringc::overwrite_at_position routine.\n";
 777      cout << "   String: " << char_array;
 778      cout << " Overwrite string: " << cstring << "\n";
 779      cout << "   Position cannot be negative it can run from 0 to ";
 780      cout << num_chars-len_char << "\n";
 781      }
 782   else if (position+len_char > num_chars )
 783      {
 784      cout << "Error in Stringc::overwrite_at_position routine.\n";
 785      cout << "   String: " << char_array;
 786      cout << "  Overwrite string: " << cstring << "\n";
 787      cout << "   Position, " << position;
 788      cout << ", is out of range it can run from 0 to ";
 789      cout << num_chars-len_char << "\n"; 
 790      }     
 791   else
 792      for (int i=0; i < len_char; i++)
 793         char_array[i+position] = cstring[i];
 794}
 795
 796//----------------------------------------------------------------------------
 797
 798void Stringc::remove_leading_blanks()
 799{
 800   if ( num_chars > 0 )
 801      {
 802      int i = 0;
 803      while ( (char_array[i] == ' ' || char_array[i] == '\t') && i<num_chars)
 804         i++;
 805      int iend = i; 
 806      if (iend != 0 ) rdelete(0,iend-1);
 807      }
 808}
 809
 810//----------------------------------------------------------------------------
 811
 812void Stringc::remove_trailing_blanks()
 813{
 814   if ( num_chars > 0 )
 815      {
 816      int i=num_chars-1;
 817      while ( (char_array[i] == ' ' || char_array[i] == '\t') && i>=0 ) i--;
 818      int istart = i+1;
 819      if ( istart != num_chars ) rdelete(istart,num_chars-1);
 820      }
 821}
 822
 823//----------------------------------------------------------------------------
 824
 825void Stringc::remove_leading(char c)
 826{
 827   if ( num_chars > 0 )
 828      {
 829      int i = 0;
 830      while ( (char_array[i] == c) && i<num_chars)
 831         i++;
 832      int iend = i; 
 833      if (iend != 0 ) rdelete(0,iend-1);
 834      }
 835}
 836
 837//----------------------------------------------------------------------------
 838
 839void Stringc::remove_trailing(char c)
 840{
 841   if ( num_chars > 0 )
 842      {
 843      int i=num_chars-1;
 844      while ( (char_array[i] == c) && i>=0 ) i--;
 845      int istart = i+1;
 846      if ( istart != num_chars ) rdelete(istart,num_chars-1);
 847      }
 848}
 849//----------------------------------------------------------------------------
 850
 851int Stringc::count_substrings(const char *substring)
 852{
 853   int j = 0;
 854   int len_sub = strlen(substring);
 855   int icount = 0;
 856   for (int i=0; i <= num_chars-len_sub; i++)
 857      {
 858      j = 0;
 859      int matches = 1;
 860      while ( j < len_sub && matches )
 861         {
 862         if ( char_array[i+j] != substring[j] ) matches = 0;
 863         j++;
 864         } 
 865      if ( matches ) icount++; 
 866      }
 867   return icount; 
 868}
 869
 870//----------------------------------------------------------------------------
 871
 872void Stringc::remove_substring(const char *substring, int istring)
 873{
 874   int j = 0;
 875   int len_sub = strlen(substring);
 876   int icount = 0;
 877   int i=0;
 878   int notfound = 1;
 879   while (notfound && i<num_chars)
 880      {
 881      j = 0;
 882      int matches = 1;
 883      while ( j < len_sub && matches )
 884         {
 885         if ( char_array[i+j] != substring[j] ) matches = 0;
 886         j++;
 887         } 
 888      if ( matches ) icount++;
 889      if ( matches && icount == istring) 
 890         {
 891         rdelete(i,i+len_sub-1);
 892         notfound = 0;
 893         }
 894      i++;
 895      }
 896}
 897
 898//----------------------------------------------------------------------------
 899
 900void Stringc::remove_all_substrings(const char *substring)
 901{
 902   int j = 0;
 903   int len_sub = strlen(substring);
 904   int i=0;
 905   while (i < num_chars-len_sub)
 906      {
 907      j = 0;
 908      int matches = 1;
 909      while ( j < len_sub && matches )
 910         {
 911         if ( char_array[i+j] != substring[j] ) matches = 0;
 912         j++;
 913         } 
 914      if ( matches ) rdelete(i,i+len_sub-1);
 915      i++;
 916      }
 917}
 918
 919//----------------------------------------------------------------------------
 920
 921void Stringc::remove_substring(char character, int ichar)
 922{
 923   int j = 0;
 924   int icount = 0;
 925   int i=0;
 926   int notfound = 1;
 927   while (notfound && i<num_chars)
 928      {
 929      j = 0;
 930      int matches = 1;
 931      while ( j < 1 && matches )
 932         {
 933         if ( char_array[i+j] != character ) matches = 0;
 934         j++;
 935         } 
 936      if ( matches ) icount++;
 937      if ( matches && icount == ichar) 
 938         {
 939         rdelete(i,i);
 940         notfound = 0;
 941         }
 942      i++;
 943      }
 944}
 945
 946//----------------------------------------------------------------------------
 947
 948void Stringc::remove_all_substrings(char character)
 949{
 950   int j = 0;
 951   int i=0;
 952   while (i < num_chars)
 953      {
 954      j = 0;
 955      int matches = 1;
 956      while ( j < 1 && matches )
 957         {
 958         if ( char_array[i+j] != character ) matches = 0;
 959         j++;
 960         } 
 961      if ( matches ) rdelete(i,i);
 962      i++;
 963      }
 964}
 965
 966//----------------------------------------------------------------------------
 967
 968int Stringc::is_double( double* ret )
 969{
 970	for ( int i = 0 ; i < num_chars ; i++ )
 971	{
 972		if ( char_array[i] == '+' || char_array[i] == '-' || char_array[i] == '.' || 
 973			 (( char_array[i] >= '0') && ( char_array[i] <= '9' )) )
 974			continue;
 975		else
 976			return 0;
 977	}
 978
 979	*ret = atof( get_char_star() );
 980	return 1;
 981			
 982}
 983
 984//----------------------------- OPERATORS ------------------------------------
 985//----------------------------------------------------------------------------
 986
 987Stringc& Stringc::operator=( const char ch)
 988   {
 989   (*this).clear_space();
 990   (*this).num_chars = 1;
 991   (*this).chunk_size = STRINGC_CHUNK_SIZE;
 992   (*this).make_space();
 993   (*this).char_array[0] = ch;
 994   (*this).char_array[1] = '\0';
 995   return *this;
 996   }
 997
 998//----------------------------------------------------------------------------
 999
1000Stringc& Stringc::operator=( const Stringc& cstring )
1001   {
1002   (*this).clear_space();
1003   (*this).num_chars = cstring.num_chars;
1004   (*this).chunk_size = cstring.chunk_size;
1005   (*this).make_space();
1006   for (int i=0; i<=cstring.num_chars; i++)
1007      (*this).char_array[i] = cstring.char_array[i];
1008(*this).char_array[num_chars] = '\0';
1009
1010   return *this;
1011   }
1012
1013//----------------------------------------------------------------------------
1014
1015Stringc& Stringc::operator=( const char *cstring )
1016   {
1017   (*this).clear_space();
1018   (*this).num_chars = strlen(cstring);
1019   (*this).chunk_size = STRINGC_CHUNK_SIZE;
1020   (*this).make_space();
1021   for (int i=0; i < (int)strlen(cstring); i++)
1022      (*this).char_array[i] = cstring[i];
1023   (*this)[num_chars] = '\0';
1024   return *this;
1025   }
1026
1027//----------------------------------------------------------------------------
1028
1029int Stringc::operator==( const Stringc& cstring ) const
1030   {
1031   if ( strcmp( char_array, cstring.char_array ) )
1032      return FALSE;
1033   else 
1034      return TRUE;
1035   }
1036
1037//----------------------------------------------------------------------------
1038
1039int Stringc::operator==( const char *cstring ) const
1040   {
1041   if ( strcmp( char_array, cstring ) )
1042      return FALSE;
1043   else 
1044      return TRUE;
1045   }
1046
1047
1048//----------------------------------------------------------------------------
1049
1050int Stringc::operator!=( const Stringc& cstring ) const
1051   {
1052   if ( strcmp( char_array, cstring.char_array ) )
1053      return TRUE;
1054   else 
1055      return FALSE;
1056   }
1057
1058//----------------------------------------------------------------------------
1059
1060int Stringc::operator!=( const char *cstring ) const
1061   {
1062   if ( strcmp( char_array, cstring ) )
1063      return TRUE;
1064   else 
1065      return FALSE;
1066   }
1067
1068//----------------------------------------------------------------------------
1069
1070//ostream& operator<<( ostream &os, const Stringc &stringc )
1071//   {
1072//   os << stringc.char_array;
1073//   return os;
1074//   }