13 #ifdef TOOLS_CSTR_DEBUG_MEM
24 inline const std::string& s_cstr() {
25 static const std::string s_v(
"tools::cstr");
37 #ifdef TOOLS_CSTR_DEBUG_MEM
38 ::printf(
"debug : str_dup \"%s\"\n",a_cstr);
40 mem::increment(s_cstr().c_str());
43 return ::strcpy((
char*)::malloc(::strlen(a_cstr)+1),a_cstr);
53 #ifdef TOOLS_CSTR_DEBUG_MEM
54 ::printf(
"debug : str_from_buffer.\n");
56 mem::increment(s_cstr().c_str());
59 char* s = (
char*)::malloc(a_len+1);
60 if(s==NULL)
return NULL;
61 s = ::strncpy(s,a_buffer,a_len);
67 if(a_cstr==NULL)
return;
69 #ifdef TOOLS_CSTR_DEBUG_MEM
70 ::printf(
"debug : str_del \"%s\"\n",a_cstr);
72 mem::decrement(s_cstr().c_str());
78 inline char*
str_new(
size_t a_l = 0,
char a_char =
' ') {
79 char* s = (
char*)::malloc((a_l+1)*
sizeof(char));
80 if(s==NULL)
return NULL;
82 #ifdef TOOLS_CSTR_DEBUG_MEM
83 ::printf(
"debug : str_new : len %lu\n",a_l);
85 mem::increment(s_cstr().c_str());
88 for(
size_t c=0;c<a_l;c++,pos++) *pos = a_char;
93 inline bool str_cat(
char*& a_1,
const char a_c) {
94 size_t l1 = ::strlen(a_1);
95 char* s = (
char*)::malloc(l1+1+1);
98 #ifdef TOOLS_CSTR_DEBUG_MEM
99 ::printf(
"debug : str_cat \"%s\", char %d\n",a_1,a_c);
101 mem::increment(s_cstr().c_str());
104 ::memcpy(s+l1,&a_c,1);
108 #ifdef TOOLS_CSTR_DEBUG_MEM
109 ::printf(
"debug : str_cat : dec\n");
111 mem::decrement(s_cstr().c_str());
117 inline bool str_cat(
char*& a_1,
const char* a_2) {
118 size_t l1 = ::strlen(a_1);
119 size_t l2 = ::strlen(a_2);
120 char* s = (
char*)::malloc(l1+l2+1);
123 #ifdef TOOLS_CSTR_DEBUG_MEM
124 ::printf(
"debug : str_cat \"%s\" \"%s\"\n",a_1,a_2);
126 mem::increment(s_cstr().c_str());
129 ::memcpy(s+l1,a_2,l2);
133 #ifdef TOOLS_CSTR_DEBUG_MEM
134 ::printf(
"debug : str_cat : dec\n");
136 mem::decrement(s_cstr().c_str());
143 size_t l = ::strlen(a_s);
147 for(
size_t i=0;i<hl;i++) {
157 unsigned int a_sz = 0) {
158 size_t l = ::strlen(a_s);
159 if(a_pos>=l)
return 0;
162 ls = (a_sz<(l-a_pos)?a_sz:(l-a_pos));
166 char* s = (
char*)::malloc(ls+1);
169 #ifdef TOOLS_CSTR_DEBUG_MEM
170 ::printf(
"debug : str_sub \"%s\"\n",a_s);
172 mem::increment(s_cstr().c_str());
176 ::memcpy(s,a_s+a_pos,ls);
181 inline char*
str_rep(
const char* a_s,
unsigned int a_pos,
unsigned int a_sz,
const char* a_new) {
183 size_t las = ::strlen(a_s);
184 if(a_pos>=las)
return 0;
185 if(a_pos+a_sz>las)
return 0;
186 size_t lan = ::strlen(a_new);
187 unsigned int num = a_sz<lan?a_sz:(
unsigned int)lan;
191 size_t le = las-(a_pos+a_sz);
192 size_t ls = a_pos+num+le;
193 char* s = (
char*)::malloc(ls+1);
196 #ifdef TOOLS_CSTR_DEBUG_MEM
197 ::printf(
"debug : str_rep \"%s\"\n",a_s);
199 mem::increment(s_cstr().c_str());
201 ::memcpy(s,a_s,a_pos);
202 ::memcpy(s+a_pos,a_new,num);
203 if(le) ::memcpy(s+a_pos+num,a_s+a_pos+a_sz,le);
210 if(*a_cstr!=a_c)
break;
222 char* _sl = ::setlocale(LC_NUMERIC,0);
223 char* old = _sl?
str_dup(_sl):0;
224 ::setlocale(LC_NUMERIC,
"C");
229 ::setlocale(LC_NUMERIC,a_s);
234 inline bool str_2d(
const char* a_s,
double& a_v) {
238 a_v = ::strtod(a_s,&
end);
272 inline size_t str_lcpy(
char *dst,
const char *src,
size_t siz) {
287 if (n != 0 && --n != 0) {
289 if ((*d++ = *s++) == 0)
break;
295 if (siz != 0) *d =
'\0';
302 inline size_t str_lcat(
char *dst,
const char *src,
size_t siz) {
320 while (n-- != 0 && *d !=
'\0') d++;
324 if (n == 0)
return(dlen + strlen(s));
335 return(dlen + (s - src));
338 template <
class VECTOR>
339 inline bool str_2ds(
char* a_s,
const char* a_sep,VECTOR& a_v) {
343 for (tok = ::strtok(a_s,a_sep);tok && *tok;tok = ::strtok(NULL,a_sep)) {
344 if(!
str_2d(tok,d)) {a_v.clear();
return false;}