2 * Copyright (C) 1998, 1999, 2000, 2001, 2003,
3 * 2006, 2007, 2009 Free Software Foundation, Inc.
6 * This file is part of GnuPG.
8 * GnuPG is free software; you can redistribute it and/or modify it
9 * under the terms of either
11 * - the GNU Lesser General Public License as published by the Free
12 * Software Foundation; either version 3 of the License, or (at
13 * your option) any later version.
17 * - the GNU General Public License as published by the Free
18 * Software Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * or both in parallel, as here.
23 * GnuPG is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
28 * You should have received a copies of the GNU General Public License
29 * and the GNU Lesser General Public License along with this program;
30 * if not, see <http://www.gnu.org/licenses/>.
33 #ifndef GNUPG_COMMON_STRINGHELP_H
34 #define GNUPG_COMMON_STRINGHELP_H
38 /*-- stringhelp.c --*/
39 char *has_leading_keyword (const char *string, const char *keyword);
41 const char *memistr (const void *buf, size_t buflen, const char *sub);
42 char *mem2str( char *, const void *, size_t);
43 char *trim_spaces( char *string );
44 char *trim_trailing_spaces( char *string );
45 unsigned int trim_trailing_chars( unsigned char *line, unsigned len,
46 const char *trimchars);
47 unsigned int trim_trailing_ws( unsigned char *line, unsigned len );
48 size_t length_sans_trailing_chars (const unsigned char *line, size_t len,
49 const char *trimchars );
50 size_t length_sans_trailing_ws (const unsigned char *line, size_t len);
53 char *make_basename(const char *filepath, const char *inputpath);
54 char *make_dirname(const char *filepath);
55 char *make_filename( const char *first_part, ... ) GPGRT_ATTR_SENTINEL(0);
56 char *make_filename_try (const char *first_part, ... ) GPGRT_ATTR_SENTINEL(0);
57 char *make_absfilename (const char *first_part, ...) GPGRT_ATTR_SENTINEL(0);
58 char *make_absfilename_try (const char *first_part,
59 ...) GPGRT_ATTR_SENTINEL(0);
60 int compare_filenames( const char *a, const char *b );
62 int hextobyte (const char *s);
64 char *sanitize_buffer (const void *p, size_t n, int delim);
67 size_t utf8_charcount (const char *s, int len);
70 #ifdef HAVE_W32_SYSTEM
71 const char *w32_strerror (int ec);
75 int ascii_isupper (int c);
76 int ascii_islower (int c);
77 int ascii_toupper (int c);
78 int ascii_tolower (int c);
79 char *ascii_strlwr (char *s);
80 int ascii_strcasecmp( const char *a, const char *b );
81 int ascii_strncasecmp (const char *a, const char *b, size_t n);
82 int ascii_memcasecmp( const void *a, const void *b, size_t n );
83 const char *ascii_memistr ( const void *buf, size_t buflen, const char *sub);
84 void *ascii_memcasemem (const void *haystack, size_t nhaystack,
85 const void *needle, size_t nneedle);
89 int memicmp( const char *a, const char *b, size_t n );
92 char *stpcpy(char *a,const char *b);
95 char *strpbrk (const char *s, const char *accept);
98 char *strsep (char **stringp, const char *delim);
101 char *strlwr(char *a);
104 # define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
107 # define memmove(d, s, n) bcopy((s), (d), (n))
110 # define stricmp(a,b) strcasecmp( (a), (b) )
113 void *memrchr (const void *buffer, int c, size_t n);
121 return (((c) & ~0x7f) == 0);
123 #endif /* !HAVE_ISASCII */
129 #define STR2(v) STR(v)
131 /* Percent-escape the string STR by replacing colons with '%3a'. If
132 EXTRA is not NULL, also replace all characters given in EXTRA. The
133 "try_" variant fails with NULL if not enough memory can be
135 char *percent_escape (const char *str, const char *extra);
136 char *try_percent_escape (const char *str, const char *extra);
139 /* Concatenate the string S1 with all the following strings up to a
140 NULL. Returns a malloced buffer with the new string or NULL on a
141 malloc error or if too many arguments are given. */
142 char *strconcat (const char *s1, ...) GPGRT_ATTR_SENTINEL(0);
143 /* Ditto, but die on error. */
144 char *xstrconcat (const char *s1, ...) GPGRT_ATTR_SENTINEL(0);
146 char **strsplit (char *string, char delim, char replacement, int *count);
148 /* Tokenize STRING using the set of delimiters in DELIM. */
149 char **strtokenize (const char *string, const char *delim);
151 /* Split STRING into space delimited fields and store them in the
153 int split_fields (char *string, char **array, int arraysize);
155 /* Return True if MYVERSION is greater or equal than REQ_VERSION. */
156 int compare_version_strings (const char *my_version, const char *req_version);
158 /* Format a string so that it fits within about TARGET_COLS columns. */
159 char *format_text (char *text, int in_place, int target_cols, int max_cols);
162 /*-- mapstrings.c --*/
163 const char *map_static_macro_string (const char *string);
165 #endif /*GNUPG_COMMON_STRINGHELP_H*/