SayoriOS  0.3.3
explode.c
См. документацию.
1 
9 #include <mem/vmm.h>
10 #include "lib/string.h"
11 #include "lib/php/explode.h"
12 
21 uint32_t str_cdsp2(const char* a_str, char del){
22  int x = 0;
23  for(size_t i = 0, len = strlen(a_str); i < len; i++){
24  if (a_str[i] == del) {
25  x++;
26  }
27  }
28  return x;
29 }
30 
31 // TODO: Remake explode to work with libvector and libstring!
32 char** explode(const char str[], char delimiter) {
33  uint32_t ccc = str_cdsp2(str, delimiter);
34  char** result = kmalloc(strlen(str)*2);
35  int y = 0;
36  int a = 0;
37 
38  for (int b = 0; b <= ccc; b++) {
39  result[b] = kmalloc(strlen(str) * sizeof(char));
40  }
41 
42  for (int i = 0; i < strlen(str); i++){
43  if (str[i] == delimiter){
44  result[a][y] = 0;
45  a++;
46  y = 0;
47  continue;
48  }
49  result[a][y] = str[i];
50  y++;
51  }
52 
53  result[a][y] = 0;
54  return result;
55 }
uint32_t str_cdsp2(const char *a_str, char del)
Функция отладки
Definition: explode.c:21
size_t strlen(const char *str)
Возращает длину строки
Definition: string.c:88