Rocco Rutte:
[apps/madmutt.git] / lib / str.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
5  *
6  * This file is part of mutt-ng, see http://www.muttng.org/.
7  * It's licensed under the GNU General Public License,
8  * please see the file GPL in the top level source directory.
9  */
10 #ifndef _LIB_STR_H
11 #define _LIB_STR_H
12
13 #include <sys/types.h>
14
15 #define NONULL(x) x?x:""
16
17 # define HUGE_STRING     5120
18 # define LONG_STRING     1024
19 # define STRING          256
20 # define SHORT_STRING    128
21
22 /*
23  * Create a format string to be used with scanf.
24  * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
25  * 
26  * See K&R 2nd ed, p. 231 for an explanation.
27  */
28 # define _MUTT_FORMAT_2(a,b)    "%" a  b
29 # define _MUTT_FORMAT_1(a, b)   _MUTT_FORMAT_2(#a, b)
30 # define MUTT_FORMAT(a)         _MUTT_FORMAT_1(a, "s")
31 # define MUTT_FORMAT2(a,b)      _MUTT_FORMAT_1(a, b)
32
33 # define ISSPACE(c) isspace((unsigned char)c)
34 # define ISBLANK(c) (c == ' ' || c == '\t')
35 # define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
36 /* this macro must check for *c == 0 since isspace(0) has
37  * unreliable behavior on some systems */
38 # define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
39
40 /*
41  * safety wrappers/replacements
42  * (mostly only difference: safely handle NULL strings)
43  */
44 char *str_dup (const char*);
45 char *str_cat (char*, size_t, const char*);
46 char *str_ncat (char*, size_t, const char*, size_t);
47 int str_cmp (const char*, const char*);
48 int str_casecmp (const char*, const char*);
49 int str_ncmp (const char*, const char*, size_t);
50 int str_ncasecmp (const char*, const char*, size_t);
51 int str_coll (const char*, const char*);
52 size_t str_len (const char*);
53
54 /*
55  * tools
56  */
57 char *str_tolower (char*);
58 char *str_substrcpy (char*, const char*, const char*, size_t);
59 char *str_substrdup (const char*, const char*);
60 void str_replace (char**, const char*);
61 void str_adjust (char**);
62 int str_eq (const char*, const char*);
63 const char *str_isstr (const char*, const char*);
64 char* str_skip_initws (char*);
65 void str_skip_trailws (char*);
66
67 #endif /* !_LIB_STR_H */