Bsoft  2.1.0
Bernard's software package
Bstring.cpp
Go to the documentation of this file.
1 
9 #include <stdio.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include "Bstring.h"
13 #include "utilities.h"
14 
15 // Definition of the global variables
16 extern int verbose; // Level of output to the screen
17 
23 {
24  data = NULL;
25  long len = s.length();
26  if ( len ) {
27  data = new char[len + 1];
28  ::strncpy(data, s.data, len);
29  data[len] = 0;
30  }
31  next = NULL;
32 }
33 
34 Bstring::Bstring(const string& s)
35 {
36  data = NULL;
37  long len = s.length();
38  if ( len ) {
39  data = new char[len + 1];
40  ::strncpy(data, s.data(), len);
41  data[len] = 0;
42  }
43  next = NULL;
44 }
45 
46 Bstring::Bstring(const Bstring& s, long start, long len)
47 {
48  data = NULL;
49  if ( start < 0 ) start = 0;
50  long end = start + len - 1;
51  long inlen = s.length();
52  if ( end >= inlen ) end = inlen - 1;
53  if ( start > end ) start = end;
54  len = end - start + 1;
55  if ( len ) {
56  data = new char[len + 1];
57  ::strncpy(data, &s.data[start], len);
58  data[len] = 0;
59  }
60  next = NULL;
61 }
62 
63 Bstring::Bstring(const char* c)
64 {
65  data = NULL;
66  if ( c ) {
67  long len = ::strlen(c);
68  if ( len ) {
69  data = new char[len + 1];
70  ::strncpy(data, c, len);
71  data[len] = 0;
72  }
73  }
74  next = NULL;
75 }
76 
77 Bstring::Bstring(const char* c, long start, long len)
78 {
79  data = NULL;
80  if ( c ) {
81  if ( start < 0 ) start = 0;
82  long end = start + len - 1;
83  long inlen = ::strlen(c);
84  if ( end >= inlen ) end = inlen - 1;
85  if ( start > end ) start = end;
86  len = end - start + 1;
87  if ( len ) {
88  data = new char[len + 1];
89  ::strncpy(data, c+start, len);
90  data[len] = 0;
91  }
92  }
93  next = NULL;
94 }
95 
96 Bstring::Bstring(const char c, long size)
97 {
98  data = NULL;
99  if ( size ) {
100 // cout << "fill size = " << size << endl;
101  data = new char[size + 1];
102  for ( long i=0; i<size; i++ ) data[i] = c;
103  data[size] = 0;
104  }
105  next = NULL;
106 }
107 
109 {
110  if ( this == &s ) return *this;
111  if ( data ) delete[] data; // Delete existing string
112  data = NULL;
113  long len = s.length();
114  if ( len ) {
115  data = new char[len + 1];
116  ::strncpy(data, s.data, len); // Copy new string
117  data[len] = 0;
118  }
119  return *this;
120 }
121 
122 Bstring& Bstring::operator=(const string& s)
123 {
124  if ( data ) delete[] data; // Delete existing string
125  data = NULL;
126  long len = s.length();
127  if ( len ) {
128  data = new char[len + 1];
129  ::strncpy(data, s.c_str(), len); // Copy new string
130  data[len] = 0;
131  }
132  return *this;
133 }
134 
136 {
137  if ( data ) delete[] data; // Delete existing string
138  data = NULL;
139  long len(0);
140  if ( c ) len = ::strlen(c);
141  if ( len ) {
142  data = new char[len + 1];
143  ::strncpy(data, c, len);
144  data[len] = 0;
145  }
146  return *this;
147 }
148 
150 {
151  *this = *this + s;
152  return *this;
153 }
154 
156 {
157  Bstring ns;
158  long l1 = length();
159  long l2 = s.length();
160  long len = l1 + l2 + 1;
161  ns.data = new char[len];
162  memset(ns.data, 0, len);
163  char* ptr = ns.data;
164  if ( data ) ptr = ::stpncpy(ns.data, data, l1);
165  if ( s.data ) ::strncpy(ptr, s.data, l2);
166  ns.data[l1+l2] = 0;
167  return ns;
168 }
169 
171 {
172  Bstring ns;
173  long l1 = length();
174  long l2 = s.length();
175  long len = l1 + l2 + 1;
176  ns.data = new char[len];
177  memset(ns.data, 0, len);
178  char* ptr = ns.data;
179  if ( data ) ptr = ::stpncpy(ns.data, data, l1);
180  if ( s.data ) ::strncpy(ptr, s.data, l2);
181  ns.data[l1+l2] = 0;
182  return ns;
183 }
184 
186 {
187  *this = *this + c;
188  return *this;
189 }
190 
192 {
193  Bstring ns;
194  long len = length();
195  long nlen = len + 2;
196  ns.data = new char[nlen];
197  memset(ns.data, 0, nlen);
198  if ( data ) ::strcpy(ns.data, data);
199  ns.data[len] = c;
200  return ns;
201 }
202 
204 {
205  return ( compare(s) == 0 );
206 }
207 
209 {
210  return ( compare(s) != 0 );
211 }
212 
214 {
215  return ( compare(s) > 0 );
216 }
217 
219 {
220  return ( compare(s) < 0 );
221 }
222 
224 {
225  return ( compare(s) >= 0 );
226 }
227 
229 {
230  return ( compare(s) <= 0 );
231 }
232 
234 {
235  Bstring ns(*this, n, length() - n);
236  ns += substr(0, n);
237  return ns;
238 }
239 
241 {
242  Bstring ns(*this, length() - n, n);
243  ns += substr(0, length() - n);
244  return ns;
245 }
246 
247 char& Bstring::operator[](long i)
248 {
249  if ( !data ) {
250  cerr << "Error in Bstring::operator[]: String length = 0!" << endl;
251  bexit(-1);
252  }
253  long len = length();
254  if ( i < 0 ) {
255  if ( len ) while ( i < 0 ) i += len;
256  else i = 0;
257  } else {
258  while ( i >= len ) i -= len;
259  }
260  return data[i];
261 }
262 
263 long Bstring::length() const
264 {
265  if ( !data ) return 0;
266  return ::strlen(data);
267 }
268 
269 long Bstring::count(const char c)
270 {
271  long n(0);
272  if ( data )
273  for ( char* s = data; *s; s++ ) if ( *s == c ) n++;
274  return n;
275 }
276 
277 long Bstring::compare(const Bstring& s)
278 {
279  if ( !data && !s.data ) return 0;
280  if ( !data ) return -1;
281  if ( !s.data ) return 1;
282  return ::strcmp(data, s.data);
283 }
284 
286 {
287  if ( !data || !s.data ) {
288  cerr << "Error in Bstring::compare_value! (data = " << &data << " s.data = " << &(s.data) << endl;
289  bexit(-1);
290  }
291  long ld = length() - s.length();
292  if ( ld ) return ld;
293  return ::strcmp(data, s.data);
294 }
295 
297 {
298  long n(length());
299  if ( data && s.data )
300  for ( n=0; data[n] && s.data[n] && data[n] == s.data[n]; ++n ) ;
301  return substr(0, n);
302 }
303 
304 void Bstring::fill(const char c)
305 {
306  if ( data )
307  for ( char* s = data; *s; s++ ) *s = c;
308 }
309 
310 void Bstring::place(long i, const Bstring& s)
311 {
312  long len(s.length());
313  if ( data ) strncpy(&data[i], s.data, len);
314 }
315 
317 {
318  Bstring ns(*this);
319  char *s, *sn;
320  for ( s = data, sn = ns.data; s && *s; s++, sn++ ) *sn = tolower(*s);
321  return ns;
322 }
323 
325 {
326  Bstring ns(*this);
327  char *s, *sn;
328  for ( s = data, sn = ns.data; *s; s++, sn++ ) *sn = toupper(*s);
329  return ns;
330 }
331 
332 Bstring Bstring::substr(long start, long len)
333 {
334  long copylen = length() - start;
335  if ( copylen > len ) copylen = len;
336  Bstring ns(*this, start, copylen);
337  return ns;
338 }
339 
341 {
342  long i, j;
343  for ( i=j=0; data[i]; i++ ) if ( !isspace(data[i]) ) j++;
344  Bstring ns('\0', j);
345  for ( i=j=0; data[i]; i++ ) if ( !isspace(data[i]) ) ns.data[j++] = data[i];
346  return ns;
347 }
348 
350 {
351  long i, j;
352  for ( i=j=0; isspace(data[i]); i++ ) j++;
353  Bstring ns(*this, j, length());
354  return ns;
355 }
356 
358 {
359  long i, j;
360  for ( i=j=0; data[i]; i++ ) if ( isalnum(data[i]) ) j++;
361  Bstring ns('\0', j);
362  for ( i=j=0; data[i]; i++ ) if ( isalnum(data[i]) ) ns.data[j++] = data[i];
363  return ns;
364 }
365 
367 {
368  long copylen = length();
369  if ( copylen > len ) copylen = len;
370  Bstring ns(' ', copylen);
371  strncpy(ns.data, data, copylen);
372  return ns;
373 }
374 
376 {
377  long copylen = length();
378  if ( copylen > len ) copylen = len;
379  long start = len - copylen;
380  Bstring ns(' ', len);
381  strncpy(ns.data + start, data, copylen);
382  return ns;
383 }
384 
385 /* Return the string before the first character.
386  If the character is not in the string, return the whole string.
387  If the character is the first in the string, return an empty string.
388 */
390 {
391  Bstring ns;
392  long i, len = length();
393  for ( i=0; i<len && data[i] != c; i++ ) ;
394  if ( i > 0 ) ns = Bstring(*this, 0, i);
395  return ns;
396 }
397 
398 /* Return the string after the first character.
399  If the character is not in the string, return an empty string.
400  If the character is the last in the string, return an empty string.
401 */
403 {
404  Bstring ns;
405  long i, len = length(), j = len;
406  for ( i=0; i<len && data[i] != c; i++ ) ;
407  if ( i < len ) {
408  i++;
409  j = len - i;
410  ns = Bstring(*this, i, j);
411  }
412 // } else i = 0;
413 // if ( j > 0 ) ns = Bstring(*this, i, j);
414  return ns;
415 }
416 
417 /* Return the string before the last character.
418  If the character is not in the string, return the whole string.
419  If the character is the first in the string, return an empty string.
420 */
422 {
423  Bstring ns;
424  long i, j = -1;
425  char* s;
426  for ( i=0, s = data; *s; i++, s++ ) if ( *s == c ) j = i;
427  if ( j < 0 ) j = i;
428  if ( j > 0 ) ns = Bstring(*this, 0, j);
429  return ns;
430 }
431 
432 /* Return the string after the last character.
433  If the character is not in the string, return an empty string.
434  If the character is the last in the string, return an empty string.
435 */
437 {
438  Bstring ns;
439  long i, j = -1;
440  char* s;
441  for ( i=0, s = data; *s; i++, s++ ) if ( *s == c ) j = i;
442  if ( j > -1 ) {
443  j++;
444  i -= j;
445  if ( i > 0 ) ns = Bstring(*this, j, i);
446  }
447  return ns;
448 }
449 
450 Bstring Bstring::within(char c1, char c2)
451 {
452  Bstring ns;
453  long i, j;
454  char* s;
455  for ( i=0, s = data; *s && *s != c1; i++, s++ ) ;
456  i++;
457  if ( *s ) s++;
458  if ( *s ) {
459  for ( j=0; *s && *s != c2; j++, s++ ) ;
460  if ( *s && j > 0 ) ns = Bstring(*this, i, j);
461  }
462  return ns;
463 }
464 
465 Bstring Bstring::replace(char cold, char cnew)
466 {
467  Bstring ns(*this);
468  for ( char* s = ns.data; *s; s++ )
469  if ( *s == cold ) *s = cnew;
470  return ns;
471 }
472 
474 {
475  long nc = count(c);
476  if ( nc < 1 ) return *this;
477  long n = length() - nc;
478  Bstring ns(' ', n);
479  char *s, *sn;
480  for ( s = data, sn = ns.data; *s; s++ )
481  if ( *s != c ) *(sn++) = *s;
482  return ns;
483 }
484 
485 Bstring Bstring::swap(const long i, const long j)
486 {
487  Bstring ns(*this);
488  ns.data[i] = data[j];
489  ns.data[j] = data[i];
490  return ns;
491 }
492 
493 Bstring Bstring::erase(const long i)
494 {
495  long j, n = length() - 1;
496  Bstring ns(' ', n);
497  char *s, *sn;
498  for ( j=0, s = data, sn = ns.data; *s; s++, j++ )
499  if ( j != i ) *(sn++) = *s;
500  return ns;
501 }
502 
504 {
505  long nlen = length() - n;
506  Bstring ns(' ', nlen);
507  char *s, *sn;
508  long i;
509  for ( i=0, s = data, sn = ns.data; i<nlen; i++ )
510  *(sn++) = *(s++);
511  return ns;
512 }
513 
514 /* Removes both the leading path and extension from a filename string.
515 */
517 {
518  Bstring ns(*this);
519  if ( ns.contains("/") ) ns = ns.post_rev('/');
520  return ns.pre_rev('.');
521 }
522 
524 {
525  Bstring ns = pre(',');
526  if ( ns.find("#", 0) > -1 )
527  ns = "raw";
528  else if ( ns.find(":", 0) > -1 )
529  ns = ns.post(':');
530  else
531  ns = ns.post_rev('.');
532  return ns.lower();
533 }
534 
536 {
537  int i;
538  Bstring s(*this);
539  Bstring cs(*this);
540  for ( i=0; i<s.length(); i+=n ) {
541  s = s << n;
542  if ( cs > s ) cs = s;
543  }
544  return cs;
545 }
546 
548 {
549  if ( !data ) return 0;
550  return strtol(data, NULL, 10);
551 }
552 
554 {
555  if ( !data ) return 0;
556  return strtod(data, NULL);
557 }
558 
559 /* The offset of a search character is returned if found, otherwise a negative value is returned */
560 long Bstring::index(const char c, long start)
561 {
562  long offset;
563  char* aptr = &data[start];
564  for ( offset = start; *aptr && *aptr != c; aptr++, offset++ ) ;
565  if ( *aptr != c ) offset = -1;
566  return offset;
567 }
568 
569 /* The offset of a search string is returned if found, otherwise a negative value is returned */
570 long Bstring::find(const Bstring& s, long start)
571 {
572  long len = s.length();
573  long offset;
574  char* aptr = &data[start];
575  for ( offset = start; *aptr; aptr++, offset++ )
576  if ( ::strncmp(s.data, aptr, len) == 0 ) break;
577  if ( *aptr == 0 ) offset = -1;
578  return offset;
579 }
580 
581 /* The offset of a search string is returned if found, otherwise a negative value is returned */
582 long Bstring::rfind(const Bstring& s, long start)
583 {
584  long i, len = s.length();
585  long offset = -1;
586  char* aptr = &data[start];
587  for ( i = start; *aptr; aptr++, i++ )
588  if ( ::strncmp(s.data, aptr, len) == 0 ) offset = i;
589  return offset;
590 }
591 
593 {
594  if ( !data ) return 0;
595  return strstr(data, s.data) != NULL;
596 }
597 
598 Bstring Bstring::insert(long pos, const Bstring& s)
599 {
600  Bstring ns = substr(0, pos);
601  Bstring ne = substr(pos, length() - pos);
602  return ns + s + ne;
603 }
604 
606 {
607  if ( !data ) return NULL;
608  long len = length();
609  if ( len < 1 ) return NULL;
610  long i;
611  Bstring tstr;
612  Bstring* list = NULL;
613  Bstring* astring = NULL;
614  char* sptr = data;
615  char* aptr = data;
616  for ( i=0; i<=len; i++, aptr++ ) {
617  if ( isspace(*sptr) ) sptr++;
618  else if ( *aptr==0 || isspace(*aptr) ) {
619  tstr = substr(sptr - data, aptr - sptr);
620  if ( tstr.length() ) {
621  astring = string_add(&astring, tstr);
622  if ( !list ) list = astring;
623  sptr = aptr;
624  }
625  }
626  }
627  return list;
628 }
629 
631 {
632  long dlen = delim.length();
633  if ( dlen < 1 ) return split();
634  long len = length();
635  if ( len < 1 ) return NULL;
636  long i;
637  Bstring tstr;
638  Bstring* list = NULL;
639  Bstring* astring = NULL;
640  char* sptr = data;
641  char* aptr = data;
642  for ( i=0; i<=len; i++, aptr++ ) {
643  if ( *aptr==0 || ::strncmp(aptr, delim.data, dlen) == 0 ) {
644  tstr = substr(sptr - data, aptr - sptr);
645  if ( tstr.length() ) {
646  astring = string_add(&astring, tstr);
647  if ( !list ) list = astring;
648  sptr = aptr + dlen;
649  aptr += dlen - 1;
650  i += dlen - 1;
651  }
652  }
653  }
654  return list;
655 }
656 
657 vector<long> Bstring::split_into_integers(const Bstring& delim)
658 {
659  vector<long> array;
660 
661  Bstring* list = split(delim);
662  if ( !list ) return array;
663 
664  Bstring* astring = NULL;
665  for ( astring=list; astring; astring=astring->next )
666  array.push_back(astring->integer());
667 
668  string_kill(list);
669 
670  return array;
671 }
672 
673 vector<double> Bstring::split_into_doubles(const Bstring& delim)
674 {
675  vector<double> array;
676 
677  Bstring* list = split(delim);
678  if ( !list ) return array;
679 
680  Bstring* astring = NULL;
681  for ( astring=list; astring; astring=astring->next )
682  array.push_back(astring->real());
683 
684  string_kill(list);
685 
686  return array;
687 }
688 
689 Bstring operator+(const char* c, const Bstring& s)
690 {
691  Bstring ns(c);
692  return ns += s;
693 }
694 
695 istream& operator>>(istream& input, Bstring& s) {
696  string str;
697  input >> str;
698  s = str;
699  return input;
700 }
701 
702 ostream& operator<<(ostream& output, Bstring& s) {
703  if ( s.length() ) output << left << s.c_str();
704  return output;
705 }
706 
713 Bstring* string_add(Bstring** list, const char* string)
714 {
715  Bstring this_string(string);
716  return string_add(list, this_string);
717 }
718 
720 {
721  Bstring* this_string = *list;
722 
723  if ( string.empty() ) return this_string;
724 
725  Bstring* new_string = new Bstring;
726 
727  *new_string = string;
728 
729  if ( !this_string )
730  *list = new_string;
731  else {
732  while ( this_string->next ) this_string = this_string->next;
733  this_string->next = new_string;
734  }
735 
736  if ( verbose & VERB_DEBUG )
737  cout << "DEBUG string_add: " << *new_string << " (" << new_string->length() << ")" << endl;
738 
739  return new_string;
740 }
741 
748 {
749  long i, len(0);
750  Bstring* str;
751 
752  for ( str = list; str; str = str->next )
753  len += str->length();
754 
755  Bstring cat = Bstring(' ', len);
756 
757  for ( i=0, str = list; str && i<len; i+=str->length(), str = str->next )
758  cat.place(i, *str);
759 
760  return cat;
761 }
762 
769 {
770  if ( !list ) return 0;
771 
772  Bstring *s, *s2;
773 
774  for ( s = list; s; ) {
775  s2 = s->next;
776 // *s = 0;
777  delete s;
778  s = s2;
779  }
780 
781  return 0;
782 }
783 
796 {
797  Bstring path;
798 
799  if ( access(filename.c_str(), R_OK) == 0 )
800  return filename;
801 
802  if ( getenv("BPARAM") ) {
803  path = getenv("BPARAM");
804  if ( path[-1] != ']' && path[-1] != '/')
805  path += "/";
806  } else
807  path = "/usr/local/bsoft/parameters/";
808  path += filename;
809 
810  if ( verbose & VERB_DEBUG )
811  cout << "DEBUG parameter_file_path: " << path << endl;
812 
813  return path;
814 }
815 
822 int QsortSmallToLargeString(const void *x, const void *y)
823 {
824  Bstring* s1 = (Bstring*) x;
825  Bstring* s2 = (Bstring*) y;
826  if( *s1 < *s2 ) return -1;
827  else return 1;
828 }
829 
836 int QsortLargeToSmallString(const void *x, const void *y)
837 {
838  Bstring* s1 = (Bstring*) x;
839  Bstring* s2 = (Bstring*) y;
840  if( *s1 > *s2 ) return -1;
841  else return 1;
842 }
843 
850 int QsortSmallToLargeStringValue(const void *x, const void *y)
851 {
852  Bstring* s1 = (Bstring*) x;
853  Bstring* s2 = (Bstring*) y;
854  if( s1->compare_value(*s2) < 0 ) return -1;
855  else return 1;
856 }
857 
864 int QsortLargeToSmallStringValue(const void *x, const void *y)
865 {
866  Bstring* s1 = (Bstring*) x;
867  Bstring* s2 = (Bstring*) y;
868  if( s1->compare_value(*s2) > 0 ) return -1;
869  else return 1;
870 }
871 
883 int string_sort(Bstring* slist, int descending, int value)
884 {
885  int i, n(0);
886  Bstring* s;
887 
888  for ( s = slist; s; s = s->next ) n++;
889 
890  Bstring* ssort = new Bstring[n];
891 
892  for ( i=0, s = slist; s; s = s->next, i++ ) ssort[i] = *s;
893 
894  if ( value ) {
895  if ( descending ) qsort((void *) ssort, n, sizeof(Bstring), QsortLargeToSmallStringValue);
896  else qsort((void *) ssort, n, sizeof(Bstring), QsortSmallToLargeStringValue);
897  } else {
898  if ( descending ) qsort((void *) ssort, n, sizeof(Bstring), QsortLargeToSmallString);
899  else qsort((void *) ssort, n, sizeof(Bstring), QsortSmallToLargeString);
900  }
901 
902  for ( i=0, s = slist; s; s = s->next, i++ ) *s = ssort[i];
903 
904  delete[] ssort;
905 
906  return 0;
907 }
Bstring::erase
Bstring erase(const long i)
Definition: Bstring.cpp:493
Bstring::operator>
bool operator>(const Bstring &s)
Definition: Bstring.cpp:213
Bstring::place
void place(long i, const Bstring &s)
Definition: Bstring.cpp:310
Bstring::remove
Bstring remove(const char c)
Definition: Bstring.cpp:473
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bstring::swap
Bstring swap(const long i, const long j)
Definition: Bstring.cpp:485
Bstring::count
long count(const char c)
Definition: Bstring.cpp:269
Bstring::insert
Bstring insert(long pos, const Bstring &s)
Definition: Bstring.cpp:598
Bstring::index
long index(const char c)
Definition: Bstring.h:102
Bstring::operator=
Bstring & operator=(const Bstring &s)
Definition: Bstring.cpp:108
Bstring
Definition: Bstring.h:29
Bstring::operator<
bool operator<(const Bstring &s)
Definition: Bstring.cpp:218
Bstring::canonical
Bstring canonical(int n)
Definition: Bstring.cpp:535
operator<<
ostream & operator<<(ostream &output, Bstring &s)
Definition: Bstring.cpp:702
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:523
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bstring::integer
long integer()
Definition: Bstring.cpp:547
Bstring::compare
long compare(const Bstring &s)
Definition: Bstring.cpp:277
Bstring::replace
Bstring replace(char cold, char cnew)
Definition: Bstring.cpp:465
Bstring::operator>>
Bstring operator>>(int n)
Definition: Bstring.cpp:240
Bstring::operator>=
bool operator>=(const Bstring &s)
Definition: Bstring.cpp:223
Bstring::no_lead_space
Bstring no_lead_space()
Definition: Bstring.cpp:349
verbose
int verbose
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
Bstring::fill
void fill(const char c)
Definition: Bstring.cpp:304
Bstring::real
double real()
Definition: Bstring.cpp:553
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:402
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bstring::operator[]
char & operator[](long i)
Definition: Bstring.cpp:247
operator+
Bstring operator+(const char *c, const Bstring &s)
Definition: Bstring.cpp:689
Bstring::compare_value
long compare_value(const Bstring &s)
Definition: Bstring.cpp:285
QsortSmallToLargeStringValue
int QsortSmallToLargeStringValue(const void *x, const void *y)
Utility function for sorting string values in qsort.
Definition: Bstring.cpp:850
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
Bstring::rfind
long rfind(const Bstring &s)
Definition: Bstring.h:106
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:389
Bstring::find
long find(const Bstring &s)
Definition: Bstring.h:104
string_sort
int string_sort(Bstring *slist, int descending, int value)
Sorts a list of strings in ascending (descending) lexical or value order.
Definition: Bstring.cpp:883
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
Bstring::right
Bstring right(long len)
Definition: Bstring.cpp:375
operator>>
istream & operator>>(istream &input, Bstring &s)
Definition: Bstring.cpp:695
Bstring::operator+=
Bstring & operator+=(const Bstring &s)
Definition: Bstring.cpp:149
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:673
Bstring.h
Header file for the string class.
Bstring::alnum
Bstring alnum()
Definition: Bstring.cpp:357
Bstring::truncate
Bstring truncate(const long n)
Definition: Bstring.cpp:503
string_catenate
Bstring string_catenate(Bstring *list)
Catenates a string linked list into one string.
Definition: Bstring.cpp:747
utilities.h
Header file for general utilities.
Bstring::substr
Bstring substr(long start, long len)
Definition: Bstring.cpp:332
QsortSmallToLargeString
int QsortSmallToLargeString(const void *x, const void *y)
Utility function for sorting string lexically in qsort.
Definition: Bstring.cpp:822
Bstring::within
Bstring within(char c1, char c2)
Definition: Bstring.cpp:450
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bstring::operator<<
Bstring operator<<(int n)
Definition: Bstring.cpp:233
Bstring::operator+
Bstring operator+(const Bstring &s)
Definition: Bstring.cpp:155
Bstring::left
Bstring left(long len)
Definition: Bstring.cpp:366
Bstring::next
Bstring * next
Definition: Bstring.h:31
parameter_file_path
Bstring parameter_file_path(Bstring filename)
Finds the parameter file path.
Definition: Bstring.cpp:795
QsortLargeToSmallString
int QsortLargeToSmallString(const void *x, const void *y)
Utility function for sorting string lexically in qsort.
Definition: Bstring.cpp:836
QsortLargeToSmallStringValue
int QsortLargeToSmallStringValue(const void *x, const void *y)
Utility function for sorting string values in qsort.
Definition: Bstring.cpp:864
Bstring::operator!=
bool operator!=(const Bstring &s)
Definition: Bstring.cpp:208
Bstring::split
Bstring * split()
Definition: Bstring.cpp:605
Bstring::base
Bstring base()
Definition: Bstring.cpp:516
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
Bstring::upper
Bstring upper()
Definition: Bstring.cpp:324
Bstring::common
Bstring common(const Bstring &s)
Definition: Bstring.cpp:296
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:316
Bstring::operator<=
bool operator<=(const Bstring &s)
Definition: Bstring.cpp:228
Bstring::no_space
Bstring no_space()
Definition: Bstring.cpp:340
Bstring::Bstring
Bstring()
Definition: Bstring.h:35
Bstring::split_into_integers
vector< long > split_into_integers(const Bstring &delim)
Definition: Bstring.cpp:657
Bstring::operator==
bool operator==(const Bstring &s)
Definition: Bstring.cpp:203