2008-06-18 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / jnlib / stringhelp.h
blobcb705193333c0a868d03b448a74ff82a0b27aa2e
1 /* stringhelp.h
2 * Copyright (C) 1998, 1999, 2000, 2001, 2003,
3 * 2006, 2007 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 int compare_filenames( const char *a, const char *b );
43 int hextobyte (const char *s);
45 size_t print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
46 int delim);
47 size_t print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
48 int delim, int delim2);
49 size_t print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
50 size_t length, int delim);
51 size_t print_sanitized_string (FILE *fp, const char *string, int delim);
52 size_t print_sanitized_string2 (FILE *fp, const char *string,
53 int delim, int delim2);
54 size_t print_sanitized_utf8_string (FILE *fp, const char *string, int delim);
55 char *sanitize_buffer (const void *p, size_t n, int delim);
58 size_t utf8_charcount (const char *s);
61 #ifdef HAVE_W32_SYSTEM
62 const char *w32_strerror (int ec);
63 #endif
66 int ascii_isupper (int c);
67 int ascii_islower (int c);
68 int ascii_toupper (int c);
69 int ascii_tolower (int c);
70 int ascii_strcasecmp( const char *a, const char *b );
71 int ascii_strncasecmp (const char *a, const char *b, size_t n);
72 int ascii_memcasecmp( const void *a, const void *b, size_t n );
73 const char *ascii_memistr ( const void *buf, size_t buflen, const char *sub);
74 void *ascii_memcasemem (const void *haystack, size_t nhaystack,
75 const void *needle, size_t nneedle);
78 #ifndef HAVE_MEMICMP
79 int memicmp( const char *a, const char *b, size_t n );
80 #endif
81 #ifndef HAVE_STPCPY
82 char *stpcpy(char *a,const char *b);
83 #endif
84 #ifndef HAVE_STRSEP
85 char *strsep (char **stringp, const char *delim);
86 #endif
87 #ifndef HAVE_STRLWR
88 char *strlwr(char *a);
89 #endif
90 #ifndef HAVE_STRTOUL
91 # define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
92 #endif
93 #ifndef HAVE_MEMMOVE
94 # define memmove(d, s, n) bcopy((s), (d), (n))
95 #endif
96 #ifndef HAVE_STRICMP
97 # define stricmp(a,b) strcasecmp( (a), (b) )
98 #endif
99 #ifndef HAVE_MEMRCHR
100 void *memrchr (const void *buffer, int c, size_t n);
101 #endif
104 #ifndef HAVE_ISASCII
105 static inline int
106 isascii (int c)
108 return (((c) & ~0x7f) == 0);
110 #endif /* !HAVE_ISASCII */
113 #ifndef STR
114 # define STR(v) #v
115 #endif
116 #define STR2(v) STR(v)
118 /* Percent-escape the string STR by replacing colons with '%3a'. If
119 EXTRA is not NULL, also replace all characters given in EXTRA. The
120 "try_" variant fails with NULL if not enough memory can be
121 allocated. */
122 char *percent_escape (const char *str, const char *extra);
123 char *try_percent_escape (const char *str, const char *extra);
126 #endif /*LIBJNLIB_STRINGHELP_H*/