New fucntions strconcat and xstrconcat.
[gnupg.git] / jnlib / stringhelp.h
blob4cd81a1afeaabe2f8002824ed0f79c7ca8edc6af
1 /* stringhelp.h
2 * Copyright (C) 1998, 1999, 2000, 2001, 2003,
3 * 2006, 2007, 2009 Free Software Foundation, Inc.
5 * This file is part of JNLIB.
7 * JNLIB is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 3 of
10 * the License, or (at your option) any later version.
12 * JNLIB is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #ifndef LIBJNLIB_STRINGHELP_H
22 #define LIBJNLIB_STRINGHELP_H
24 #include "types.h"
26 const char *memistr (const void *buf, size_t buflen, const char *sub);
27 char *mem2str( char *, const void *, size_t);
28 char *trim_spaces( char *string );
29 char *trim_trailing_spaces( char *string );
30 unsigned int trim_trailing_chars( unsigned char *line, unsigned len,
31 const char *trimchars);
32 unsigned int trim_trailing_ws( unsigned char *line, unsigned len );
33 size_t length_sans_trailing_chars (const unsigned char *line, size_t len,
34 const char *trimchars );
35 size_t length_sans_trailing_ws (const unsigned char *line, size_t len);
38 char *make_basename(const char *filepath, const char *inputpath);
39 char *make_dirname(const char *filepath);
40 char *make_filename( const char *first_part, ... );
41 char *make_filename_try (const char *first_part, ... );
42 int compare_filenames( const char *a, const char *b );
44 int hextobyte (const char *s);
46 size_t print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
47 int delim);
48 size_t print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
49 int delim, int delim2);
50 size_t print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
51 size_t length, int delim);
52 size_t print_sanitized_string (FILE *fp, const char *string, int delim);
53 size_t print_sanitized_string2 (FILE *fp, const char *string,
54 int delim, int delim2);
55 size_t print_sanitized_utf8_string (FILE *fp, const char *string, int delim);
56 char *sanitize_buffer (const void *p, size_t n, int delim);
59 size_t utf8_charcount (const char *s);
62 #ifdef HAVE_W32_SYSTEM
63 const char *w32_strerror (int ec);
64 #endif
67 int ascii_isupper (int c);
68 int ascii_islower (int c);
69 int ascii_toupper (int c);
70 int ascii_tolower (int c);
71 int ascii_strcasecmp( const char *a, const char *b );
72 int ascii_strncasecmp (const char *a, const char *b, size_t n);
73 int ascii_memcasecmp( const void *a, const void *b, size_t n );
74 const char *ascii_memistr ( const void *buf, size_t buflen, const char *sub);
75 void *ascii_memcasemem (const void *haystack, size_t nhaystack,
76 const void *needle, size_t nneedle);
79 #ifndef HAVE_MEMICMP
80 int memicmp( const char *a, const char *b, size_t n );
81 #endif
82 #ifndef HAVE_STPCPY
83 char *stpcpy(char *a,const char *b);
84 #endif
85 #ifndef HAVE_STRSEP
86 char *strsep (char **stringp, const char *delim);
87 #endif
88 #ifndef HAVE_STRLWR
89 char *strlwr(char *a);
90 #endif
91 #ifndef HAVE_STRTOUL
92 # define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
93 #endif
94 #ifndef HAVE_MEMMOVE
95 # define memmove(d, s, n) bcopy((s), (d), (n))
96 #endif
97 #ifndef HAVE_STRICMP
98 # define stricmp(a,b) strcasecmp( (a), (b) )
99 #endif
100 #ifndef HAVE_MEMRCHR
101 void *memrchr (const void *buffer, int c, size_t n);
102 #endif
105 #ifndef HAVE_ISASCII
106 static inline int
107 isascii (int c)
109 return (((c) & ~0x7f) == 0);
111 #endif /* !HAVE_ISASCII */
114 #ifndef STR
115 # define STR(v) #v
116 #endif
117 #define STR2(v) STR(v)
119 /* Percent-escape the string STR by replacing colons with '%3a'. If
120 EXTRA is not NULL, also replace all characters given in EXTRA. The
121 "try_" variant fails with NULL if not enough memory can be
122 allocated. */
123 char *percent_escape (const char *str, const char *extra);
124 char *try_percent_escape (const char *str, const char *extra);
127 /* Concatenate the string S1 with all the following strings up to a
128 NULL. Returns a malloced buffer with the new string or NULL on a
129 malloc error or if too many arguments are given. */
130 char *strconcat (const char *s1, ...) GNUPG_GCC_A_SENTINEL(0);
131 /* Ditto, but die on error. */
132 char *xstrconcat (const char *s1, ...) GNUPG_GCC_A_SENTINEL(0);
136 #endif /*LIBJNLIB_STRINGHELP_H*/