sipxportlib  Version 3.3
UtlString.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2014 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2006 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
8 // Licensed to SIPfoundry under a Contributor Agreement.
9 //
10 // $$
12 
13 
14 #ifndef _UtlString_h_
15 #define _UtlString_h_
16 
17 // SYSTEM INCLUDES
18 #include <stdarg.h>
19 
20 #include "os/OsDefs.h"
21 
22 // APPLICATION INCLUDES
23 #include "utl/UtlDefs.h"
25 
26 // DEFINES
27 #define DEFAULT_UTLSTRING_CAPACITY 100
28 
29 // MACROS
30 // EXTERNAL FUNCTIONS
31 // EXTERNAL VARIABLES
32 // CONSTANTS
33 // STRUCTS
34 // TYPEDEFS
35 // FORWARD DECLARATIONS
36 
49 {
50 /* //////////////////////////// PUBLIC //////////////////////////////////// */
51 public:
52  static const UtlContainableType TYPE;
54  static const char* ssNull;
55 
56  static const size_t UTLSTRING_NOT_FOUND;
57 
58  static const size_t UTLSTRING_TO_END;
65  typedef enum StripType
66  {
67  leading=1,
70  } StripType;
71 
75  typedef enum CompareCase
76  {
79  } CompareCase;
80 
81 // ================================================================
84 
87  UtlString();
88 
90  UtlString(const char* szSource );
95  UtlString(const char* szSource, size_t length);
102  UtlString(const UtlString& source);
104 
106  UtlString(const UtlString& source, size_t length);
114  virtual UtlCopyableContainable* clone() const;
116 
118 // ================================================================
122 
125  UtlString& operator=(const char* szStr);
126 
128  UtlString& operator=(const UtlString& str);
129 
131 // ================================================================
135 
138  size_t length() const;
139 
141  const char* data() const;
153  operator const char*() const;
160  size_t capacity() const;
162 
164 // ================================================================
169 
172  UtlString operator() (size_t start,
174  size_t len
177  ) const;
188  char operator()(size_t N);
199 // ================================================================
204 
206 
208  UtlBoolean isNull() const;
209 
211  virtual int compareTo(const char *) const;
216  int compareTo(const char *, CompareCase type) const;
218 
220  int compareTo(UtlString const *, CompareCase type) const;
225  UtlBoolean contains(const char *) const;
233  friend UtlBoolean operator!=(const char *, const UtlString& );
234 
235  friend UtlBoolean operator!=(const char , const UtlString& );
236 
237  friend UtlBoolean operator==(const char , const UtlString& );
238 
239  friend UtlBoolean operator==(const char *, const UtlString& );
240 
241  UtlBoolean operator==(const char *) const;
242 
243  UtlBoolean operator!=(const char *) const;
244 
245  UtlBoolean operator==(const UtlString&) const;
246 
247  UtlBoolean operator!=(const UtlString&) const;
248 
250 // ================================================================
255 
258  size_t index(char c) const;
263  size_t index(char c, size_t offset) const;
270  size_t first(char c) const;
278  size_t index(const char* ) const;
284  size_t index(const char* , size_t ) const;
292  size_t index(const char* , size_t , CompareCase ) const;
300  size_t index(const UtlString& ) const;
308  size_t index(const UtlString& match,
310  size_t offset
311  ) const;
319  size_t index(const UtlString& , size_t , CompareCase ) const;
328  size_t first(const char* ) const;
334  size_t last(char s) const;
340 // ================================================================
346 
349  UtlString& operator+=(const char *);
350 
352  UtlString& append(const char* szStr);
353 
355  UtlString& operator+=(const UtlString& s);
356 
358  UtlString& append(const UtlString& str
359  );
360 
362  UtlString& append(const UtlString& str,
363  size_t position,
364  size_t length
365  );
385  UtlString& append(const char* szStr, size_t N);
387 
389  UtlString& operator+=(const char c);
390 
392  UtlString& append(const char c);
393 
395  UtlString& appendFormat(const char* format, ... )
396 #ifdef __GNUC__
397  /* with the -Wformat switch, this enables format string checking */
398  __attribute__ ((format(printf, 2, 3)))
399 #endif
400  ;
401 
403  UtlString& appendBinaryToString(const void* binaryData, int numBytes, int valuesPerRow = 16);
415 // ================================================================
425 
428  UtlString& insert(size_t position,
429  const UtlString& src
430  );
435  UtlString& insert(size_t position,
437  const char newChar
438  );
443  UtlString& insert(size_t position,
445  const char* src
446  );
451  UtlString& prepend(const char* szStr);
455  UtlString& insert(size_t position,
457  const char* src,
458  size_t sourceLenth
459  );
466 // ================================================================
471 
474  void replaceAt(size_t pos,
475  char newChar
476  );
477 
478 
480  UtlString& replace(const char src, const char tgt);
481 
483  UtlString& replace(size_t pos,
484  size_t N,
485  const char* replaceStr
486  );
493  UtlString& replace(size_t pos,
495  size_t N,
496  const char* replaceStr,
497  size_t L
498  );
505  UtlString& replace(size_t pos,
507  size_t N,
508  const UtlString& replaceStr
509  );
516 // ================================================================
521 
524  friend UtlString operator+(const UtlString& s1, const UtlString& s2);
525 
527  friend UtlString operator+(const UtlString& s, const char* c);
528 
530  friend UtlString operator+(const char* c, const UtlString& s);
531 
533 // ================================================================
538 
541  UtlString& remove(size_t pos);
546  UtlString& remove(size_t pos, size_t N);
552 // ================================================================
557 
560  UtlString strip();
561 
563  UtlString strip(StripType whichEnd);
570  UtlString strip(StripType whichEnd, char charToStrip);
578 // ================================================================
583 
588  void toLower();
589 
593  void toUpper();
594 
596 // ================================================================
600 
603  size_t capacity(size_t N);
617  void resize(size_t N, UtlBoolean clearTail=TRUE);
627 // ================================================================
632 
635  virtual unsigned hash() const;
641  virtual UtlContainableType getContainableType() const;
647  virtual int compareTo(UtlContainable const *other) const;
657  virtual UtlBoolean isEqual(UtlContainable const *) const;
663  virtual UtlBoolean isInstanceOf(const UtlContainableType type) const;
665 
667 // ================================================================
671 
674  virtual ~UtlString();
675 
677 
678 /* //////////////////////////// PROTECTED ///////////////////////////////// */
679 protected:
680 
681 /* //////////////////////////// PRIVATE /////////////////////////////////// */
682 private:
683  char* mpData; //: The value of UtlString.
684  size_t mSize; //: The number of bytes of data used.
685  size_t mCapacity; //: The allocated size of data.
686  char mBuiltIn[DEFAULT_UTLSTRING_CAPACITY];
687 };
688 
689 /* ============================ INLINE METHODS ============================ */
690 
691 #endif // _UtlString_h_
virtual int compareTo(const char *) const
Compare this string to a null terminated string (case sensitive).
Definition: UtlString.cpp:1221
void toLower()
Definition: UtlString.cpp:637
void resize(size_t N, UtlBoolean clearTail=TRUE)
Set a new size for the string.
Definition: UtlString.cpp:671
virtual UtlBoolean isInstanceOf(const UtlContainableType type) const
Determine if this object is a derivative of the specified UtlContainableType.
Definition: UtlString.cpp:1320
StripType
Definition: UtlString.h:65
const char * data() const
Return a read-only pointer to the stored string value..
Definition: UtlString.cpp:832
UtlString & operator=(const char *szStr)
Replace the contents of this string with a null terminated string.
Definition: UtlString.cpp:117
UtlString & insert(size_t position, const UtlString &src)
Insert a UtlString.
Definition: UtlString.cpp:402
CompareCase
Definition: UtlString.h:75
Definition: UtlString.h:67
Definition: UtlCopyableContainable.h:43
friend UtlString operator+(const UtlString &s1, const UtlString &s2)
Concatenate two UtlStrings as: s1 + s2.
Definition: UtlString.cpp:775
virtual unsigned hash() const
Calculate a hash over the string contents.
Definition: UtlString.cpp:1102
void replaceAt(size_t pos, char newChar)
Replace a single character at the designated position.
Definition: UtlString.cpp:458
friend UtlBoolean operator!=(const char *, const UtlString &)
Definition: UtlString.cpp:1130
friend UtlBoolean operator==(const char, const UtlString &)
Definition: UtlString.cpp:1155
static const size_t UTLSTRING_TO_END
Definition: UtlString.h:58
UtlString & replace(const char src, const char tgt)
Replace all instances of character src with character tgt.
Definition: UtlString.cpp:515
UtlBoolean isNull() const
Return true if this is an empty string.
Definition: UtlString.cpp:1315
Definition: UtlString.h:78
UtlString & append(const char *szStr)
Append a null terminated string to the end of this string.
Definition: UtlString.cpp:202
UtlBoolean contains(const char *) const
Check for a null terminated value in this string.
Definition: UtlString.cpp:1300
UtlString strip()
Removes whitespace (space, tab, Cr, Lf) from the end of the string.
Definition: UtlString.cpp:533
Definition: UtlString.h:69
const char *const UtlContainableType
Definition: UtlDefs.h:70
Definition: UtlContainable.h:37
size_t capacity() const
Return the current capacity allocated for this string.
Definition: UtlString.cpp:1058
void toUpper()
Definition: UtlString.cpp:654
size_t length() const
The current length of the string value.
Definition: UtlString.cpp:825
virtual UtlContainableType getContainableType() const
Determine whether or not the values in a containable are comparable.
Definition: UtlString.cpp:1121
Definition: UtlString.h:77
Definition: UtlString.h:48
UtlString & appendFormat(const char *format,...)
Append format string like pritnf.
Definition: UtlString.cpp:254
UtlString & operator+=(const char *)
Append a null terminated string to the end of the lvalue.
Definition: UtlString.cpp:151
virtual UtlCopyableContainable * clone() const
Clone method for UtlCopyableContainable requirements.
Definition: UtlString.cpp:97
static const UtlContainableType TYPE
Definition: UtlString.h:52
size_t index(char c) const
Find the first instance of a single character.
Definition: UtlString.cpp:840
Definition: UtlString.h:68
UtlString & prepend(const char *szStr)
Prepend a null terminated string at the beginning of this string.
Definition: UtlString.cpp:186
#define DEFAULT_UTLSTRING_CAPACITY
initial capacity unless overridden by the constructor
Definition: UtlString.h:27
UtlString()
Default Constructor.
Definition: UtlString.cpp:39
static const char * ssNull
Definition: UtlString.h:54
int UtlBoolean
Definition: UtlDefs.h:41
size_t last(char s) const
Find the last instance of a character.
Definition: UtlString.cpp:1037
UtlString & appendBinaryToString(const void *binaryData, int numBytes, int valuesPerRow=16)
Append binary data in human readable string format.
Definition: UtlString.cpp:300
#define TRUE
Definition: UtlDefs.h:25
size_t first(char c) const
Find the first instance of a single character.
Definition: UtlString.cpp:810
UtlString operator()(size_t start, size_t len) const
Allows references of the form stringVar(start,length) - also see append.
Definition: UtlString.cpp:1066
virtual UtlBoolean isEqual(UtlContainable const *) const
Definition: UtlString.cpp:1214
static const size_t UTLSTRING_NOT_FOUND
Returned from a search that failed.
Definition: UtlString.h:56
virtual ~UtlString()
Destructor.
Definition: UtlString.cpp:103