Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EST_String.h
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1997 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 
34 #ifndef __EST_STRING_H__
35 #define __EST_STRING_H__
36 
37 class EST_String;
38 class EST_Regex;
39 
40 #define EST_Regex_max_subexpressions 10
41 
42 #include <cstring>
43 #include <iostream>
44 #include <climits>
45 using namespace std;
46 #include "EST_Chunk.h"
47 #include "EST_strcasecmp.h"
48 #include "EST_bool.h"
49 
50 extern "C" void abort(void);
51 
52 class EST_String;
53 int fcompare(const EST_String &a, const EST_String &b, const unsigned char *table=NULL);
54 int fcompare(const EST_String &a, const char *b, const unsigned char *table=NULL);
55 
56 /** @class EST_String
57  * @ingroup stringclasses
58  * A non-copyleft implementation of a string class to use with
59  * compilers that aren't GNU C++.
60  *
61  * Strings are reference-counted and reasonably efficient (eg you
62  * can pass them around, into and out of functions and so on
63  * without worrying too much about the cost).
64  *
65  * The associated class EST_Regex can be used to represent regular
66  * expressions.
67  *
68  * @see EST_Chunk
69  * @see EST_Regex
70  * @see string_example
71  * @author Alan W Black <awb@cstr.ed.ac.uk>
72  * @author Richard Caley <rjc@cstr.ed.ac.uk>
73  * @version $Id: EST_String.h,v 1.7 2009/07/03 17:13:56 awb Exp $
74  */
75 class EST_String {
76 
77  /** For better libg++ compatibility.
78  *
79  * Includes String from char constructor which
80  * tends to mask errors in use. Also reverses the () and [] operators.
81  */
82 # define __FSF_COMPATIBILITY__ (0)
83 
84  /** Allow gsub() to be used in multi-threaded applications
85  * This will cause gsub to use a local table of substitution points
86  * walloced for each gsub. Otherwise one global one is used which
87  * should be faster, but non reentrant.
88  */
89 # define __GSUB_REENTRANT__ (1)
90 
91 /// Gripe about weird arguments like Nulls
92 #define __STRING_ARG_GRIPE__ (1)
93 
94 /// When we find something to gripe about we die then and there.
95 #define __GRIPE_FATAL__ (1)
96 
97 #if __GRIPE_FATAL__
98 # define gripe(WHAT) (cerr<< ("oops! " WHAT "\n"),abort())
99 #else
100 # define gripe(WHAT) (cerr<< ("oops! " WHAT "\n"))
101 #endif
102 
103 #if __STRING_ARG_GRIPE__
104 # define safe_strlen(S) ((S)?strlen(S):(gripe("null strlen"),0))
105 # define CHECK_STRING_ARG(S) if (!(S)) gripe("null string arg")
106 #else
107 # define safe_strlen(S) ((S)?strlen(S):0)
108 # define CHECK_STRING_ARG(S) /* empty */
109 #endif
110 
111 public:
112  /// Global version string.
113  static const char *version;
114 
115  /// Constant empty string
116  static const EST_String Empty;
117 
118  /// Type of string size field.
119  typedef int EST_string_size;
120  /// Maximum string size.
121 # define MAX_STRING_SIZE (INT_MAX)
122 
123 private:
124  /// Smart pointer to actual memory.
125  EST_ChunkPtr memory;
126  /// Size of string.
127  EST_string_size size;
128 
129  // Make sure this is exactly the same as an EST_String. This is being too
130  // clever by half.
131 
132  struct EST_dumb_string {
133  EST_ChunkPtr memory;
134  EST_string_size size;
135  } ;
136 
137  /// Flags indicating which bit of a string to extract.
138  enum EST_chop_direction {
139  Chop_Before = -1,
140  Chop_At = 0,
141  Chop_After = 1
142  };
143 
144  /// Simple utility which removes const-ness from memory
145  static inline EST_ChunkPtr &NON_CONST_CHUNKPTR(const EST_ChunkPtr &ecp)
146  { return *((EST_ChunkPtr *)&ecp);}
147 
148  /// private constructor which uses the buffer given.
149  EST_String(int len, EST_ChunkPtr cp) {
150  size=len;
151  memory = cp;
152  }
153 
154  /// Is more than one String represented by the same memory?
155  int shareing (void) { return memory.shareing();}
156 
157  /**@name Finding substrings */
158  ///@{
159  /// Find substring
160  int locate(const char *it, int len, int from, int &start, int &end) const;
161  /// Find substring
162  int locate(const EST_String &s, int from, int &start, int &end) const
163  { return locate((const char *)s.memory, s.size, from, start, end); }
164  /// Find match for regexp.
165  int locate(EST_Regex &ex, int from, int &start, int &end, int *starts=NULL, int *ends=NULL) const;
166  ///@}
167 
168 
169  /**@name Extract Substrings */
170  ///@{
171  int extract(const char *it, int len, int from, int &start, int &end) const;
172  int extract(const EST_String &s, int from, int &start, int &end) const
173  { return extract((const char *)s.memory, s.size, from, start, end); }
174  int extract(EST_Regex &ex, int from, int &start, int &end) const;
175  ///@}
176 
177  /**@name Chop out part of string */
178  ///@{
179  /// Locate subsring and chop.
180  EST_String chop_internal(const char *s, int length, int pos, EST_chop_direction directionult) const;
181  /// Chop at given position.
182  EST_String chop_internal(int pos, int length, EST_chop_direction directionult) const;
183 
184  /// Locate match for expression and chop.
185  EST_String chop_internal(EST_Regex &ex, int pos, EST_chop_direction directionult) const;
186  ///@}
187 
188  /**@name Global search and replace */
189  ///@{
190  /// Substitute for string
191  int gsub_internal(const char *os, int olength, const char *s, int length);
192  /// Substitute for matches of regexp.
193  int gsub_internal(EST_Regex &ex, const char *s, int length);
194  ///@}
195 
196  /// Split the string down into parts.
197  int split_internal(EST_String result[], int max, const char* s_seperator, int slen, EST_Regex *re_separator, char quote) const;
198 
199  int Int(bool *ok_p) const;
200  long Long(bool *ok_p) const;
201  float Float(bool *ok_p) const;
202  double Double(bool *ok_p) const;
203 public:
204 
205  /// Construct an empty string.
206  EST_String(void) :memory() {size=0;}
207 
208  /// Construct from char *
209  EST_String(const char *s);
210 
211  /// Construct from part of char * or fill with given character.
212  EST_String(const char *s, int start_or_fill, int len);
213 
214  /// Construct from C string.
215  EST_String(const char *s, int s_size, int start, int len);
216 
217  // Create from EST_String
218  EST_String(const EST_String &s, int start, int len);
219 
220  /** Copy constructor
221  * We have to declare our own copy constructor to lie to the
222  * compiler about the constness of the RHS.
223  */
224  EST_String(const EST_String &s) {
225  memory = NON_CONST_CHUNKPTR(s.memory);
226  size = s.size;
227  }
228 
229 #if __FSF_COMPATIBILITY__
230  /** Construct from single char.
231  * This constructor is not usually included as it can mask errors.
232  * @see __FSF_COMPATIBILITY__
233  */
234  EST_String(const char c);
235 #endif
236 
237  /// Destructor.
239  size=0;
240  memory=NULL;
241  }
242 
243  /// Length of string ({\em not} length of underlying chunk)
244  int length(void) const { return size; }
245  /// Size of underlying chunk.
246  int space (void) const { return memory.size(); }
247  /// Get a const-pointer to the actual memory.
248  const char *str(void) const { return size==0?"":(const char *)memory; }
249  /// Get a writable pointer to the actual memory.
250  char *updatable_str(void) { return size==0?(char *)"":(char *)memory; }
251  void make_updatable(void) { cp_make_updatable(memory, size+1);}
252 
253 
254  /// Build string from a single character.
255  static EST_String FromChar(const char c)
256  { const char s[2] = { c, 0 }; return EST_String(s); }
257 
258  /// Build string from an integer.
259  static EST_String Number(int i, int base=10);
260 
261  /// Build string from a long integer.
262  static EST_String Number(long i, int base=10);
263 
264  /// Build string from a double.
265  static EST_String Number(double d);
266 
267  /// Build string from a float
268  static EST_String Number(float f);
269 
270  /// Convert to an integer
271  int Int(bool &ok) const { return Int(&ok); }
272  int Int(void) const { return Int((bool *)NULL); }
273 
274  /// Convert to a long
275  long Long(bool &ok) const { return Long(&ok); }
276  long Long(void) const { return Long((bool *)NULL); }
277 
278  /// Convert to a float
279  float Float(bool &ok) const { return Float(&ok); }
280  float Float(void) const { return Float((bool *)NULL); }
281 
282  /// Convert to a double
283  double Double(bool &ok) const { return Double(&ok); }
284  double Double(void) const { return Double((bool *)NULL); }
285 
286  /**@name Before */
287  ///@{
288  /// Part before position
289  EST_String before(int pos, int len=0) const
290  { return chop_internal(pos, len, Chop_Before); }
291  /// Part before first matching substring after pos.
292  EST_String before(const char *s, int pos=0) const
293  { return chop_internal(s, safe_strlen(s), pos, Chop_Before); }
294  /// Part before first matching substring after pos.
295  EST_String before(const EST_String &s, int pos=0) const
296  { return chop_internal(s.str(), s.size, pos, Chop_Before); }
297  /// Part before first match of regexp after pos.
298  EST_String before(EST_Regex &e, int pos=0) const
299  { return chop_internal(e, pos, Chop_Before); }
300  ///@}
301 
302  /**@name At */
303  ///@{
304  /// Return part at position
305  EST_String at(int from, int len=0) const
306  { return EST_String(str(),size,from<0?(size+from):from,len); }
307  /// Return part where substring found (not useful, included for completeness)
308  EST_String at(const char *s, int pos=0) const
309  { return chop_internal(s, safe_strlen(s), pos, Chop_At); }
310  /// Return part where substring found (not useful, included for completeness)
311  EST_String at(const EST_String &s, int pos=0) const
312  { return chop_internal(s.str(), s.size, pos, Chop_At); }
313  /// Return part matching regexp.
314  EST_String at(EST_Regex &e, int pos=0) const
315  { return chop_internal(e, pos, Chop_At); }
316  ///@}
317 
318  /**@name After */
319  ///@{
320  /// Part after pos+len
321  EST_String after(int pos, int len=1) const
322  { return chop_internal(pos, len, Chop_After); }
323  /// Part after substring.
324  EST_String after(const char *s, int pos=0) const
325  { return chop_internal(s, safe_strlen(s), pos, Chop_After); }
326  /// Part after substring.
327  EST_String after(const EST_String &s, int pos=0) const
328  { return chop_internal(s.str(), s.size, pos, Chop_After); }
329  /// Part after match of regular expression.
330  EST_String after(EST_Regex &e, int pos=0) const
331  { return chop_internal(e, pos, Chop_After); }
332  ///@}
333 
334  /**@name Search for something */
335  ///@{
336  /// Find a substring.
337  int search(const char *s, int len, int &mlen, int pos=0) const
338  { int start, end;
339  if (locate(s, len, pos, start, end))
340  { mlen=end-start; return start; }
341  return -1;
342  }
343 
344  /// Find a substring.
345  int search(const EST_String s, int &mlen, int pos=0) const
346  { int start, end;
347  if (locate(s, pos, start, end))
348  { mlen=end-start; return start; }
349  return -1;
350  }
351 
352  /// Find a match of the regular expression.
353  int search(EST_Regex &re, int &mlen, int pos=0, int *starts=NULL, int *ends=NULL) const
354  { int start=0, end=0;
355  if (locate(re, pos, start, end, starts, ends))
356  { mlen=end-start; return start; }
357  return -1;
358  }
359  ///@}
360 
361 
362  /**@name Get position of something */
363  ///@{
364  /// Position of substring (starting at pos)
365  int index(const char *s, int pos=0) const
366  { int start, end; return locate(s, safe_strlen(s), pos, start, end)?start:-1; }
367  /// Position of substring (starting at pos)
368  int index(const EST_String &s, int pos=0) const
369  { int start, end; return locate(s, pos, start, end)?start:-1; }
370  /// Position of match of regexp (starting at pos)
371  int index(EST_Regex &ex, int pos=0) const
372  { int start, end; return locate(ex, pos, start, end)?start:-1; }
373  ///@}
374 
375  /**@name Does string contain something? */
376  ///@{
377  /// Does it contain this substring?
378  int contains(const char *s, int pos=-1) const
379  { int start, end; return extract(s, safe_strlen(s), pos, start, end); }
380  /// Does it contain this substring?
381  int contains(const EST_String &s, int pos=-1) const
382  { int start, end; return extract(s, pos, start, end); }
383  /// Does it contain this character?
384  int contains(const char c, int pos=-1) const
385  { int start, end; char s[2] = {c,0}; return extract(s, 1, pos, start, end); }
386  /// Does it contain a match for this regular expression?
387  int contains(EST_Regex &ex, int pos=-1) const
388  { int start, end; return extract(ex, pos, start, end); }
389  ///@}
390 
391  /**@name Does string exactly match? */
392  ///@{
393  /// Exactly match this string?
394  int matches(const char *e, int pos=0) const;
395  /// Exactly match this string?
396  int matches(const EST_String &e, int pos=0) const;
397  /// Exactly matches this regular expression, can return ends of sub-expressions.
398  int matches(EST_Regex &e, int pos=0, int *starts=NULL, int *ends=NULL) const;
399  ///@}
400 
401  /**@name Global replacement */
402  ///@{
403  /// Substitute one string for another.
404  int gsub(const char *os, const EST_String &s)
405  { return gsub_internal(os, safe_strlen(os), s, s.size); }
406  /// Substitute one string for another.
407  int gsub(const char *os, const char *s)
408  { return gsub_internal(os, safe_strlen(os), s, safe_strlen(s)); }
409  /// Substitute one string for another.
410  int gsub(const EST_String &os, const EST_String &s)
411  { return gsub_internal(os, os.size, s, s.size); }
412  /// Substitute one string for another.
413  int gsub(const EST_String &os, const char *s)
414  { return gsub_internal(os, os.size, s, safe_strlen(s)); }
415 
416  /// Substitute string for matches of regular expression.
417  int gsub(EST_Regex &ex, const EST_String &s)
418  { return gsub_internal(ex, s, s.size); }
419  /// Substitute string for matches of regular expression.
420  int gsub(EST_Regex &ex, const char *s)
421  { return gsub_internal(ex, s, safe_strlen(s)); }
422  /// Substitute string for matches of regular expression.
423  int gsub(EST_Regex &ex, int bracket_num)
424  { return gsub_internal(ex, NULL, bracket_num); }
425  /// Substitute the result of a match into a string.
426  int subst(EST_String source,
427  int (&starts)[EST_Regex_max_subexpressions],
428  int (&ends)[EST_Regex_max_subexpressions]);
429  ///@}
430 
431  /**@name Frequency counts */
432  ///@{
433  /// Number of occurrences of substring
434  int freq(const char *s) const;
435  /// Number of occurrences of substring
436  int freq(const EST_String &s) const;
437  /// Number of matches of regular expression.
438  int freq(EST_Regex &s) const;
439  ///@}
440 
441  /**@name Quoting */
442  ///@{
443  /// Return the string in quotes with internal quotes protected.
444  EST_String quote(const char quotec) const;
445  /// Return in quotes if there is something to protect (e.g. spaces)
446  EST_String quote_if_needed(const char quotec) const;
447  /// Remove quotes and unprotect internal quotes.
448  EST_String unquote(const char quotec) const;
449  /// Remove quotes if any.
450  EST_String unquote_if_needed(const char quotec) const;
451  ///@}
452 
453  /**@name Operators */
454  ///@{
455 #if __FSF_COMPATIBILITY__
456  const char operator [] (int i) const { return memory[i]; }
457  char &operator () (int i) { return memory(i); }
458 #else
459  /// Function style access to constant strings.
460  const char operator () (int i) const { return memory[i]; }
461  /// Array style access to writable strings.
462  char &operator [] (int i) { return memory(i); }
463 #endif
464 
465  /// Cast to const char * by simply giving access to pointer.
466  operator const char*() const {return str(); }
467  operator const char*() {return str(); }
468  /// Cast to char *, may involve copying.
469  operator char*() { return updatable_str(); }
470 
471  ///@}
472 
473  /**@name Add to end of string. */
474  ///@{
475  /// Add C string to end of EST_String
476  EST_String &operator += (const char *b);
477  /// Add EST_String to end of EST_String
478  EST_String &operator += (const EST_String b);
479  ///@}
480 
481  /**@name Assignment */
482  ///@{
483  /// Assign C string to EST_String
484  EST_String &operator = (const char *str);
485  /// Assign single character to EST_String
486  EST_String &operator = (const char c);
487  /// Assign EST_String to EST_String.
488  EST_String &operator = (const EST_String &s);
489  ///@}
490 
491  /**@name Concatenation */
492  ///@{
493  /// Concatenate two EST_Strings
494  friend EST_String operator + (const EST_String &a, const EST_String &b);
495  /// Concatenate C String with EST_String
496  friend EST_String operator + (const char *a, const EST_String &b);
497  /// Concatenate EST_String with C String
498  friend EST_String operator + (const EST_String &a, const char *b);
499  ///@}
500 
501  /// Repeat string N times
502  friend EST_String operator * (const EST_String &s, int n);
503 
504  /**@name relational operators */
505  ///@{
506  ///
507  friend int operator == (const char *a, const EST_String &b);
508  ///
509  friend int operator == (const EST_String &a, const char *b)
510  { return b == a; }
511  ///
512  friend int operator == (const EST_String &a, const EST_String &b);
513 
514  ///
515  friend int operator != (const char *a, const EST_String &b)
516  { return !(a==b); }
517  ///
518  friend int operator != (const EST_String &a, const char *b)
519  { return !(a==b); }
520  ///
521  friend int operator != (const EST_String &a, const EST_String &b)
522  { return !(a==b); }
523 
524  ///
525  friend inline int operator < (const char *a, const EST_String &b)
526  { return compare(a,b) < 0; }
527  ///
528  friend inline int operator < (const EST_String &a, const char *b)
529  { return compare(a,b) < 0; }
530  ///
531  friend inline int operator < (const EST_String &a, const EST_String &b)
532  { return compare(a,b) < 0; }
533  ///
534  friend inline int operator > (const char *a, const EST_String &b)
535  { return compare(a,b) > 0; }
536  ///
537  friend inline int operator > (const EST_String &a, const char *b)
538  { return compare(a,b) > 0; }
539  ///
540  friend inline int operator > (const EST_String &a, const EST_String &b)
541  { return compare(a,b) > 0; }
542  ///
543  friend inline int operator <= (const char *a, const EST_String &b)
544  { return compare(a,b) <= 0; }
545  ///
546  friend inline int operator <= (const EST_String &a, const char *b)
547  { return compare(a,b) <= 0; }
548  ///
549  friend inline int operator <= (const EST_String &a, const EST_String &b)
550  { return compare(a,b) <= 0; }
551  ///
552  friend inline int operator >= (const char *a, const EST_String &b)
553  { return compare(a,b) >= 0; }
554  ///
555  friend inline int operator >= (const EST_String &a, const char *b)
556  { return compare(a,b) >= 0; }
557  ///
558  friend inline int operator >= (const EST_String &a, const EST_String &b)
559  { return compare(a,b) >= 0; }
560  ///@}
561 
562  ///@}
563 
564  /**@name String comparison.
565  * All these operators return -1, 0 or 1 to indicate the sort
566  * order of the strings.
567  */
568  ///@{
569  ///
570  friend int compare(const EST_String &a, const EST_String &b);
571  ///
572  friend int compare(const EST_String &a, const char *b);
573  ///
574  friend inline int compare(const char *a, const EST_String &b)
575  { return -compare(b,a); }
576  /** Case folded comparison.
577  *
578  * The table argument can defined how upper and lower
579  * case characters correspond. The default works for
580  * ASCII.
581  */
582  ///@{
583  friend int fcompare(const EST_String &a, const EST_String &b,
584  const unsigned char *table);
585 
586  friend int fcompare(const EST_String &a, const char *b,
587  const unsigned char *table);
588  ///
589  friend inline int fcompare(const EST_String &a, const EST_String &b,
590  const EST_String &table)
591  { return fcompare(a, b, (const unsigned char *)(const char *)table); }
592  ///@}
593  ///@}
594  ///@}
595 
596 
597  /**@name Split a string into parts.
598  *
599  * These functions divide up a string producing an array of
600  * substrings.
601  */
602  ///@{
603  /// Split at a given separator.
604  friend int split(const EST_String & s, EST_String result[],
605  int max, const EST_String& seperator, char quote=0)
606  { return s.split_internal(result, max, (const char *)seperator, seperator.length(), NULL, quote); }
607  /// Split at a given separator.
608  friend int split(const EST_String &s, EST_String result[],
609  int max, const char *seperator, char quote=0)
610  { return s.split_internal(result, max, seperator, strlen(seperator), NULL, quote); }
611  /// Split at each match of the regular expression.
612  friend int split(const EST_String & s, EST_String result[], int max,
613  EST_Regex& seperator, char quote=0)
614  { return s.split_internal(result, max, NULL, 0, &seperator, quote); }
615  ///@}
616 
617  /// Convert to upper case.
618  friend EST_String upcase(const EST_String &s);
619  /// Convert to lower case.
620  friend EST_String downcase(const EST_String &s);
621 
622  /** Concatenate a number of strings.
623  * This is more efficient than multiple uses of + or +=
624  */
625  static EST_String cat(const EST_String s1,
626  const EST_String s2 = Empty,
627  const EST_String s3 = Empty,
628  const EST_String s4 = Empty,
629  const EST_String s5 = Empty,
630  const EST_String s6 = Empty,
631  const EST_String s7 = Empty,
632  const EST_String s8 = Empty,
633  const EST_String s9 = Empty
634  );
635 
636  /* Hacky way to ignore volatile */
637  EST_String & ignore_volatile(void) volatile { return *((EST_String *)(void *)this); }
638 
639  /// Stream output for EST_String.
640  friend ostream &operator << (ostream &s, const EST_String &str);
641  friend class EST_Regex;
642 
643 };
644 
645 EST_ChunkPtr chunk_allocate(int bytes);
646 EST_ChunkPtr chunk_allocate(int bytes, const char *initial, int initial_len);
647 EST_ChunkPtr chunk_allocate(int bytes, const EST_ChunkPtr &initial, int initial_start, int initial_len);
648 
649 int operator == (const char *a, const EST_String &b);
650 int operator == (const EST_String &a, const EST_String &b);
651 ostream &operator << (ostream &s, const EST_String &str);
652 
653 #include "EST_Regex.h"
654 
655 #endif
EST_String at(EST_Regex &e, int pos=0) const
Return part matching regexp.
Definition: EST_String.h:314
EST_String(void)
Construct an empty string.
Definition: EST_String.h:206
EST_String at(const EST_String &s, int pos=0) const
Return part where substring found (not useful, included for completeness)
Definition: EST_String.h:311
EST_String after(const char *s, int pos=0) const
Part after substring.
Definition: EST_String.h:324
int Int(bool &ok) const
Convert to an integer.
Definition: EST_String.h:271
int index(const char *s, int pos=0) const
Position of substring (starting at pos)
Definition: EST_String.h:365
int gsub(EST_Regex &ex, const char *s)
Substitute string for matches of regular expression.
Definition: EST_String.h:420
A Regular expression class to go with the CSTR EST_String class.
Definition: EST_Regex.h:56
friend ostream & operator<<(ostream &s, const EST_Regex &str)
Stream output of regular expression.
Definition: EST_Regex.cc:330
long Long(bool &ok) const
Convert to a long.
Definition: EST_String.h:275
friend int fcompare(const EST_String &a, const EST_String &b, const unsigned char *table)
Definition: EST_String.cc:1148
static const char * version
Global version string.
Definition: EST_String.h:113
EST_String after(EST_Regex &e, int pos=0) const
Part after match of regular expression.
Definition: EST_String.h:330
friend int split(const EST_String &s, EST_String result[], int max, EST_Regex &seperator, char quote=0)
Split at each match of the regular expression.
Definition: EST_String.h:612
int gsub(EST_Regex &ex, const EST_String &s)
Substitute string for matches of regular expression.
Definition: EST_String.h:417
int index(const EST_String &s, int pos=0) const
Position of substring (starting at pos)
Definition: EST_String.h:368
int contains(const EST_String &s, int pos=-1) const
Does it contain this substring?
Definition: EST_String.h:381
int gsub(const char *os, const EST_String &s)
Substitute one string for another.
Definition: EST_String.h:404
EST_String after(const EST_String &s, int pos=0) const
Part after substring.
Definition: EST_String.h:327
friend int split(const EST_String &s, EST_String result[], int max, const char *seperator, char quote=0)
Split at a given separator.
Definition: EST_String.h:608
int space(void) const
Size of underlying chunk.
Definition: EST_String.h:246
int EST_string_size
Type of string size field.
Definition: EST_String.h:119
int contains(const char c, int pos=-1) const
Does it contain this character?
Definition: EST_String.h:384
friend int split(const EST_String &s, EST_String result[], int max, const EST_String &seperator, char quote=0)
Split at a given separator.
Definition: EST_String.h:604
EST_String before(const EST_String &s, int pos=0) const
Part before first matching substring after pos.
Definition: EST_String.h:295
EST_String at(const char *s, int pos=0) const
Return part where substring found (not useful, included for completeness)
Definition: EST_String.h:308
static EST_String FromChar(const char c)
Build string from a single character.
Definition: EST_String.h:255
int contains(EST_Regex &ex, int pos=-1) const
Does it contain a match for this regular expression?
Definition: EST_String.h:387
int length(void) const
Length of string ({not} length of underlying chunk)
Definition: EST_String.h:244
int gsub(const EST_String &os, const char *s)
Substitute one string for another.
Definition: EST_String.h:413
int index(EST_Regex &ex, int pos=0) const
Position of match of regexp (starting at pos)
Definition: EST_String.h:371
EST_String before(EST_Regex &e, int pos=0) const
Part before first match of regexp after pos.
Definition: EST_String.h:298
EST_String before(const char *s, int pos=0) const
Part before first matching substring after pos.
Definition: EST_String.h:292
int contains(const char *s, int pos=-1) const
Does it contain this substring?
Definition: EST_String.h:378
const char * str(void) const
Get a const-pointer to the actual memory.
Definition: EST_String.h:248
char * updatable_str(void)
Get a writable pointer to the actual memory.
Definition: EST_String.h:250
int search(EST_Regex &re, int &mlen, int pos=0, int *starts=NULL, int *ends=NULL) const
Find a match of the regular expression.
Definition: EST_String.h:353
int gsub(const char *os, const char *s)
Substitute one string for another.
Definition: EST_String.h:407
double Double(bool &ok) const
Convert to a double.
Definition: EST_String.h:283
EST_String after(int pos, int len=1) const
Part after pos+len.
Definition: EST_String.h:321
int search(const EST_String s, int &mlen, int pos=0) const
Find a substring.
Definition: EST_String.h:345
EST_String before(int pos, int len=0) const
Part before position.
Definition: EST_String.h:289
int search(const char *s, int len, int &mlen, int pos=0) const
Find a substring.
Definition: EST_String.h:337
EST_String at(int from, int len=0) const
Return part at position.
Definition: EST_String.h:305
EST_String(const EST_String &s)
Definition: EST_String.h:224
static const EST_String Empty
Constant empty string.
Definition: EST_String.h:116
int gsub(EST_Regex &ex, int bracket_num)
Substitute string for matches of regular expression.
Definition: EST_String.h:423
float Float(bool &ok) const
Convert to a float.
Definition: EST_String.h:279
~EST_String()
Destructor.
Definition: EST_String.h:238
int gsub(const EST_String &os, const EST_String &s)
Substitute one string for another.
Definition: EST_String.h:410