Przeglądaj źródła

:bug: Debug Trim + Suppr methode inutile

Arthur Brandao 6 lat temu
rodzic
commit
2f0bfdff5c
3 zmienionych plików z 11 dodań i 68 usunięć
  1. 0 0
      Serveur/constante.h
  2. 11 59
      Serveur/str.c
  3. 0 9
      Serveur/str.h

+ 0 - 0
Serveur/boolean.h → Serveur/constante.h


+ 11 - 59
Serveur/str.c

@@ -36,62 +36,6 @@ int intToStr(int x, char str[], int d){
 
 /* --- Fonctions publiques --- */
 
-char** str_split(char* str, const char delim, int* length) {
-    char** res;
-    char* signet, * tmp = str;
-    char last = 0;
-    int compteur = 0, nb = 1, taille, count = 0;
-    //Compte le nombre d'element
-    while (*tmp) {
-        if (*tmp == delim && last != delim) {
-            nb++;
-        }
-        last = *tmp;
-        tmp++;
-    }
-    //Creation du tableau
-    res = malloc(sizeof (char*));
-    //Decoupage
-    tmp = str;
-    while (*tmp) {
-        //Si c'est le dernier mot
-        if (compteur == nb - 1) {
-            //Ajoute tous ce qui reste
-            res[compteur] = malloc(sizeof (char) * (strlen(str) - count));
-            int i = 0;
-            while(*tmp){
-                res[compteur][i++] = *tmp;
-                tmp++;
-            }
-        } else {
-            //Recup la taille du mot
-            signet = tmp;
-            taille = 0;
-            while (*tmp != delim) {
-                taille++;
-                tmp++;
-                count++;
-            }
-            //Creation du mot
-            res[compteur] = malloc(sizeof (char) * taille);
-            //Ajout du mot
-            for (int i = 0; i < taille; i++) {
-                res[compteur][i] = *signet;
-                signet++;
-            }
-            compteur++;
-            //Passe les delimiteurs consecutif
-            while (*tmp == delim) {
-                tmp++;
-                count++;
-            }
-        }
-    }
-    //Retour nombre de mot et tableau
-    *length = nb;
-    return res;
-}
-
 char* trim(char* str){
     return ltrim(rtrim(str, ' '), ' ');
 }
@@ -110,11 +54,15 @@ char* ltrim(char* str, char mask){
     }
     //Si aucun espace au debut
     if(cmpt == 0){
-        return str;
+        res = malloc(sizeof(char) * (strlen(str) + 1));
+        memset(res, 0, strlen(str) + 1);
+        strcpy(res, str);
+        return res;
     }
     //Sinon creation nouvelle chaine
     res = malloc(sizeof(char) * (strlen(str) - cmpt + 1));
-    for(int i = 0, j = cmpt; i < (strlen(str) - cmpt); i++, j++){
+    memset(res, 0, strlen(str) - cmpt + 1);
+    for(int i = 0, j = cmpt; j < (strlen(str)); i++, j++){
         res[i] = str[j];
     }
     //Retour nouvelle chaine
@@ -131,11 +79,15 @@ char* rtrim(char* str, char mask){
     }
     //Si aucun espace au debut
     if(cmpt == strlen(str) - 1){
-        return str;
+        res = malloc(sizeof(char) * (strlen(str) + 1));
+        memset(res, 0, strlen(str) + 1);
+        strcpy(res, str);
+        return res;
     }
     cmpt++;
     //Sinon creation nouvelle chaine
     res = malloc(sizeof(char) * (cmpt + 2));
+    memset(res, 0, cmpt + 2);
     for(int i = 0; i < cmpt; i++){
         res[i] = str[i];
     }

+ 0 - 9
Serveur/str.h

@@ -9,15 +9,6 @@
 
 #include <string.h>
 
-/**
- * Separe une chaine en à tableau par rapport à un caractère séparateur
- * @param char* La chaine à séparer
- * @param const char Le caractère séparateur
- * @param int* Le nombre d'élément dans le tableau final (initialisé dans la fonction)
- * @return 
- */
-char** str_split(char*, const char, int*);
-
 /**
  * Retire les espaces avant et après la chaine
  * @param char* La chaine à modifier