]>
Commit | Line | Data |
---|---|---|
0f15e632 | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
0f15e632 | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
0f15e632 | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 67 String */ |
10 | ||
0f15e632 | 11 | #ifndef SQUID_STRING_H |
12 | #define SQUID_STRING_H | |
13 | ||
e1f7507e AJ |
14 | #include <ostream> |
15 | ||
bb790702 FC |
16 | /* squid string placeholder (for printf) */ |
17 | #ifndef SQUIDSTRINGPH | |
18 | #define SQUIDSTRINGPH "%.*s" | |
b716b3d4 | 19 | #define SQUIDSTRINGPRINT(s) (s).psize(),(s).rawBuf() |
bb790702 FC |
20 | #endif /* SQUIDSTRINGPH */ |
21 | ||
30abd221 | 22 | class String |
23 | { | |
0353e724 | 24 | |
30abd221 | 25 | public: |
26 | _SQUID_INLINE_ String(); | |
9e9ef416 RP |
27 | String(char const *); |
28 | String(String const &); | |
30abd221 | 29 | ~String(); |
30 | ||
b4197865 | 31 | typedef size_t size_type; //storage size intentionally unspecified |
556bfec0 | 32 | const static size_type npos = static_cast<size_type>(-1); |
a7a42b14 | 33 | |
30abd221 | 34 | String &operator =(char const *); |
35 | String &operator =(String const &); | |
36 | bool operator ==(String const &) const; | |
37 | bool operator !=(String const &) const; | |
38 | ||
3db44fdf | 39 | /** |
40 | * Retrieve a single character in the string. | |
f53969cc | 41 | \param pos Position of character to retrieve. |
3db44fdf | 42 | */ |
4ce0e99b | 43 | _SQUID_INLINE_ char operator [](unsigned int pos) const; |
3db44fdf | 44 | |
a7a42b14 | 45 | _SQUID_INLINE_ size_type size() const; |
9b558d8a FC |
46 | /// variant of size() suited to be used for printf-alikes. |
47 | /// throws when size() > MAXINT | |
696a257c | 48 | int psize() const; |
99524de7 | 49 | |
99524de7 FC |
50 | /** |
51 | * Returns a raw pointer to the underlying backing store. The caller has been | |
52 | * verified not to make any assumptions about null-termination | |
53 | */ | |
54 | _SQUID_INLINE_ char const * rawBuf() const; | |
55 | /** | |
56 | * Returns a raw pointer to the underlying backing store. | |
57 | * The caller requires it to be null-terminated. | |
58 | */ | |
59 | _SQUID_INLINE_ char const * termedBuf() const; | |
e7e1bf60 | 60 | void limitInit(const char *str, int len); // TODO: rename to assign() |
30abd221 | 61 | void clean(); |
62 | void reset(char const *str); | |
63 | void append(char const *buf, int len); | |
64 | void append(char const *buf); | |
65 | void append(char const); | |
9e9ef416 | 66 | void append(String const &); |
30abd221 | 67 | void absorb(String &old); |
826a1fed FC |
68 | const char * pos(char const *aString) const; |
69 | const char * pos(char const ch) const; | |
b4f2886c | 70 | ///offset from string start of the first occurrence of ch |
2c1fd837 | 71 | /// returns String::npos if ch is not found |
826a1fed FC |
72 | size_type find(char const ch) const; |
73 | size_type find(char const *aString) const; | |
74 | const char * rpos(char const ch) const; | |
75 | size_type rfind(char const ch) const; | |
9e9ef416 RP |
76 | _SQUID_INLINE_ int cmp(char const *) const; |
77 | _SQUID_INLINE_ int cmp(char const *, size_type count) const; | |
78 | _SQUID_INLINE_ int cmp(String const &) const; | |
79 | _SQUID_INLINE_ int caseCmp(char const *) const; | |
80 | _SQUID_INLINE_ int caseCmp(char const *, size_type count) const; | |
81 | _SQUID_INLINE_ int caseCmp(String const &) const; | |
30abd221 | 82 | |
a7a42b14 | 83 | String substr(size_type from, size_type to) const; |
9b558d8a | 84 | |
a7a42b14 | 85 | _SQUID_INLINE_ void cut(size_type newLength); |
30abd221 | 86 | |
30abd221 | 87 | private: |
e7e1bf60 | 88 | void allocAndFill(const char *str, int len); |
a7a42b14 FC |
89 | void allocBuffer(size_type sz); |
90 | void setBuffer(char *buf, size_type sz); | |
e7e1bf60 | 91 | |
b38b26cb AJ |
92 | bool defined() const {return buf_!=NULL;} |
93 | bool undefined() const {return !defined();} | |
94 | ||
15267b22 AR |
95 | _SQUID_INLINE_ bool nilCmp(bool, bool, int &) const; |
96 | ||
30abd221 | 97 | /* never reference these directly! */ |
a7a42b14 | 98 | size_type size_; /* buffer size; 64K limit */ |
30abd221 | 99 | |
a7a42b14 | 100 | size_type len_; /* current length */ |
30abd221 | 101 | |
102 | char *buf_; | |
9b558d8a FC |
103 | |
104 | _SQUID_INLINE_ void set(char const *loc, char const ch); | |
105 | _SQUID_INLINE_ void cutPointer(char const *loc); | |
106 | ||
30abd221 | 107 | }; |
108 | ||
109 | _SQUID_INLINE_ std::ostream & operator<<(std::ostream& os, String const &aString); | |
110 | ||
634592a6 FC |
111 | _SQUID_INLINE_ bool operator<(const String &a, const String &b); |
112 | ||
32d002cb | 113 | #if _USE_INLINE_ |
30abd221 | 114 | #include "String.cci" |
115 | #endif | |
0f15e632 | 116 | |
8a648e8d FC |
117 | const char *checkNullString(const char *p); |
118 | int stringHasWhitespace(const char *); | |
119 | int stringHasCntl(const char *); | |
120 | char *strwordtok(char *buf, char **t); | |
0875c529 | 121 | |
0f15e632 | 122 | #endif /* SQUID_STRING_H */ |
f53969cc | 123 |