diff --git a/dap-sdk/core/include/dap_common.h b/dap-sdk/core/include/dap_common.h index 164121dd11fe57bf04f86571482f2bfcc3217589..ce4b8eac420af5ee6d27bf0d54fb76c9b111b096 100755 --- a/dap-sdk/core/include/dap_common.h +++ b/dap-sdk/core/include/dap_common.h @@ -508,7 +508,10 @@ static inline void * dap_mempcpy(void * a_dest,const void * a_src,size_t n) return ((byte_t*) memcpy(a_dest,a_src,n))+n; } - +static int dap_is_alpha_and_(char e); +static int dap_is_alpha(char e); +static int dap_is_digit(char e); +static char **dap_parse_items(const char *a_str, char a_delimiter, int *a_count, const int a_only_digit); #ifdef __MINGW32__ int exec_silent(const char *a_cmd); diff --git a/dap-sdk/core/src/dap_common.c b/dap-sdk/core/src/dap_common.c index 2789fec964794a738da7f5df3c47f67aea44ddfb..09061848b4b38535d7bc6d6ddeddb551f4011025 100755 --- a/dap-sdk/core/src/dap_common.c +++ b/dap-sdk/core/src/dap_common.c @@ -1097,3 +1097,83 @@ char* dap_ctime_r(time_t *a_time, char* a_buf){ return "(null)\r\n"; } +static int dap_is_alpha_and_(char e) +{ + if ((e >= '0' && e <= '9')||(e >= 'a' && e <= 'z')||(e >= 'A' && e <= 'Z')||(e == '_')) return 1; + return 0; +} + +static int dap_is_alpha(char e) +{ + if ((e >= '0' && e <= '9')||(e >= 'a' && e <= 'z')||(e >= 'A' && e <= 'Z')) return 1; + return 0; +} +static int dap_is_digit(char e) +{ + if ((e >= '0' && e <= '9')) return 1; + return 0; +} +static char **dap_parse_items(const char *a_str, char a_delimiter, int *a_count, const int a_only_digit) +{ + int l_count_temp = *a_count = 0; + int l_len_str = strlen(a_str); + if (l_len_str == 0) return NULL; + char *s, *l_temp_str; + s = l_temp_str = dap_strdup(a_str); + + int l_buf = 0; + for (int i = 0; i < l_len_str; i++) { + if (s[i] == a_delimiter && !l_buf) { + s[i] = 0; + continue; + } + if (s[i] == a_delimiter && l_buf) { + s[i] = 0; + l_buf = 0; + continue; + } + if (!s_is_alpha(s[i]) && l_buf) { + s[i] = 0; + l_buf = 0; + continue; + } + if (!s_is_alpha(s[i]) && !l_buf) { + s[i] = 0; + continue; + } + if (a_only_digit) { + if (s_is_digit(s[i])) { + l_buf++; + if (l_buf == 1) l_count_temp++; + continue; + } + } else if (s_is_alpha(s[i])) { + l_buf++; + if (l_buf == 1) l_count_temp++; + continue; + } + if (!s_is_alpha(s[i])) { + l_buf = 0; + s[i] = 0; + continue; + } + } + + s = l_temp_str; + if (l_count_temp == 0) { + free (l_temp_str); + return NULL; + } + + char **lines = DAP_CALLOC(l_count_temp, sizeof (void *)); + for (int i = 0; i < l_count_temp; i++) { + while (*s == 0) s++; + lines[i] = strdup(s); + s = strchr(s, '\0'); + s++; + } + + free (l_temp_str); + *a_count = l_count_temp; + return lines; +}