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