commit 3d7aef5: [Minor] Add starts_with function for rspamd_ftok_t
Vsevolod Stakhov
vsevolod at highsecure.ru
Thu Feb 7 15:14:11 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-02-07 12:34:22 +0000
URL: https://github.com/rspamd/rspamd/commit/3d7aef55713b576997aec976326c1143d14fe3f8
[Minor] Add starts_with function for rspamd_ftok_t
---
src/libutil/fstring.c | 13 +++++++++++++
src/libutil/fstring.h | 9 +++++++++
2 files changed, 22 insertions(+)
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c
index 2cfbd7bf8..967de9e98 100644
--- a/src/libutil/fstring.c
+++ b/src/libutil/fstring.c
@@ -375,6 +375,19 @@ rspamd_ftok_cmp (const rspamd_ftok_t *s1,
return s1->len - s2->len;
}
+gboolean
+rspamd_ftok_starts_with (const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2)
+{
+ g_assert (s1 != NULL && s2 != NULL);
+
+ if (s1->len >= s2->len) {
+ return !!(memcmp (s1->begin, s2->begin, s1->len) == 0);
+ }
+
+ return FALSE;
+}
+
void
rspamd_fstring_mapped_ftok_free (gpointer p)
{
diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h
index 96749052c..1a4d25eb9 100644
--- a/src/libutil/fstring.h
+++ b/src/libutil/fstring.h
@@ -139,6 +139,15 @@ gint rspamd_ftok_casecmp (const rspamd_ftok_t *s1,
gint rspamd_ftok_cmp (const rspamd_ftok_t *s1,
const rspamd_ftok_t *s2);
+/**
+ * Returns true if `s1` starts with `s2`
+ * @param s1
+ * @param s2
+ * @return
+ */
+gboolean rspamd_ftok_starts_with (const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2);
+
/**
* Return TRUE if ftok is equal to specified C string
*/
More information about the Commits
mailing list