]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add macro to assing rspamd_ftok_t from c string
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 17 Dec 2016 19:12:57 +0000 (19:12 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 17 Dec 2016 19:12:57 +0000 (19:12 +0000)
src/libutil/fstring.h

index c1b2058178e3862fd8d8a6a2ebcf61b3342fb22f..ac69b01dfd5552a5a76845d78cc74aa9392a73c0 100644 (file)
@@ -179,4 +179,15 @@ gchar *rspamd_ftokdup (const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT;
 gchar *rspamd_fstringdup (const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT;
 
 #define RSPAMD_FTOK_ASSIGN(t, lit) do { (t)->begin = (lit); (t)->len = sizeof(lit) - 1; } while (0)
+#define RSPAMD_FTOK_FROM_STR(t, str) do { \
+       if (G_LIKELY(str)) { \
+               (t)->begin = (const char*)(str); \
+               (t)->len = strlen (str); \
+       } \
+       else { \
+               (t)->begin = NULL; \
+               (t)->len = 0; \
+       } \
+} while (0)
+
 #endif