File indexing completed on 2025-01-18 10:02:04
0001 #ifndef MAD_STR_H
0002 #define MAD_STR_H
0003
0004
0005
0006 struct int_array;
0007 struct char_array;
0008 struct char_p_array;
0009
0010
0011 double myatof(const char *instr);
0012 char* mycpy(char* sout, const char* sin);
0013 char* mystrchr(char* string, char c);
0014 void mystrcpy(struct char_array* target, const char *source);
0015 char* mystrstr(char* string, const char* s);
0016 void myrepl(const char* in, const char* out, const char* string_in, char* string_out);
0017 int mysplit(char* buf, struct char_p_array* list);
0018
0019 void conv_char(const char* string, struct int_array* tint);
0020 void stolower_nq(char* s);
0021 char* strip(const char* name);
0022 int supp_lt(char* inbuf, int flag);
0023 void supp_mul_char(char c, char* string);
0024 char* supp_tb(char* string);
0025 int zero_string(char* string);
0026 char* buffer(const char* string);
0027 char* permbuff(const char* string);
0028 char* tmpbuff(const char* string);
0029 int is_token(char* pb, char* string, int slen);
0030 char* join(char** it_list, int n);
0031 char* join_b(char** it_list, int n);
0032 char next_non_blank(char* string);
0033 int next_non_blank_pos(char* string);
0034 char* noquote(char* string);
0035 int quote_level(char* string, char* send);
0036 int square_to_colon(char* string);
0037 char* slash_to_bkslash(char* string);
0038
0039
0040
0041 #include <ctype.h>
0042
0043 static inline int
0044 str_pos(const char s[], char c)
0045 {
0046 int i;
0047 for (i = 0; s[i]; i++)
0048 if (s[i] == c) return i;
0049 return -1;
0050 }
0051
0052 static inline int
0053 char_cnt(char c, const char* s)
0054
0055 {
0056 int i, k = 0;
0057 for (i = 0; s[i]; i++)
0058 if(s[i] == c) k++;
0059 return k;
0060 }
0061
0062 static inline int
0063 next_char(char c, char** toks, int start, int nitem)
0064
0065 {
0066 int i;
0067 for (i = start; i < nitem; i++)
0068 if(*toks[i] == c) return i;
0069 return -1;
0070 }
0071
0072 static inline void
0073 replace(char* buf, char in, char out)
0074
0075 {
0076 int j;
0077 for (j = 0; buf[j]; j++)
0078 if (buf[j] == in) buf[j] = out;
0079 }
0080
0081 static inline char*
0082 stolower(char* s)
0083 {
0084 int j;
0085 for (j = 0; s[j]; j++) {
0086 unsigned char c = s[j];
0087 s[j] = tolower(c);
0088 }
0089 return s;
0090 }
0091
0092 static inline char*
0093 stoupper(char* s)
0094 {
0095 int j;
0096 for (j = 0; s[j]; j++) {
0097 unsigned char c = s[j];
0098 s[j] = toupper(c);
0099 }
0100 return s;
0101 }
0102
0103 static inline int
0104 mystricmp(const char *s1, const char *s2)
0105 {
0106 const unsigned char *us1 = (const unsigned char *)s1;
0107 const unsigned char *us2 = (const unsigned char *)s2;
0108
0109 while (tolower(*us1) == tolower(*us2)) {
0110 if (*us1 == '\0') return 0;
0111 us1++, us2++;
0112 }
0113 return tolower(*us1) - tolower(*us2);
0114 }
0115
0116 static inline int
0117 mystrnicmp(const char *s1, const char *s2, size_t n)
0118 {
0119 const unsigned char *us1 = (const unsigned char *)s1;
0120 const unsigned char *us2 = (const unsigned char *)s2;
0121
0122 while (tolower(*us1) == tolower(*us2)) {
0123 if (*us1 == '\0' || n <= 1) return 0;
0124 us1++, us2++, n--;
0125 }
0126 return tolower(*us1) - tolower(*us2);
0127 }
0128
0129 static inline int
0130 string_cnt(char c, int n, char* toks[])
0131
0132 {
0133 int i, k = 0;
0134 for (i = 0; i < n; i++)
0135 if(*toks[i] == c) k++;
0136 return k;
0137 }
0138
0139 static inline void
0140 supp_char(char c, char* s)
0141
0142 {
0143 char *p;
0144 for (p = s; *s; s++)
0145 if (*s != c) *p++ = *s;
0146 *p = '\0';
0147 }
0148
0149 static inline int
0150 all_blank(char* s)
0151 {
0152 int i;
0153 for (i = 0; s[i]; i++)
0154 if(s[i] != ' ') return 0;
0155 return 1;
0156 }
0157
0158 static inline char*
0159 str2path(char *path)
0160 {
0161 #ifdef _WIN32
0162 for (int i = 0; path[i]; i++)
0163 if (path[i] == '/') path[i] = '\\';
0164 #else
0165 for (int i = 0; path[i]; i++)
0166 if (path[i] == '\\') path[i] = '/';
0167 #endif
0168 return path;
0169 }
0170
0171 #endif
0172