2001-10-06 14:13:28 +00:00
|
|
|
#ifndef CSTRING_H
|
|
|
|
#define CSTRING_H
|
|
|
|
|
2002-07-25 17:23:35 +00:00
|
|
|
#include <stdarg.h>
|
2002-06-01 19:26:11 +00:00
|
|
|
#include "stdpre.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
#include <string>
|
2002-06-01 19:26:11 +00:00
|
|
|
#include "stdpost.h"
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
typedef std::string CString;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-06-03 16:34:22 +00:00
|
|
|
class CStringUtil {
|
|
|
|
public:
|
2002-07-25 17:23:35 +00:00
|
|
|
// format a string using positional arguments. fmt has literal
|
|
|
|
// characters and conversion specifications introduced by `%':
|
|
|
|
// %% literal `%'
|
|
|
|
// %{n} positional element n, n a positive integer, {} are literal
|
|
|
|
// all arguments in the variable list are const char*. positional
|
|
|
|
// elements are indexed from 1.
|
|
|
|
static CString format(const char* fmt, ...);
|
|
|
|
static CString vformat(const char* fmt, va_list);
|
|
|
|
|
|
|
|
// print a string using printf-style formatting
|
|
|
|
static CString print(const char* fmt, ...);
|
|
|
|
static CString vprint(const char* fmt, va_list);
|
|
|
|
|
|
|
|
// like print but print into a given buffer. if the resulting string
|
|
|
|
// will not fit into the buffer then a new buffer is allocated and
|
|
|
|
// returned, otherwise the input buffer is returned. the caller must
|
|
|
|
// delete[] the returned buffer if is not the passed-in buffer.
|
|
|
|
//
|
|
|
|
// prefix and suffix must be >= 0. exactly prefix characters and
|
|
|
|
// at least suffix characters are available in the buffer before
|
|
|
|
// and after the printed string, respectively. bufferLength is the
|
|
|
|
// length of buffer and should not be adjusted by the caller to
|
|
|
|
// account for prefix or suffix.
|
|
|
|
static char* vsprint(char* buffer, int bufferLength,
|
|
|
|
int prefix, int suffix, const char* fmt, va_list);
|
|
|
|
|
2002-06-03 16:34:22 +00:00
|
|
|
class CaselessCmp {
|
|
|
|
public:
|
|
|
|
bool operator()(const CString&, const CString&) const;
|
|
|
|
static bool less(const CString&, const CString&);
|
|
|
|
static bool equal(const CString&, const CString&);
|
|
|
|
static bool cmpLess(const CString::value_type&,
|
2002-06-10 22:06:45 +00:00
|
|
|
const CString::value_type&);
|
2002-06-03 16:34:22 +00:00
|
|
|
static bool cmpEqual(const CString::value_type&,
|
2002-06-10 22:06:45 +00:00
|
|
|
const CString::value_type&);
|
2002-06-03 16:34:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
#endif
|
|
|
|
|