1 /* stringhelp.h
2  * Copyright (C) 1998, 1999, 2000, 2001, 2003,
3  *               2006, 2007  Free Software Foundation, Inc.
4  *
5  * This file is part of JNLIB.
6  *
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 2.1 of
10  * the License, or (at your option) any later version.
11  *
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.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  */
22 
23 #ifndef LIBJNLIB_STRINGHELP_H
24 #define LIBJNLIB_STRINGHELP_H
25 
26 #include "types.h"
27 
28 const char *memistr (const void *buf, size_t buflen, const char *sub);
29 char *mem2str( char *, const void *, size_t);
30 char *trim_spaces( char *string );
31 char *trim_trailing_spaces( char *string );
32 unsigned int trim_trailing_chars( unsigned char *line, unsigned len,
33 					      const char *trimchars);
34 unsigned int trim_trailing_ws( unsigned char *line, unsigned len );
35 size_t length_sans_trailing_chars (const unsigned char *line, size_t len,
36                                    const char *trimchars );
37 size_t length_sans_trailing_ws (const unsigned char *line, size_t len);
38 
39 
40 char *make_basename(const char *filepath, const char *inputpath);
41 char *make_dirname(const char *filepath);
42 char *make_filename( const char *first_part, ... );
43 int compare_filenames( const char *a, const char *b );
44 
45 int hextobyte (const char *s);
46 
47 size_t print_sanitized_buffer (FILE *fp, const void *buffer, size_t length,
48                                int delim);
49 size_t print_sanitized_buffer2 (FILE *fp, const void *buffer, size_t length,
50                                 int delim, int delim2);
51 size_t print_sanitized_utf8_buffer (FILE *fp, const void *buffer,
52                                     size_t length, int delim);
53 size_t print_sanitized_string (FILE *fp, const char *string, int delim);
54 size_t print_sanitized_string2 (FILE *fp, const char *string,
55                                 int delim, int delim2);
56 size_t print_sanitized_utf8_string (FILE *fp, const char *string, int delim);
57 char *sanitize_buffer (const void *p, size_t n, int delim);
58 
59 
60 size_t utf8_charcount (const char *s);
61 
62 
63 #ifdef HAVE_W32_SYSTEM
64 const char *w32_strerror (int ec);
65 #endif
66 
67 
68 int ascii_isupper (int c);
69 int ascii_islower (int c);
70 int ascii_toupper (int c);
71 int ascii_tolower (int c);
72 int ascii_strcasecmp( const char *a, const char *b );
73 int ascii_strncasecmp (const char *a, const char *b, size_t n);
74 int ascii_memcasecmp( const void *a, const void *b, size_t n );
75 const char *ascii_memistr ( const void *buf, size_t buflen, const char *sub);
76 void *ascii_memcasemem (const void *haystack, size_t nhaystack,
77                         const void *needle, size_t nneedle);
78 
79 
80 #ifndef HAVE_MEMICMP
81 int memicmp( const char *a, const char *b, size_t n );
82 #endif
83 #ifndef HAVE_STPCPY
84 char *stpcpy(char *a,const char *b);
85 #endif
86 #ifndef HAVE_STRSEP
87 char *strsep (char **stringp, const char *delim);
88 #endif
89 #ifndef HAVE_STRLWR
90 char *strlwr(char *a);
91 #endif
92 #ifndef HAVE_STRTOUL
93 #  define strtoul(a,b,c)  ((unsigned long)strtol((a),(b),(c)))
94 #endif
95 #ifndef HAVE_MEMMOVE
96 #  define memmove(d, s, n) bcopy((s), (d), (n))
97 #endif
98 #ifndef HAVE_STRICMP
99 #  define stricmp(a,b)	 strcasecmp( (a), (b) )
100 #endif
101 #ifndef HAVE_MEMRCHR
102 void *memrchr (const void *buffer, int c, size_t n);
103 #endif
104 
105 
106 #ifndef HAVE_ISASCII
107 static inline int
isascii(int c)108 isascii (int c)
109 {
110   return (((c) & ~0x7f) == 0);
111 }
112 #endif /* !HAVE_ISASCII */
113 
114 
115 #ifndef STR
116 #  define STR(v) #v
117 #endif
118 #define STR2(v) STR(v)
119 
120 /* Percent-escape the string STR by replacing colons with '%3a'.  If
121    EXTRA is not NULL, also replace all characters given in EXTRA. */
122 char *percent_escape (const char *str, const char *extra);
123 
124 
125 #endif /*LIBJNLIB_STRINGHELP_H*/
126