]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/SquidString.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 67 String */
11 #ifndef SQUID_STRING_H
12 #define SQUID_STRING_H
16 /* squid string placeholder (for printf) */
18 #define SQUIDSTRINGPH "%.*s"
19 #define SQUIDSTRINGPRINT(s) (s).psize(),(s).rawBuf()
20 #endif /* SQUIDSTRINGPH */
26 _SQUID_INLINE_
String();
28 String(String
const &);
31 typedef size_t size_type
; //storage size intentionally unspecified
32 const static size_type npos
= static_cast<size_type
>(-1);
34 String
&operator =(char const *);
35 String
&operator =(String
const &);
36 bool operator ==(String
const &) const;
37 bool operator !=(String
const &) const;
40 * Retrieve a single character in the string.
41 \param pos Position of character to retrieve.
43 _SQUID_INLINE_
char operator [](unsigned int pos
) const;
45 _SQUID_INLINE_ size_type
size() const;
46 /// variant of size() suited to be used for printf-alikes.
47 /// throws when size() > MAXINT
51 * Returns a raw pointer to the underlying backing store. The caller has been
52 * verified not to make any assumptions about null-termination
54 _SQUID_INLINE_
char const * rawBuf() const;
56 * Returns a raw pointer to the underlying backing store.
57 * The caller requires it to be null-terminated.
59 _SQUID_INLINE_
char const * termedBuf() const;
60 void limitInit(const char *str
, int len
); // TODO: rename to assign()
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);
66 void append(String
const &);
67 void absorb(String
&old
);
68 const char * pos(char const *aString
) const;
69 const char * pos(char const ch
) const;
70 ///offset from string start of the first occurrence of ch
71 /// returns String::npos if ch is not found
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;
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;
83 String
substr(size_type from
, size_type to
) const;
85 _SQUID_INLINE_
void cut(size_type newLength
);
88 void allocAndFill(const char *str
, int len
);
89 void allocBuffer(size_type sz
);
90 void setBuffer(char *buf
, size_type sz
);
92 bool defined() const {return buf_
!=NULL
;}
93 bool undefined() const {return !defined();}
95 _SQUID_INLINE_
bool nilCmp(bool, bool, int &) const;
97 /* never reference these directly! */
98 size_type size_
; /* buffer size; 64K limit */
100 size_type len_
; /* current length */
104 _SQUID_INLINE_
void set(char const *loc
, char const ch
);
105 _SQUID_INLINE_
void cutPointer(char const *loc
);
109 _SQUID_INLINE_
std::ostream
& operator<<(std::ostream
& os
, String
const &aString
);
111 _SQUID_INLINE_
bool operator<(const String
&a
, const String
&b
);
114 #include "String.cci"
117 const char *checkNullString(const char *p
);
118 int stringHasWhitespace(const char *);
119 int stringHasCntl(const char *);
120 char *strwordtok(char *buf
, char **t
);
122 #endif /* SQUID_STRING_H */