00001 #ifndef STR__H__
00002 #define STR__H__
00003
00022 #define STR_BLOCKSIZE 16
00023
00027 struct str
00028 {
00033 char* s;
00037 unsigned len;
00039 unsigned size;
00040 };
00041 typedef struct str str;
00042
00047 struct str_sortentry
00048 {
00049 const char* str;
00050 unsigned long len;
00051 };
00052 typedef struct str_sortentry str_sortentry;
00053
00056 extern const char str_lcase_digits[36];
00057 extern const char str_ucase_digits[36];
00058
00059
00062 int str_init(str* s);
00063 int str_alloc(str* s, unsigned size, int copy);
00065 #define str_ready(S,SZ) str_alloc(S,SZ,0)
00066
00067 #define str_realloc(S,SZ) str_alloc(S,SZ,1)
00068 void str_free(str* s);
00069 int str_truncate(str* s, unsigned len);
00070
00071
00074 int str_copy(str* s, const str* in);
00075 int str_copys(str* s, const char* in);
00076 int str_copyb(str* s, const char* in, unsigned len);
00077 int str_copy2s(str* s, const char* a, const char* b);
00078 int str_copy3s(str* s, const char* a, const char* b, const char* c);
00079 int str_copy4s(str* s, const char* a, const char* b, const char* c, const char* d);
00080 int str_copy5s(str* s, const char* a, const char* b, const char* c, const char* d, const char* e);
00081 int str_copy6s(str* s, const char* a, const char* b, const char* c, const char* d, const char* e, const char* f);
00082
00083
00086 int str_cat(str* s, const str* in);
00087 int str_cats(str* s, const char* in);
00088 int str_catc(str* s, char in);
00089 int str_catb(str* s, const char* in, unsigned len);
00090 int str_cati(str* s, long in);
00091 int str_catiw(str* s, long in, unsigned width, char pad);
00092 int str_catu(str* s, unsigned long in);
00093 int str_catuw(str* s, unsigned long in, unsigned width, char pad);
00094 int str_catx(str* s, unsigned long in);
00095 int str_catxw(str* s, unsigned long in, unsigned width, char pad);
00096 int str_catill(str* s, long long in);
00097 int str_catiwll(str* s, long long in, unsigned width, char pad);
00098 int str_catull(str* s, unsigned long long in);
00099 int str_catuwll(str* s, unsigned long long in, unsigned width, char pad);
00100 int str_catxll(str* s, unsigned long long in);
00101 int str_catxwll(str* s, unsigned long long in, unsigned width, char pad);
00102 int str_catsnumw(str* s, long in, unsigned width, char pad,
00103 unsigned base, const char* digits);
00104 int str_catunumw(str* s, unsigned long in, unsigned width, char pad,
00105 unsigned base, const char* digits);
00106 int str_catsllnumw(str* s, long long in, unsigned width, char pad,
00107 unsigned base, const char* digits);
00108 int str_catullnumw(str* s, unsigned long long in, unsigned width, char pad,
00109 unsigned base, const char* digits);
00110 int str_cat2s(str* s, const char* a, const char* b);
00111 int str_cat3s(str* s, const char* a, const char* b, const char* c);
00112 int str_cat4s(str* s, const char* a, const char* b, const char* c, const char* d);
00113 int str_cat5s(str* s, const char* a, const char* b, const char* c, const char* d, const char* e);
00114 int str_cat6s(str* s, const char* a, const char* b, const char* c, const char* d, const char* e, const char* f);
00115
00116 int str_join(str* s, char sep, const str* t);
00117 int str_joins(str* s, char sep, const char* in);
00118 int str_joinb(str* s, char sep, const char* in, unsigned len);
00119
00120
00122
00123 void str_lower(str* s);
00124 void str_upper(str* s);
00125 void str_subst(str* s, char from, char to);
00126 void str_lstrip(str* s);
00127 void str_rstrip(str* s);
00128 #define str_strip(S) (str_rstrip(S), str_lstrip(S))
00129 void str_lcut(str* s, unsigned count);
00130 void str_rcut(str* s, unsigned count);
00131 int str_sort(str* s, char sep, long count,
00132 int (*fn)(const str_sortentry* a, const str_sortentry* b));
00133
00134
00137 int str_cmp(const str* a, unsigned aoffset, const str* b, unsigned boffset);
00138 int str_cmps(const str* a, unsigned offset, const char* b);
00139 int str_cmpb(const str* a, unsigned offset, const char* b, unsigned len);
00140
00141 int str_diff(const str* a, const str* b);
00142 int str_diffs(const str* a, const char* b);
00143 int str_diffb(const str* a, const char* b, unsigned len);
00144
00145 int str_start(const str* a, const str* b);
00146 int str_starts(const str* a, const char* b);
00147 int str_startb(const str* a, const char* b, unsigned len);
00148
00149 int str_case_start(const str* a, const str* b);
00150 int str_case_starts(const str* a, const char* b);
00151 int str_case_startb(const str* a, const char* b, unsigned len);
00152
00153
00156 void str_buildmap(int map[256], const char* list);
00157 unsigned str_count(const str* s, char ch);
00158 unsigned str_countof(const str* s, const char* list);
00159 #define str_findfirst(S,C) str_findnext(S,C,0)
00160 #define str_findfirstof(S,L) str_findnextof(S,L,0)
00161 #define str_findfirstnot(S,L) str_findnextnot(S,L,0)
00162 #define str_findlast(S,C) str_findprev(S,C,-1)
00163 #define str_findlastof(S,L) str_findprevof(S,L,-1)
00164 #define str_findlastnot(S,L) str_findprevof(S,L,-1)
00165 int str_findnext(const str* s, char ch, unsigned pos);
00166 int str_findnextof(const str* s, const char* list, unsigned pos);
00167 int str_findnextnot(const str* s, const char* list, unsigned pos);
00168 int str_findprev(const str* s, char ch, unsigned pos);
00169 int str_findprevof(const str* s, const char* list, unsigned pos);
00170 int str_findprevnot(const str* s, const char* list, unsigned pos);
00171
00172
00175 int str_match(const str* s, const str* pattern);
00176 int str_matchb(const str* s, const char* pptr, unsigned plen);
00177 int str_matchs(const str* s, const char* pattern);
00178 int str_case_match(const str* s, const str* pattern);
00179 int str_case_matchb(const str* s, const char* pptr, unsigned plen);
00180 int str_case_matchs(const str* s, const char* pattern);
00181 int str_glob(const str* s, const str* pattern);
00182 int str_globb(const str* s, const char* pptr, unsigned plen);
00183 int str_globs(const str* s, const char* pattern);
00184 int str_case_glob(const str* s, const str* pattern);
00185 int str_case_globb(const str* s, const char* pptr, unsigned plen);
00186 int str_case_globs(const str* s, const char* pattern);
00187
00188
00189
00190
00191 #endif