Jelajahi Sumber

:bulb: Ajout documentation str

Arthur Brandao 6 tahun lalu
induk
melakukan
9285176a73
2 mengubah file dengan 76 tambahan dan 31 penghapusan
  1. 28 29
      Serveur/str.c
  2. 48 2
      Serveur/str.h

+ 28 - 29
Serveur/str.c

@@ -2,7 +2,7 @@
  * File:   str.c
  * Author: Arthur Brandao
  *
- * Created on 28 octobre 2018
+ * Created on 12 octobre 2018
  */
 #define _POSIX_C_SOURCE 200112L
 
@@ -11,6 +11,31 @@
 #include <math.h>
 #include "str.h"
 
+/* --- Fonctions privées --- */
+
+// Converts a given integer x to string str[].  d is the number 
+// of digits required in output. If d is more than the number 
+// of digits in x, then 0s are added at the beginning. 
+int intToStr(int x, char str[], int d){ 
+    int i = 0; 
+    while (x) 
+    { 
+        str[i++] = (x%10) + '0'; 
+        x = x/10; 
+    } 
+  
+    // If number of digits required is more, then 
+    // add 0s at the beginning 
+    while (i < d) 
+        str[i++] = '0'; 
+  
+    reverse(str, i); 
+    str[i] = '\0'; 
+    return i; 
+} 
+
+/* --- Fonctions publiques --- */
+
 char** str_split(char* str, const char delim, int* length) {
     char** res;
     char* signet, * tmp = str;
@@ -118,9 +143,7 @@ char* rtrim(char* str, char mask){
     return res;
 }
 
-// reverses a string 'str' of length 'len' 
-void reverse(char *str, int len) 
-{ 
+void reverse(char *str, int len){ 
     int i=0, j=len-1, temp; 
     while (i<j) 
     { 
@@ -131,31 +154,7 @@ void reverse(char *str, int len)
     } 
 } 
 
- // Converts a given integer x to string str[].  d is the number 
- // of digits required in output. If d is more than the number 
- // of digits in x, then 0s are added at the beginning. 
-int intToStr(int x, char str[], int d) 
-{ 
-    int i = 0; 
-    while (x) 
-    { 
-        str[i++] = (x%10) + '0'; 
-        x = x/10; 
-    } 
-  
-    // If number of digits required is more, then 
-    // add 0s at the beginning 
-    while (i < d) 
-        str[i++] = '0'; 
-  
-    reverse(str, i); 
-    str[i] = '\0'; 
-    return i; 
-} 
-
-// Converts a floating point number to string. 
-void ftoa(float n, char *res, int afterpoint) 
-{ 
+void ftoa(float n, char *res, int afterpoint) { 
     // Extract integer part 
     int ipart = (int)n; 
   

+ 48 - 2
Serveur/str.h

@@ -2,20 +2,66 @@
  * File:   str.h
  * Author: Arthur Brandao
  *
- * Created on 28 octobre 2018
+ * Created on 12 octobre 2018
  */
 #ifndef STR_H
 #define STR_H
 
 #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
+ * @return La chaine modifiée
+ */
 char* trim(char*);
+
+/**
+ * Retire le caractère passé en paramètre avant et après la chaine
+ * @param char* La chaine à modifier
+ * @param char Le caractère à retirer
+ * @return La chaine modifiée
+ */
 char* mtrim(char*, char);
+
+/**
+ * Retire le caractère passé en paramètre avant la chaine
+ * @param char* La chaine à modifier
+ * @param char Le caractère à retirer
+ * @return La chaine modifiée
+ */
 char* ltrim(char*, char);
+
+/**
+ * Retire le caractère passé en paramètre après la chaine
+ * @param char* La chaine à modifier
+ * @param char Le caractère à retirer
+ * @return La chaine modifiée
+ */
 char* rtrim(char*, char);
+
+/**
+ * Inverse la chaine de caractère
+ * @param char* La chaine
+ * @param int La taille de la chaine
+ */
 void reverse(char*, int);
-int intToStr(int, char*, int);
+
+/**
+ * Convertit un float en chaine de caractère
+ * @param float Le float à convertir
+ * @param char* Le buffer de reception de la chaine
+ * @param int Le nombre de chiffre après la virgule 
+ */
 void ftoa(float, char*, int) ;
 
 #endif /* STR_H */