kcutil.h   kcutil.h 
skipping to change at line 338 skipping to change at line 338
* Split a string with delimiters. * Split a string with delimiters.
* @param str the string. * @param str the string.
* @param delims the delimiters. * @param delims the delimiters.
* @param elems a vector object into which the result elements are pushed. * @param elems a vector object into which the result elements are pushed.
* @return the number of result elements. * @return the number of result elements.
*/ */
size_t strsplit(const std::string& str, const std::string& delims, size_t strsplit(const std::string& str, const std::string& delims,
std::vector<std::string>* elems); std::vector<std::string>* elems);
/** /**
* Convert the letters of a string into upper case.
* @param str the string to convert.
* @return the string itself.
*/
std::string* strtoupper(std::string* str);
/**
* Convert the letters of a string into lower case.
* @param str the string to convert.
* @return the string itself.
*/
std::string* strtolower(std::string* str);
/**
* Cut space characters at head or tail of a string.
* @param str the string to convert.
* @return the string itself.
*/
std::string* strtrim(std::string* str);
/**
* Convert a UTF-8 string into a UCS-4 vector. * Convert a UTF-8 string into a UCS-4 vector.
* @param src the source object. * @param src the source object.
* @param dest the destination object. * @param dest the destination object.
*/ */
void strutftoucs(const std::string& src, std::vector<uint32_t>* dest); void strutftoucs(const std::string& src, std::vector<uint32_t>* dest);
/** /**
* Convert a UCS-4 vector into a UTF-8 string. * Convert a UCS-4 vector into a UTF-8 string.
* @param src the source object. * @param src the source object.
* @param dest the destination object. * @param dest the destination object.
skipping to change at line 493 skipping to change at line 514
/** /**
* Duplicate a region on memory. * Duplicate a region on memory.
* @param ptr the source buffer. * @param ptr the source buffer.
* @param size the size of the source buffer. * @param size the size of the source buffer.
* @note Because the region of the return value is allocated with the the n ew[] operator, it * @note Because the region of the return value is allocated with the the n ew[] operator, it
* should be released with the delete[] operator when it is no longer in us e. * should be released with the delete[] operator when it is no longer in us e.
*/ */
char* memdup(const char* ptr, size_t size); char* memdup(const char* ptr, size_t size);
/** /**
* Compare two regions by case insensitive evaluation.
* @param abuf a buffer.
* @param bbuf the other buffer.
* @param size the size of each buffer.
* @return positive if the former is big, negative if the latter is big, 0
if both are
* equivalent.
*/
int32_t memicmp(const void* abuf, const void* bbuf, size_t size);
/**
* Find the first occurrence of a sub pattern.
* @param hbuf the target pattern buffer.
* @param hsiz the size of the target pattern buffer.
* @param nbuf the sub pattern buffer.
* @param nsiz the size of the sub pattern buffer.
* @return the pointer to the beginning of the sub pattern in the target pa
ttern buffer, or NULL
* if the sub pattern is not found.
*/
void* memmem(const void* hbuf, size_t hsiz, const void* nbuf, size_t nsiz);
/**
* Find the first occurrence of a sub pattern by case insensitive evaluatio
n.
* @param hbuf the target pattern buffer.
* @param hsiz the size of the target pattern buffer.
* @param nbuf the sub pattern buffer.
* @param nsiz the size of the sub pattern buffer.
* @return the pointer to the beginning of the sub pattern in the target pa
ttern buffer, or NULL
* if the sub pattern is not found.
*/
void* memimem(const void* hbuf, size_t hsiz, const void* nbuf, size_t nsiz)
;
/**
* Duplicate a string on memory. * Duplicate a string on memory.
* @param str the source string. * @param str the source string.
* @note Because the region of the return value is allocated with the the n ew[] operator, it * @note Because the region of the return value is allocated with the the n ew[] operator, it
* should be released with the delete[] operator when it is no longer in us e. * should be released with the delete[] operator when it is no longer in us e.
*/ */
char* strdup(const char* str); char* strdup(const char* str);
/** /**
* Convert the letters of a string into upper case. * Convert the letters of a string into upper case.
* @param str the string to convert. * @param str the string to convert.
skipping to change at line 536 skipping to change at line 589
char* strsqzspc(char* str); char* strsqzspc(char* str);
/** /**
* Normalize space characters in a string and trim it. * Normalize space characters in a string and trim it.
* @param str the string to convert. * @param str the string to convert.
* @return the string itself. * @return the string itself.
*/ */
char* strnrmspc(char* str); char* strnrmspc(char* str);
/** /**
* Compare two strings with case insensitive evaluation. * Compare two strings by case insensitive evaluation.
* @param astr a string. * @param astr a string.
* @param bstr the other string. * @param bstr the other string.
* @return positive if the former is big, negative if the latter is big, 0 if both are * @return positive if the former is big, negative if the latter is big, 0 if both are
* equivalent. * equivalent.
*/ */
int32_t stricmp(const char* astr, const char* bstr); int32_t stricmp(const char* astr, const char* bstr);
/** /**
* Find the first occurrence of a substring by case insensitive evaluation.
* @param hstr the target string.
* @param nstr the substring.
* @return the pointer to the beginning of the substring in the target stri
ng, or NULL if the
* substring is not found.
*/
char* stristr(const char* hstr, const char* nstr);
/**
* Check whether a string begins with a key. * Check whether a string begins with a key.
* @param str the string. * @param str the string.
* @param key the forward matching key string. * @param key the forward matching key string.
* @return true if the target string begins with the key, else, it is false . * @return true if the target string begins with the key, else, it is false .
*/ */
bool strfwm(const char* str, const char* key); bool strfwm(const char* str, const char* key);
/** /**
* Check whether a string begins with a key by case insensitive evaluation. * Check whether a string begins with a key by case insensitive evaluation.
* @param str the string. * @param str the string.
skipping to change at line 1441 skipping to change at line 1503
break; break;
} }
++it; ++it;
} }
std::string col(pv, it); std::string col(pv, it);
elems->push_back(col); elems->push_back(col);
return elems->size(); return elems->size();
} }
/** /**
* Convert the letters of a string into upper case.
*/
inline std::string* strtoupper(std::string* str) {
_assert_(str);
size_t size = str->size();
for (size_t i = 0; i < size; i++) {
int32_t c = (unsigned char)(*str)[i];
if (c >= 'a' && c <= 'z') (*str)[i] = c - ('a' - 'A');
}
return str;
}
/**
* Convert the letters of a string into lower case.
*/
inline std::string* strtolower(std::string* str) {
_assert_(str);
size_t size = str->size();
for (size_t i = 0; i < size; i++) {
int32_t c = (unsigned char)(*str)[i];
if (c >= 'A' && c <= 'Z') (*str)[i] = c + ('a' - 'A');
}
return str;
}
/**
* Cut space characters at head or tail of a string.
*/
inline std::string* strtrim(std::string* str) {
_assert_(str);
size_t size = str->size();
size_t wi = 0;
size_t li = 0;
for (size_t i = 0; i < size; i++) {
int32_t c = (unsigned char)(*str)[i];
if (c >= '\0' && c <= ' ') {
if (wi > 0) (*str)[wi++] = c;
} else {
(*str)[wi++] = c;
li = wi;
}
}
str->resize(li);
return str;
}
/**
* Convert a UTF-8 string into a UCS-4 vector. * Convert a UTF-8 string into a UCS-4 vector.
*/ */
inline void strutftoucs(const std::string& src, std::vector<uint32_t>* dest ) { inline void strutftoucs(const std::string& src, std::vector<uint32_t>* dest ) {
_assert_(dest); _assert_(dest);
const unsigned char* rp = (unsigned char*)src.c_str(); const unsigned char* rp = (unsigned char*)src.c_str();
while (*rp != '\0') { while (*rp != '\0') {
uint32_t c = *(unsigned char*)rp; uint32_t c = *(unsigned char*)rp;
if (c < 0x80) { if (c < 0x80) {
dest->push_back(c); dest->push_back(c);
} else if (c < 0xe0) { } else if (c < 0xe0) {
skipping to change at line 1994 skipping to change at line 2103
* Duplicate a region on memory. * Duplicate a region on memory.
*/ */
inline char* memdup(const char* ptr, size_t size) { inline char* memdup(const char* ptr, size_t size) {
_assert_(ptr && size <= MEMMAXSIZ); _assert_(ptr && size <= MEMMAXSIZ);
char* obuf = new char[size+1]; char* obuf = new char[size+1];
std::memcpy(obuf, ptr, size); std::memcpy(obuf, ptr, size);
return obuf; return obuf;
} }
/** /**
* Compare two regions by case insensitive evaluation.
*/
inline int32_t memicmp(const void* abuf, const void* bbuf, size_t size) {
_assert_(abuf && bbuf && size <= MEMMAXSIZ);
const unsigned char* ap = (unsigned char*)abuf;
const unsigned char* bp = (unsigned char*)bbuf;
const unsigned char* ep = ap + size;
while (ap < ep) {
int32_t ac = *ap;
if (ac >= 'A' && ac <= 'Z') ac += 'a' - 'A';
int32_t bc = *bp;
if (bc >= 'A' && bc <= 'Z') bc += 'a' - 'A';
if (ac != bc) return ac - bc;
ap++;
bp++;
}
return 0;
}
/**
* Find the first occurrence of a sub pattern.
*/
inline void* memmem(const void* hbuf, size_t hsiz, const void* nbuf, size_t
nsiz) {
_assert_(hbuf && hsiz <= MEMMAXSIZ && nbuf && nsiz <= MEMMAXSIZ);
if (nsiz < 1) return (void*)hbuf;
if (hsiz < nsiz) return NULL;
int32_t tc = *(unsigned char*)nbuf;
const unsigned char* rp = (unsigned char*)hbuf;
const unsigned char* ep = (unsigned char*)hbuf + hsiz - nsiz;
while (rp <= ep) {
if (*rp == tc) {
bool hit = true;
for (size_t i = 1; i < nsiz; i++) {
if (rp[i] != ((unsigned char*)nbuf)[i]) {
hit = false;
break;
}
}
if (hit) return (void*)rp;
}
rp++;
}
return NULL;
}
/**
* Find the first occurrence of a sub pattern by case insensitive evaluatio
n.
*/
inline void* memimem(const void* hbuf, size_t hsiz, const void* nbuf, size_
t nsiz) {
_assert_(hbuf && hsiz <= MEMMAXSIZ && nbuf && nsiz <= MEMMAXSIZ);
if (nsiz < 1) return (void*)hbuf;
if (hsiz < nsiz) return NULL;
int32_t tc = *(unsigned char*)nbuf;
if (tc >= 'A' && tc <= 'Z') tc += 'a' - 'A';
const unsigned char* rp = (unsigned char*)hbuf;
const unsigned char* ep = (unsigned char*)hbuf + hsiz - nsiz;
while (rp <= ep) {
int32_t cc = *rp;
if (cc >= 'A' && cc <= 'Z') cc += 'a' - 'A';
if (cc == tc) {
bool hit = true;
for (size_t i = 1; i < nsiz; i++) {
int32_t hc = rp[i];
if (hc >= 'A' && hc <= 'Z') hc += 'a' - 'A';
int32_t nc = ((unsigned char*)nbuf)[i];
if (nc >= 'A' && nc <= 'Z') nc += 'a' - 'A';
if (hc != nc) {
hit = false;
break;
}
}
if (hit) return (void*)rp;
}
rp++;
}
return NULL;
}
/**
* Duplicate a string on memory. * Duplicate a string on memory.
*/ */
inline char* strdup(const char* str) { inline char* strdup(const char* str) {
_assert_(str); _assert_(str);
size_t size = std::strlen(str); size_t size = std::strlen(str);
char* obuf = memdup(str, size); char* obuf = memdup(str, size);
obuf[size] = '\0'; obuf[size] = '\0';
return obuf; return obuf;
} }
skipping to change at line 2113 skipping to change at line 2301
if (*wp == ' ') { if (*wp == ' ') {
*wp = '\0'; *wp = '\0';
} else { } else {
break; break;
} }
} }
return str; return str;
} }
/** /**
* Compare two strings with case insensitive evaluation. * Compare two strings by case insensitive evaluation.
*/ */
inline int32_t stricmp(const char* astr, const char* bstr) { inline int32_t stricmp(const char* astr, const char* bstr) {
_assert_(astr && bstr); _assert_(astr && bstr);
while (*astr != '\0') { while (*astr != '\0') {
if (*bstr == '\0') return 1; if (*bstr == '\0') return 1;
int32_t ac = (*astr >= 'A' && *astr <= 'Z') ? *astr + ('a' - 'A') : *(u int32_t ac = *(unsigned char*)astr;
nsigned char*)astr; if (ac >= 'A' && ac <= 'Z') ac += 'a' - 'A';
int32_t bc = (*bstr >= 'A' && *bstr <= 'Z') ? *bstr + ('a' - 'A') : *(u int32_t bc = *(unsigned char*)bstr;
nsigned char*)bstr; if (bc >= 'A' && bc <= 'Z') bc += 'a' - 'A';
if (ac != bc) return ac - bc; if (ac != bc) return ac - bc;
astr++; astr++;
bstr++; bstr++;
} }
return (*bstr == '\0') ? 0 : -1; return (*bstr == '\0') ? 0 : -1;
} }
/** /**
* Find the first occurrence of a substring by case insensitive evaluation.
*/
inline char* stristr(const char* hstr, const char* nstr) {
_assert_(hstr && nstr);
if (*nstr == '\0') return (char*)hstr;
int32_t tc = *nstr;
if (tc >= 'A' && tc <= 'Z') tc += 'a' - 'A';
const char* rp = hstr;
while (*rp != '\0') {
int32_t cc = *rp;
if (cc >= 'A' && cc <= 'Z') cc += 'a' - 'A';
if (cc == tc) {
bool hit = true;
for (size_t i = 1; nstr[i] != '\0'; i++) {
int32_t hc = rp[i];
if (hc >= 'A' && hc <= 'Z') hc += 'a' - 'A';
int32_t nc = nstr[i];
if (nc >= 'A' && nc <= 'Z') nc += 'a' - 'A';
if (hc != nc) {
hit = false;
break;
}
}
if (hit) return (char*)rp;
}
rp++;
}
return NULL;
}
/**
* Check whether a string begins with a key. * Check whether a string begins with a key.
*/ */
inline bool strfwm(const char* str, const char* key) { inline bool strfwm(const char* str, const char* key) {
_assert_(str && key); _assert_(str && key);
while (*key != '\0') { while (*key != '\0') {
if (*str != *key || *str == '\0') return false; if (*str != *key || *str == '\0') return false;
key++; key++;
str++; str++;
} }
return true; return true;
 End of changes. 9 change blocks. 
6 lines changed or deleted 234 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/