aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/fstring.h
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-04-21 16:25:51 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-04-21 16:25:51 +0100
commit61555065f3d1c8badcc9573691232f1b6e42988c (patch)
tree563d5b7cb8c468530f7e79c4da0a75267b1184e1 /src/libutil/fstring.h
parentad5bf825b7f33bc10311673991f0cc888e69c0b1 (diff)
downloadrspamd-61555065f3d1c8badcc9573691232f1b6e42988c.tar.gz
rspamd-61555065f3d1c8badcc9573691232f1b6e42988c.zip
Rework project structure, remove trash files.
Diffstat (limited to 'src/libutil/fstring.h')
-rw-r--r--src/libutil/fstring.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h
new file mode 100644
index 000000000..bd680e365
--- /dev/null
+++ b/src/libutil/fstring.h
@@ -0,0 +1,120 @@
+/*
+ * Functions for handling with fixed size strings
+ */
+
+#ifndef FSTRING_H
+#define FSTRING_H
+
+#include "config.h"
+#include "mem_pool.h"
+
+#define update_buf_size(x) (x)->free = (x)->buf->size - ((x)->pos - (x)->buf->begin); (x)->buf->len = (x)->pos - (x)->buf->begin
+
+typedef struct f_str_s {
+ gchar *begin;
+ size_t len;
+ size_t size;
+} f_str_t;
+
+typedef struct f_str_buf_s {
+ f_str_t *buf;
+ gchar *pos;
+ size_t free;
+} f_str_buf_t;
+
+typedef struct f_tok_s {
+ f_str_t word;
+ size_t pos;
+} f_tok_t;
+
+/*
+ * Search first occurence of character in string
+ */
+ssize_t fstrchr (f_str_t *src, gchar c);
+
+/*
+ * Search last occurence of character in string
+ */
+ssize_t fstrrchr (f_str_t *src, gchar c);
+
+/*
+ * Search for pattern in orig
+ */
+ssize_t fstrstr (f_str_t *orig, f_str_t *pattern);
+
+/*
+ * Search for pattern in orig ignoring case
+ */
+ssize_t fstrstri (f_str_t *orig, f_str_t *pattern);
+
+/*
+ * Split string by tokens
+ * word contains parsed word
+ */
+gint fstrtok (f_str_t *text, const gchar *sep, f_tok_t *state);
+
+/*
+ * Copy one string into other
+ */
+size_t fstrcpy (f_str_t *dest, f_str_t *src);
+
+/*
+ * Concatenate two strings
+ */
+size_t fstrcat (f_str_t *dest, f_str_t *src);
+
+/*
+ * Push one character to fstr
+ */
+gint fstrpush (f_str_t *dest, gchar c);
+
+/*
+ * Push one character to fstr
+ */
+gint fstrpush_unichar (f_str_t *dest, gunichar c);
+
+/*
+ * Allocate memory for f_str_t
+ */
+f_str_t* fstralloc (rspamd_mempool_t *pool, size_t len);
+
+/*
+ * Allocate memory for f_str_t from temporary pool
+ */
+f_str_t* fstralloc_tmp (rspamd_mempool_t *pool, size_t len);
+
+/*
+ * Truncate string to its len
+ */
+f_str_t* fstrtruncate (rspamd_mempool_t *pool, f_str_t *orig);
+
+/*
+ * Enlarge string to new size
+ */
+f_str_t* fstrgrow (rspamd_mempool_t *pool, f_str_t *orig, size_t newlen);
+
+/*
+ * Return specified character
+ */
+#define fstridx(str, pos) *((str)->begin + (pos))
+
+/*
+ * Return fast hash value for fixed string
+ */
+guint32 fstrhash (f_str_t *str);
+
+/*
+ * Return fast hash value for fixed string converted to lowercase
+ */
+guint32 fstrhash_lowercase (f_str_t *str, gboolean is_utf);
+/*
+ * Make copy of string to 0-terminated string
+ */
+gchar* fstrcstr (f_str_t *str, rspamd_mempool_t *pool);
+
+/*
+ * Strip fstr string from space symbols
+ */
+void fstrstrip (f_str_t *str);
+
+#endif