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