From 9b3143d0aae9bd9152d3eed4255d870833c13d95 Mon Sep 17 00:00:00 2001
From: Dmitrii <naidv88@gmail.com>
Date: Thu, 16 Dec 2021 16:38:32 +0500
Subject: [PATCH] [+] add new dap functions

---
 dap-sdk/core/include/dap_common.h |  5 +-
 dap-sdk/core/src/dap_common.c     | 80 +++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/dap-sdk/core/include/dap_common.h b/dap-sdk/core/include/dap_common.h
index 164121dd11..ce4b8eac42 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 2789fec964..09061848b4 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;
+}
-- 
GitLab