123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #ifndef STRUTIL_H
- #define STRUTIL_H
- #pragma once
- #include "config.h"
- #include <stddef.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <limits.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- /* c-string extension funtions */
- /**
- * search string in buffer,
- * memstr : buffer search, case sensitive
- * memistr : buffer search, case insensitive
- */
- TOOLKIT_API const char *memstr(const char *buf, int n, const char *str);
- TOOLKIT_API char *memstr1(char *buf, int n, const char *str);
- TOOLKIT_API const char *memrstr(const char *buf, int n, const char *str);
- TOOLKIT_API const char *memistr(const char *buf, int n, const char *str);
- TOOLKIT_API const char *memristr(const char *buf, int n, const char *str);
- #ifdef _WIN32
- TOOLKIT_API void* memmem(const void* haystack, size_t haystacklen,
- const void* needle, size_t needlelen);
- TOOLKIT_API char* strcasestr(const char* haystack, const char* needle);
- #endif //_WIN32
- /**
- * trim string inplace
- * strltrim : left trim
- * strrtrim : right trim
- * strtrim : both left and right trim
- * strnormws: removes white-space surrounding the string, and
- * converts all remaining groups of white-space to a single space.
- */
- TOOLKIT_API char *strtrim(char *s, const char *trims);
- TOOLKIT_API char *strltrim(char *s, const char *trims);
- TOOLKIT_API char *strrtrim(char *s, const char *trims);
- TOOLKIT_API char *strnormws(char *s);
- #ifdef _WIN32
- /**
- * copy string and return pointer to the end null-terminated char
- */
- TOOLKIT_API char* stpcpy(char* dst, const char* src);
- /**
- * string tokenize
- */
- TOOLKIT_API char* strsep(char** stringp, const char* delim);
- TOOLKIT_API char* strtok_r(char* str, const char* delim, char** tracker);
- #endif //_WIN32
- /**
- * replace occurrences of substring in string, return value should be freed by free
- */
- TOOLKIT_API char *strrepleace(const char *str, const char *oldstr, const char *newstr);
- /**
- * split string to string list, use strarrayfree to free memory
- */
- TOOLKIT_API char **strsplit(const char *s, const char *delim);
- TOOLKIT_API void strfreev(char **strings);
- /**
- * substring
- */
- TOOLKIT_API char *strsub(char *dest,char *src, size_t offset, size_t len);
- TOOLKIT_API char *strleft(char *dest,char *src, size_t len);
- TOOLKIT_API char *strright(char *dest,char *src, size_t len);
- /**
- * allocate a concatenation of strings, Use (char*)0, not NULL, to end the list of parameters.
- */
- TOOLKIT_API char * TOOLKIT_CC stralloc(const char *arg1, ...);
- TOOLKIT_API char * TOOLKIT_CC stralloca(const char *arg1, ...);
- /**
- * duplicate a memory buffer
- */
- TOOLKIT_API void *memdup(const void *buf, int len);
- TOOLKIT_API void *memdupa(const void *buf, int len);
- #ifdef _WIN32
- TOOLKIT_API char* strdupa(const char* str);
- /**
- * Duplicates the first @n bytes of a string, returning a newly-allocated
- * conflict with /usr/include/string.h
- */
- TOOLKIT_API char *strndup(const char *str, int n);
- #endif //_WIN32
- /**
- * Creates a new string @length bytes long filled with @fill_char.
- * Creates a new string @length bytes long filled with @fill_char.
- */
- TOOLKIT_API char* strnfill(int length, int fill_char);
- /**
- * Compares str1 and str2 like strcmp(). Handles NULL strings gracefully.
- */
- TOOLKIT_API int strcmp0 (const char *str1,const char *str2);
- /**
- * create a string from format list
- */
- TOOLKIT_API char* TOOLKIT_CC strdup_printf(const char *format, ...);
- TOOLKIT_API char* TOOLKIT_CC strdup_vprintf(const char *format, va_list args);
- /**
- * Copies src to dest;
- * dest is guaranteed to be nul-terminated;
- * src must be nul-terminated;
- * dest_size is the buffer size, not the number of chars to copy.
- * Caveat: strlcpy() is supposedly more secure than strcpy() or strncpy(),
- * but if you really want to avoid screwups, g_strdup() is an even better idea.
- */
- TOOLKIT_API size_t strlcpy(char *dest, const char *src, size_t size);
- TOOLKIT_API size_t strlcat(char *dest, const char *src, size_t size);
- TOOLKIT_API ssize_t strscpy(char* dest, const char* src, size_t size);
- /**
- * Copies NULL-terminated array of strings. The copy is a deep copy;
- * the new array should be freed by first freeing each string,
- * then the array itself. strfreev() does this for you.
- * If called on a NULL value, g_strdupv() simply returns NULL.
- */
- TOOLKIT_API char** strdupv (char **str_array);
- /**
- * Joins a number of strings together to form one long string,
- * with the optional separator inserted between each of them.
- * @return a newly-allocated string containing all of the strings joined together, with separator between them.
- */
- TOOLKIT_API char* strjoinv (const char *separator,char **str_array);
- TOOLKIT_API char* TOOLKIT_CC strjoin (const char *separator, ...);
- /**
- * Looks whether the string str ends with suffix.
- */
- TOOLKIT_API int str_has_suffix (const char *str, const char *suffix);
- /**
- * Looks whether the string str starts with prefix.
- */
- TOOLKIT_API int str_has_prefix (const char *str,const char *prefix);
- /**
- * Returns the length of the given NULL-terminated string array str_array.
- */
- TOOLKIT_API unsigned int strv_length (char **str_array);
- /** xml escape */
- TOOLKIT_API char *str_xml_escape(const char *src);
- /** parse cmd line */
- TOOLKIT_API void str_parse_cmdline (char *cmdstart,char **argv,char *args,int *numargs,int *numchars);
- TOOLKIT_API void str_get_format_uuid(char* strbuffer, size_t ulen);
- TOOLKIT_API int str_reset_buffer(void* pbuf, int idata, size_t ulen);
- TOOLKIT_API int str_rend_string(char* pSrc, int iflag);
- TOOLKIT_API int str_fifter_string(char* pbuf, size_t usize, const char* psrc, const char cflag);
- TOOLKIT_API int str_get_interger_netaddr(char* strbuf, size_t ubufszie, const char* szip);
- TOOLKIT_API int str_convert_interaddr_strip(char* strbuf, size_t ubufszie, const char* szinter_ip);
- TOOLKIT_API int str_connect_strings(char* strbuf, size_t ulen, const char* psrca, const char* psrcb, const char* pstr);
- #ifdef __cplusplus
- } // extern "C" {
- #endif
- #endif // STRUTIL_H
|