diff th_string.h @ 0:728243125263

Import.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Mar 2008 00:15:03 +0000
parents
children 707e35b03f89
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/th_string.h	Thu Mar 20 00:15:03 2008 +0000
@@ -0,0 +1,116 @@
+/*
+ * Miscellaneous string-handling related utility-functions
+ * Programmed and designed by Matti 'ccr' Hamalainen
+ * (C) Copyright 2002-2008 Tecnic Software productions (TNSP)
+ *
+ * Please read file 'COPYING' for information on license and distribution.
+ */
+#ifndef _TH_STRING_H
+#define _TH_STRING_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "th_util.h"
+#include <stdlib.h>
+#include <ctype.h>
+
+/*
+ * Macros
+ */
+/* TODO - Remove usage of libc functions for increased portability.
+ * Possible issues are locales, impossible to implement them...
+ */
+#define th_isalnum(c)	isalnum((int)(unsigned char) c)
+#define th_isalpha(c)	isalpha((int)(unsigned char) c)
+#define th_isascii(c)	isascii((int)(unsigned char) c)
+#define th_isblank(c)	isblank((int)(unsigned char) c)
+#define th_iscntrl(c)	iscntrl((int)(unsigned char) c)
+#define th_isdigit(c)	isdigit((int)(unsigned char) c)
+#define th_isgraph(c)	isgraph((int)(unsigned char) c)
+#define th_islower(c)	islower((int)(unsigned char) c)
+#define th_isprint(c)	isprint((int)(unsigned char) c)
+#define th_ispunct(c)	ispunct((int)(unsigned char) c)
+#define th_isspace(c)	isspace((int)(unsigned char) c)
+#define th_isupper(c)	isupper((int)(unsigned char) c)
+#define th_isxdigit(c)	isxdigit((int)(unsigned char) c)
+#define th_iscrlf(c)	((c=='\r')||(c=='\n'))
+
+#define th_isspecial(q)	(((q >= 0x5b) && (q <= 0x60)) || ((q >= 0x7b) && (q <= 0x7d)))
+
+#define th_tolower(c)	tolower((int)(unsigned char) c)
+#define th_toupper(c)	toupper((int)(unsigned char) c)
+
+/*
+ * Typedefs and structures
+ */
+typedef struct tstrnode {
+	char_t	*pcStr;		/* String */
+	ulint_t	nUsed;		/* Times this string has been referenced */
+	void	*pData;		/* Extra data */
+	
+	struct tstrnode *pPrev, *pNext;
+} t_str_node;
+
+
+#define SET_HASH_MAXINDEX	(256)
+
+typedef t_str_node *t_str_hash[SET_HASH_MAXINDEX];
+
+
+typedef struct tstrindex {
+	t_str_node	**ppIndex;
+	ulint_t		n;
+} t_str_index;
+
+
+/*
+ * Normal NUL-terminated string functions
+ */
+char_t *th_stralloc(size_t);
+char_t *th_strrealloc(char_t *, size_t);
+size_t	th_strlen(char_t *);
+char_t *th_strdup(char_t *);
+char_t *th_strcat(char_t *, char_t *);
+char_t *th_strcpy(char_t *, char_t *);
+char_t *th_strncpy(char_t *, char_t *, size_t);
+int	th_strcmp(char_t *, char_t *);
+int	th_strncmp(char_t *, char_t *, size_t);
+int	th_strcasecmp(char_t *, char_t *);
+int	th_strncasecmp(char_t *, char_t *, size_t);
+void	th_strip_ctrlchars(char_t *);
+char_t *th_strstr(char_t *, char_t *);
+
+int	th_pstrcpy(char_t **, char_t *);
+int	th_pstrcat(char_t **, char_t *);
+
+char_t	*th_findnext(char_t *, size_t *);
+char_t	*th_findsep(char_t *, size_t *, char_t);
+char_t	*th_findseporspace(char_t *, size_t *, char_t);
+
+BOOL	th_strmatch(char_t *, char_t *);
+BOOL	th_strcasematch(char_t *, char_t *);
+
+
+/*
+ * Handling of string-lists and hashes
+ */
+t_str_node *	th_strnode_new(char_t *, ulint_t, void *);
+void		th_strnode_free(t_str_node *);
+void		th_strlist_free(t_str_node *);
+void		th_strlist_insert(t_str_node **, t_str_node *);
+int		th_strhash_insert(t_str_node **, t_str_node *, BOOL);
+void		th_strhash_free(t_str_node **);
+void		th_strhash_change_pdata(t_str_hash, void *, void *);
+t_str_node *	th_strhash_search(t_str_node **, char_t *, BOOL);
+t_str_index *	th_strhash_makeindex(t_str_node **);
+t_str_index *	th_strlist_makeindex(t_str_node *);
+void		th_strindex_free(t_str_index *);
+void		th_strindex_sort_nused(t_str_index *);
+void		th_strindex_sort_alpha(t_str_index *);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _TH_STRING_H */