27 String::String(
const char *p_str) : m_pBuffer(NULL), m_nBufSize(0), m_tokPtr(NULL)
29 int nlen = strlen(p_str);
31 memcpy(m_pBuffer, p_str, nlen + 1);
33 String::String(
const char* p_str,
int nLen) :m_pBuffer(NULL), m_nBufSize(0), m_tokPtr(NULL)
36 nLen = min(nLen, (
int)strlen(p_str));
37 memcpy(m_pBuffer, p_str, nLen);
38 m_pBuffer[nLen] =
'\0';
48 Reset(p_str.m_nBufSize);
49 memcpy(m_pBuffer, p_str.m_pBuffer, m_nBufSize);
58 if (nLen > m_nBufSize) {
59 char *pNew =
new char[nLen];
61 memcpy(pNew, m_pBuffer,
sizeof(
char)*m_nBufSize);
73 va_start(vaParams, p_pMessage);
77 int nLen = strlen(strBuffer);
79 memcpy(m_pBuffer, strBuffer,
sizeof(
char)*(nLen + 1));
85 Reset(p_str.m_nBufSize);
86 memcpy(m_pBuffer, p_str.m_pBuffer, p_str.m_nBufSize);
91 int nLen = strlen(pStr);
93 memcpy(m_pBuffer, pStr, nLen + 1);
97 m_pBuffer[nLocal] =
'\0';
98 *
this += m_pBuffer + nLocal + nLen;
102 char *p = strstr(m_pBuffer, sub);
104 return p - m_pBuffer;
110 int nLocal =
Find(src);
115 String strnew(m_pBuffer, nLocal);
116 return strnew + rpl + &m_pBuffer[nLocal + strlen(src)];
120 m_tokPtr = m_pBuffer;
125 if (*m_tokPtr ==
'\0')
129 for (; *m_tokPtr !=
'\0'; m_tokPtr++)
133 if (NULL == strchr(p, *m_tokPtr)) {
139 if (strchr(p, *m_tokPtr)) {
151 char *psave = strdup(m_pBuffer);
154 char *p = strtok(psave, delimiter);
157 p = strtok(NULL, delimiter);
164 char *p = strrchr(m_pBuffer,
'.');
166 return String(m_pBuffer, p - m_pBuffer);
173 while (*p = toupper(*p))
180 while (*p = tolower(*p))
String(int p_nLen=cn_default_str_len)
store the top pointer. used in
const char * Format(const char *p_pMessage,...)
format print to string
void Split(Array< String > &aStrs, const char *delimiter)
split to string array. Using strtok().
const int cn_default_max_len
default maximum length
String Replace(const char *src, const char *rpl)
replace
void operator=(const String &p_str)
operator =
char * Reset(int nLen)
Reset the string leng.
void Clean()
Clean the array. Just set the top of array to -1 and donot release the memory.
void Add(T t)
Add a value to the tail of array.
char * TokSub(const char *p)
split next
void DeleteSub(int nLocal, int nLen)
delete a sub-string
char * TokBegin(const char *p)
split begin
String FileName()
if the string is a path, this function return the file name.
int Find(const char *sub)
Find.
define all the code written by Bin Wang.