summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/extstr.c32
-rw-r--r--src/common/extstr.h4
2 files changed, 36 insertions, 0 deletions
diff --git a/src/common/extstr.c b/src/common/extstr.c
index cabc307..0b37606 100644
--- a/src/common/extstr.c
+++ b/src/common/extstr.c
@@ -368,3 +368,35 @@ char *ellipsis(char *input, size_t max)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : str = chaîne à analyser. *
+* suffix = chaîne à retrouver en extrémité éventuellement. *
+* *
+* Description : Détermine si une chaîne se termine par une autre. *
+* *
+* Retour : true si le suffixe a été identifié, ou false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool endswith(const char *str, const char *suffix)
+{
+ bool result; /* Bilan à faire remonter */
+ size_t len; /* Taille de la chaîne soumise */
+ size_t suflen; /* Taille du suffixe */
+
+ result = false;
+
+ len = strlen(str);
+ suflen = strlen(suffix);
+
+ if (len > suflen && strncmp(&str[len - suflen], suffix, suflen) == 0)
+ result = true;
+
+ return result;
+
+}
diff --git a/src/common/extstr.h b/src/common/extstr.h
index 6eb3889..9b49563 100644
--- a/src/common/extstr.h
+++ b/src/common/extstr.h
@@ -26,6 +26,7 @@
#include <ctype.h>
+#include <stdbool.h>
#include <sys/types.h>
@@ -60,6 +61,9 @@ char *escape_crlf(char *);
/* Borne la taille d'une chaîne à une valeur donnée. */
char *ellipsis(char *, size_t);
+/* Détermine si une chaîne se termine par une autre. */
+bool endswith(const char *, const char *);
+
#endif /* _COMMON_EXTSTR_H */