ucommon
7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc.. Fossies Dox: ucommon-7.0.0.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) 
|
Go to the documentation of this file. 19 #include <ucommon-config.h> 161 if(str < text || str > text +
len)
218 assert(format != NULL);
221 va_start(args, format);
264 this->cstring::~cstring();
300 const char *mystr =
"";
308 return strcmp(mystr, s) == 0;
316 const char *mystr =
"";
325 return strcoll(mystr, s);
327 return strcmp(mystr, s);
372 while(offset < str->
len) {
382 if(!
str || !clist || !*clist)
400 if(!
str || !clist || !*clist)
458 while(offset < str->
len) {
491 size_t tcl = strlen(substring);
495 #if defined(_MSWINDOWS_) 497 result = strstr(text, substring);
498 #elif defined(HAVE_STRICMP) 500 result = stristr(text, substring);
503 result = strcasestr(text, substring);
506 result = strstr(text, substring);
521 const char *
String::search(
const char *substring,
unsigned instance,
unsigned flags)
const 532 while(instance-- &&
result) {
533 #if defined(_MSWINDOWS_) 535 result = strstr(text, substring);
536 #elif defined(HAVE_STRICMP) 538 result = stristr(text, substring);
541 result = strcasestr(text, substring);
544 result = strstr(text, substring);
557 while(offset < str->
len) {
567 assert(clist != NULL);
615 return (
size_t)(s -
str->
text);
635 assert(format != NULL);
638 va_start(args, format);
650 assert(format != NULL);
660 #if !defined(_MSC_VER) 663 assert(format != NULL);
666 return vsscanf(
str->
text, format, args);
672 assert(format != NULL);
677 va_start(args, format);
679 rtn = vsscanf(
str->
text, format, args);
715 if(!s || !*s || !
str)
748 if(!s || !*s || !
str)
762 if(!s || !*s || !
str)
786 if(!s || !*s || !
str)
879 size_t len = strlen(text);
899 size_t len = strlen(text);
1177 String::operator bool()
const 1263 assert(mem != NULL);
1312 if(!
token || !clist)
1328 if(*
result && *eol && NULL != (eol = strchr(eol, *
result))) {
1329 if(eol[0] != eol[1] || *
result == eol[1]) {
1397 size_t len = strlen(cp) + 1;
1398 mem = (
char *)malloc(
len);
1415 mem = (
char *)malloc(++
size);
1427 size_t len = strlen(cp);
1454 size_t l1 = strlen(
str);
1455 size_t l2 = strlen(key);
1461 if(!strncmp(key,
str, l2)) {
1470 while(l1 >= l2 && !strchr(
delim, *
str)) {
1474 while(l1 >= l2 && strchr(
delim, *
str)) {
1484 size_t l1 = strlen(
str);
1485 size_t l2 = strlen(key);
1500 while(l1 >= l2 && !strchr(
delim, *
str)) {
1504 while(l1 >= l2 && strchr(
delim, *
str)) {
1523 size_t l = strlen(s);
1559 size_t l = strlen(s);
1582 size_t l = strlen(s);
1583 size_t o = strlen(
str);
1599 size_t o = strlen(
str);
1616 while(*
str && strchr(clist, *
str))
1681 memset(
str, 0, strlen(
str));
1688 if(strchr(clist, *(
str++)))
1699 while(*
str && strchr(clist, *
str))
1716 if(!strchr(clist,
str[--
len]))
1733 if(strchr(clist,
str[
pos]))
1749 if(strchr(clist, *
str))
1761 return str + strlen(
str);
1763 char *s =
str + strlen(
str);
1766 if(strchr(clist, *(--s)))
1783 return strcasecmp(s1, s2) == 0;
1798 return strncasecmp(s1, s2,
size) == 0;
1809 return strcmp(s1, s2) == 0;
1819 return strncmp(s1, s2,
size) == 0;
1830 return strcoll(s1, s2);
1832 return strcmp(s1, s2);
1839 assert(clist != NULL);
1846 if(*
str == clist[0] &&
str[
len - 1] == clist[1]) {
1868 if(
ch >=
'0' &&
ch <=
'9')
1870 else if(
ch >=
'A' &&
ch <=
'F')
1871 return ch -
'A' + 10;
1880 if(ws && isspace(*
str)) {
1899 while(format && *format) {
1900 while(*format && !isdigit(*format)) {
1904 if(isdigit(*format)) {
1905 skip = (unsigned)strtol(format, &ep, 10);
1916 char *buf =
out.data();
1918 snprintf(buf, 3,
"%02x", *(
binary++));
1930 while(format && *format) {
1931 while(*format && !isdigit(*format)) {
1932 *(
string++) = *(format++);
1935 if(isdigit(*format)) {
1936 skip = (unsigned)strtol(format, &ep, 10);
1940 snprintf(
string, 3,
"%02x", *(
binary++));
1955 if(ws && isspace(*
str)) {
1962 if(hi < 0 || lo < 0)
1964 *(bin++) = (hi << 4) | lo;
1979 while(format && *format) {
1980 while(*format && !isdigit(*format)) {
1981 if(*(
string++) != *(format++))
1985 if(isdigit(*format)) {
1986 skip = (unsigned)strtol(format, &ep, 10);
2000 unsigned long temp = USHRT_MAX + 1;
2007 if(
temp > USHRT_MAX)
2010 value = (
unsigned short)
temp;
2023 long temp = SHRT_MAX + 1;
2036 value = (short)
temp;
2054 value = strtol(
str->
text, &ep, 0);
2070 value = strtoul(
str->
text, &ep, 0);
2086 value = strtod(
str->
text, &ep);
2100 size_t len = strlen(
get);
2115 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2119 size_t dsize = (
size * 4 / 3) + 1;
2128 assert(dest != NULL && bin != NULL);
2135 if (!dsize || !
size)
2140 while(
size >= 3 && dsize > 4) {
2141 bits = (((unsigned)bin[0])<<16) | (((
unsigned)bin[1])<<8)
2142 | ((unsigned)bin[2]);
2147 *(dest++) =
alphabet[(bits >> 12) & 0x3f];
2148 *(dest++) =
alphabet[(bits >> 6) & 0x3f];
2153 if (
size && dsize > 4) {
2154 bits = ((unsigned)bin[0])<<16;
2158 *(dest++) =
alphabet[(bits >> 12) & 0x3f];
2163 bits |= ((unsigned)bin[1])<<8;
2164 *(dest++) =
alphabet[(bits >> 12) & 0x3f];
2165 *(dest++) =
alphabet[(bits >> 6) & 0x3f];
2177 return (
size * 4 / 3) + 4;
2188 for (i = 0; i < 256; ++i)
2191 for (i = 0; i < 64 ; ++i)
2204 c = (uint8_t)(*(src++));
2211 bits = (bits << 6) +
decoder[c];
2212 if (bits & 0x1000000) {
2220 else if (bits & 0x1000)
2234 for (i = 0; i < 256; ++i)
2237 for (i = 0; i < 64 ; ++i)
2251 c = (uint8_t)(*(src++));
2263 bits = (bits << 6) +
decoder[c];
2264 if (bits & 0x1000000) {
2269 *(dest++) = (uint8_t)((bits >> 16) & 0xff);
2270 *(dest++) = (uint8_t)((bits >> 8) & 0xff);
2271 *(dest++) = (uint8_t)((bits & 0xff));
2276 if (bits & 0x40000) {
2278 *(dest++) = (uint8_t)((bits >> 10) & 0xff);
2279 *(dest++) = (uint8_t)((bits >> 2) & 0xff);
2282 else if ((bits & 0x1000) &&
size) {
2283 *(dest++) = (uint8_t)((bits >> 4) & 0xff);
2288 #define CRC24_INIT 0xb704ceL 2289 #define CRC24_POLY 0x1864cfbL 2297 crc ^= (*
binary++) << 16;
2298 for (i = 0; i < 8; i++) {
2300 if (crc & 0x1000000)
2304 return crc & 0xffffffL;
2309 uint16_t crc = 0xffff;
2314 for (i = 0; i < 8; i++) {
2316 crc = (crc >> 1) ^ 0xa001;
void trim(const char *list)
String & operator++(void)
static size_t b64encode(char *string, const uint8_t *binary, size_t size, size_t width=0)
static size_t b64decode(uint8_t *binary, const char *string, size_t size, bool ws=false)
static size_t b64size(size_t size)
static shell::charopt delim('d', "--delim", _TEXT("set deliminter between arguments"))
static memstring * create(size_t size)
virtual cstring * c_copy(void) const
void cut(size_t offset, size_t size=0)
int scanf(const char *format,...) __SCANF(2
void set(size_t offset, const char *text, size_t size)
int strnicmp(const char *s1, const char *s2, size_t size)
static size_t hexcount(const char *str, bool ws=false)
static uint16_t crc16(uint8_t *binary, size_t size)
static String b64(const uint8_t *binary, size_t size)
char at(int position) const
static shell::stringopt out('o', "--output", _TEXT("output file"), "filename", "-")
static size_t hex2bin(const char *string, uint8_t *binary, size_t maxsize, bool wsflag=false)
size_t offset(const char *pointer) const
String left(size_t size) const
bool is_copied(void) const
bool operator<=(const char *text) const
static void fix(String &object)
bool operator==(const char *text) const
void release(void) __FINAL
static void swap(String &object1, String &object2)
const char operator[](int offset) const
const char * rfind(const char *list, size_t offset=npos) const
static int hexcode(char ch)
const char * rskip(const char *list, size_t offset=npos) const
void chop(const char *list)
String & operator%(short &value)
static void result(const char *path, int code)
void rset(const char *text, char overflow, size_t offset, size_t size=0)
const char * begin(void) const
static void adj(struct timeval *ts)
int int size_t size_t vprintf(const char *format, va_list args) __PRINTF(2
unsigned replace(const char *string, const char *text=NULL, unsigned flags=0)
virtual void release(void) __OVERRIDE
const char * find(const char *list, size_t offset=0) const
const char * search(const char *string, unsigned instance=0, unsigned flags=0) const
int int vscanf(const char *format, va_list args) __SCANF(2
static const char * pos(const char *text, ssize_t offset)
static bool eq_case(const char *text1, const char *text2)
static shell::stringopt quote('q', "--quote", _TEXT("set quote for each argument"), "string", "")
String & operator-=(size_t number)
String & operator=(const String &object)
String get(size_t offset, size_t size=0) const
bool operator!=(const char *text) const
static bool check(const char *string, size_t maximum, size_t minimum=0)
const char * skip(const char *list, size_t offset=0) const
void strip(const char *list)
void cow(size_t adj=0) __FINAL
int int size_t size_t char * data(void)
static String hex(const uint8_t *binary, size_t size)
virtual void retain(void) __OVERRIDE
String & operator&=(const char *text)
void split(const char *pointer)
const char * end(void) const
int stricmp(const char *s1, const char *s2)
String & operator|=(const char *text)
static char * token(char *text, char **last, const char *list, const char *quote=NULL, const char *end=NULL)
bool eq(const struct sockaddr *s1, const struct sockaddr *s2)
virtual bool resize(size_t size)
void add(const char *text)
void set(const char *text)
const String operator+(const char *text) const
static size_t hexdump(const uint8_t *binary, char *string, const char *format)
memstring(void *memory, size_t size)
bool equal(const char *string) const
bool operator>=(const char *text) const
void retain(void) __OVERRIDE
const char * rchr(char character) const
cstring * c_copy(void) const __OVERRIDE
String & operator&(const char *text)
void fill(size_t size, char fill)
String & operator--(void)
int int size_t printf(const char *format,...) __PRINTF(2
bool operator<(const char *text) const
const char * chr(char character) const
void add(const char *text)
virtual int compare(const char *string) const
static size_t hexsize(const char *format)
void * alloc(size_t size)
static const uint8_t alphabet[65]
static const char * ifind(const char *text, const char *key, const char *optional)
bool resize(size_t size) __FINAL
static size_t b64count(const char *str, bool ws=false)
virtual void cow(size_t size=0)
static size_t seek(char *text, const char *list)
static uint32_t crc24(uint8_t *binary, size_t size)
void rsplit(const char *pointer)
bool unquote(const char *quote)
const char * c_str(void) const
size_t ccount(const char *list) const
String & operator+=(const char *text)
void paste(size_t offset, const char *text, size_t size=0)
static char * dup(const char *text)
void clear(size_t offset)
String operator()(int offset, size_t size) const
void release(void) __OVERRIDE
static size_t hexpack(uint8_t *binary, const char *string, const char *format)
bool operator>(const char *text) const
bool operator*=(const char *substring)
cstring * create(size_t size) const
String & operator^=(const String &object)
virtual void dealloc(void) __OVERRIDE
String & operator|(const char *text)