xref: /aosp_15_r20/external/libcups/cups/string-private.h (revision 5e7646d21f1134fb0638875d812ef646c12ab91e)
1*5e7646d2SAndroid Build Coastguard Worker /*
2*5e7646d2SAndroid Build Coastguard Worker  * Private string definitions for CUPS.
3*5e7646d2SAndroid Build Coastguard Worker  *
4*5e7646d2SAndroid Build Coastguard Worker  * Copyright © 2007-2018 by Apple Inc.
5*5e7646d2SAndroid Build Coastguard Worker  * Copyright © 1997-2006 by Easy Software Products.
6*5e7646d2SAndroid Build Coastguard Worker  *
7*5e7646d2SAndroid Build Coastguard Worker  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
8*5e7646d2SAndroid Build Coastguard Worker  * information.
9*5e7646d2SAndroid Build Coastguard Worker  */
10*5e7646d2SAndroid Build Coastguard Worker 
11*5e7646d2SAndroid Build Coastguard Worker #ifndef _CUPS_STRING_PRIVATE_H_
12*5e7646d2SAndroid Build Coastguard Worker #  define _CUPS_STRING_PRIVATE_H_
13*5e7646d2SAndroid Build Coastguard Worker 
14*5e7646d2SAndroid Build Coastguard Worker /*
15*5e7646d2SAndroid Build Coastguard Worker  * Include necessary headers...
16*5e7646d2SAndroid Build Coastguard Worker  */
17*5e7646d2SAndroid Build Coastguard Worker 
18*5e7646d2SAndroid Build Coastguard Worker #  include "config.h"
19*5e7646d2SAndroid Build Coastguard Worker #  include <stdio.h>
20*5e7646d2SAndroid Build Coastguard Worker #  include <stdlib.h>
21*5e7646d2SAndroid Build Coastguard Worker #  include <stdarg.h>
22*5e7646d2SAndroid Build Coastguard Worker #  include <ctype.h>
23*5e7646d2SAndroid Build Coastguard Worker #  include <errno.h>
24*5e7646d2SAndroid Build Coastguard Worker #  include <locale.h>
25*5e7646d2SAndroid Build Coastguard Worker #  include <time.h>
26*5e7646d2SAndroid Build Coastguard Worker 
27*5e7646d2SAndroid Build Coastguard Worker #  include <cups/versioning.h>
28*5e7646d2SAndroid Build Coastguard Worker 
29*5e7646d2SAndroid Build Coastguard Worker #  ifdef HAVE_STRING_H
30*5e7646d2SAndroid Build Coastguard Worker #    include <string.h>
31*5e7646d2SAndroid Build Coastguard Worker #  endif /* HAVE_STRING_H */
32*5e7646d2SAndroid Build Coastguard Worker 
33*5e7646d2SAndroid Build Coastguard Worker #  ifdef HAVE_STRINGS_H
34*5e7646d2SAndroid Build Coastguard Worker #    include <strings.h>
35*5e7646d2SAndroid Build Coastguard Worker #  endif /* HAVE_STRINGS_H */
36*5e7646d2SAndroid Build Coastguard Worker 
37*5e7646d2SAndroid Build Coastguard Worker #  ifdef HAVE_BSTRING_H
38*5e7646d2SAndroid Build Coastguard Worker #    include <bstring.h>
39*5e7646d2SAndroid Build Coastguard Worker #  endif /* HAVE_BSTRING_H */
40*5e7646d2SAndroid Build Coastguard Worker 
41*5e7646d2SAndroid Build Coastguard Worker #  if defined(_WIN32) && !defined(__CUPS_SSIZE_T_DEFINED)
42*5e7646d2SAndroid Build Coastguard Worker #    define __CUPS_SSIZE_T_DEFINED
43*5e7646d2SAndroid Build Coastguard Worker #    include <stddef.h>
44*5e7646d2SAndroid Build Coastguard Worker /* Windows does not support the ssize_t type, so map it to long... */
45*5e7646d2SAndroid Build Coastguard Worker typedef long ssize_t;			/* @private@ */
46*5e7646d2SAndroid Build Coastguard Worker #  endif /* _WIN32 && !__CUPS_SSIZE_T_DEFINED */
47*5e7646d2SAndroid Build Coastguard Worker 
48*5e7646d2SAndroid Build Coastguard Worker 
49*5e7646d2SAndroid Build Coastguard Worker /*
50*5e7646d2SAndroid Build Coastguard Worker  * C++ magic...
51*5e7646d2SAndroid Build Coastguard Worker  */
52*5e7646d2SAndroid Build Coastguard Worker 
53*5e7646d2SAndroid Build Coastguard Worker #  ifdef __cplusplus
54*5e7646d2SAndroid Build Coastguard Worker extern "C" {
55*5e7646d2SAndroid Build Coastguard Worker #  endif /* __cplusplus */
56*5e7646d2SAndroid Build Coastguard Worker 
57*5e7646d2SAndroid Build Coastguard Worker 
58*5e7646d2SAndroid Build Coastguard Worker /*
59*5e7646d2SAndroid Build Coastguard Worker  * String pool structures...
60*5e7646d2SAndroid Build Coastguard Worker  */
61*5e7646d2SAndroid Build Coastguard Worker 
62*5e7646d2SAndroid Build Coastguard Worker #  define _CUPS_STR_GUARD	0x12344321
63*5e7646d2SAndroid Build Coastguard Worker 
64*5e7646d2SAndroid Build Coastguard Worker typedef struct _cups_sp_item_s		/**** String Pool Item ****/
65*5e7646d2SAndroid Build Coastguard Worker {
66*5e7646d2SAndroid Build Coastguard Worker #  ifdef DEBUG_GUARDS
67*5e7646d2SAndroid Build Coastguard Worker   unsigned int	guard;			/* Guard word */
68*5e7646d2SAndroid Build Coastguard Worker #  endif /* DEBUG_GUARDS */
69*5e7646d2SAndroid Build Coastguard Worker   unsigned int	ref_count;		/* Reference count */
70*5e7646d2SAndroid Build Coastguard Worker   char		str[1];			/* String */
71*5e7646d2SAndroid Build Coastguard Worker } _cups_sp_item_t;
72*5e7646d2SAndroid Build Coastguard Worker 
73*5e7646d2SAndroid Build Coastguard Worker 
74*5e7646d2SAndroid Build Coastguard Worker /*
75*5e7646d2SAndroid Build Coastguard Worker  * Replacements for the ctype macros that are not affected by locale, since we
76*5e7646d2SAndroid Build Coastguard Worker  * really only care about testing for ASCII characters when parsing files, etc.
77*5e7646d2SAndroid Build Coastguard Worker  *
78*5e7646d2SAndroid Build Coastguard Worker  * The _CUPS_INLINE definition controls whether we get an inline function body,
79*5e7646d2SAndroid Build Coastguard Worker  * and external function body, or an external definition.
80*5e7646d2SAndroid Build Coastguard Worker  */
81*5e7646d2SAndroid Build Coastguard Worker 
82*5e7646d2SAndroid Build Coastguard Worker #  if defined(__GNUC__) || __STDC_VERSION__ >= 199901L
83*5e7646d2SAndroid Build Coastguard Worker #    define _CUPS_INLINE static inline
84*5e7646d2SAndroid Build Coastguard Worker #  elif defined(_MSC_VER)
85*5e7646d2SAndroid Build Coastguard Worker #    define _CUPS_INLINE static __inline
86*5e7646d2SAndroid Build Coastguard Worker #  elif defined(_CUPS_STRING_C_)
87*5e7646d2SAndroid Build Coastguard Worker #    define _CUPS_INLINE
88*5e7646d2SAndroid Build Coastguard Worker #  endif /* __GNUC__ || __STDC_VERSION__ */
89*5e7646d2SAndroid Build Coastguard Worker 
90*5e7646d2SAndroid Build Coastguard Worker #  ifdef _CUPS_INLINE
91*5e7646d2SAndroid Build Coastguard Worker _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_isalnum(int ch)92*5e7646d2SAndroid Build Coastguard Worker _cups_isalnum(int ch)			/* I - Character to test */
93*5e7646d2SAndroid Build Coastguard Worker {
94*5e7646d2SAndroid Build Coastguard Worker   return ((ch >= '0' && ch <= '9') ||
95*5e7646d2SAndroid Build Coastguard Worker           (ch >= 'A' && ch <= 'Z') ||
96*5e7646d2SAndroid Build Coastguard Worker           (ch >= 'a' && ch <= 'z'));
97*5e7646d2SAndroid Build Coastguard Worker }
98*5e7646d2SAndroid Build Coastguard Worker 
99*5e7646d2SAndroid Build Coastguard Worker _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_isalpha(int ch)100*5e7646d2SAndroid Build Coastguard Worker _cups_isalpha(int ch)			/* I - Character to test */
101*5e7646d2SAndroid Build Coastguard Worker {
102*5e7646d2SAndroid Build Coastguard Worker   return ((ch >= 'A' && ch <= 'Z') ||
103*5e7646d2SAndroid Build Coastguard Worker           (ch >= 'a' && ch <= 'z'));
104*5e7646d2SAndroid Build Coastguard Worker }
105*5e7646d2SAndroid Build Coastguard Worker 
106*5e7646d2SAndroid Build Coastguard Worker _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_islower(int ch)107*5e7646d2SAndroid Build Coastguard Worker _cups_islower(int ch)			/* I - Character to test */
108*5e7646d2SAndroid Build Coastguard Worker {
109*5e7646d2SAndroid Build Coastguard Worker   return (ch >= 'a' && ch <= 'z');
110*5e7646d2SAndroid Build Coastguard Worker }
111*5e7646d2SAndroid Build Coastguard Worker 
112*5e7646d2SAndroid Build Coastguard Worker _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_isspace(int ch)113*5e7646d2SAndroid Build Coastguard Worker _cups_isspace(int ch)			/* I - Character to test */
114*5e7646d2SAndroid Build Coastguard Worker {
115*5e7646d2SAndroid Build Coastguard Worker   return (ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' ||
116*5e7646d2SAndroid Build Coastguard Worker           ch == '\v');
117*5e7646d2SAndroid Build Coastguard Worker }
118*5e7646d2SAndroid Build Coastguard Worker 
119*5e7646d2SAndroid Build Coastguard Worker _CUPS_INLINE int			/* O - 1 on match, 0 otherwise */
_cups_isupper(int ch)120*5e7646d2SAndroid Build Coastguard Worker _cups_isupper(int ch)			/* I - Character to test */
121*5e7646d2SAndroid Build Coastguard Worker {
122*5e7646d2SAndroid Build Coastguard Worker   return (ch >= 'A' && ch <= 'Z');
123*5e7646d2SAndroid Build Coastguard Worker }
124*5e7646d2SAndroid Build Coastguard Worker 
125*5e7646d2SAndroid Build Coastguard Worker _CUPS_INLINE int			/* O - Converted character */
_cups_tolower(int ch)126*5e7646d2SAndroid Build Coastguard Worker _cups_tolower(int ch)			/* I - Character to convert */
127*5e7646d2SAndroid Build Coastguard Worker {
128*5e7646d2SAndroid Build Coastguard Worker   return (_cups_isupper(ch) ? ch - 'A' + 'a' : ch);
129*5e7646d2SAndroid Build Coastguard Worker }
130*5e7646d2SAndroid Build Coastguard Worker 
131*5e7646d2SAndroid Build Coastguard Worker _CUPS_INLINE int			/* O - Converted character */
_cups_toupper(int ch)132*5e7646d2SAndroid Build Coastguard Worker _cups_toupper(int ch)			/* I - Character to convert */
133*5e7646d2SAndroid Build Coastguard Worker {
134*5e7646d2SAndroid Build Coastguard Worker   return (_cups_islower(ch) ? ch - 'a' + 'A' : ch);
135*5e7646d2SAndroid Build Coastguard Worker }
136*5e7646d2SAndroid Build Coastguard Worker #  else
137*5e7646d2SAndroid Build Coastguard Worker extern int _cups_isalnum(int ch);
138*5e7646d2SAndroid Build Coastguard Worker extern int _cups_isalpha(int ch);
139*5e7646d2SAndroid Build Coastguard Worker extern int _cups_islower(int ch);
140*5e7646d2SAndroid Build Coastguard Worker extern int _cups_isspace(int ch);
141*5e7646d2SAndroid Build Coastguard Worker extern int _cups_isupper(int ch);
142*5e7646d2SAndroid Build Coastguard Worker extern int _cups_tolower(int ch);
143*5e7646d2SAndroid Build Coastguard Worker extern int _cups_toupper(int ch);
144*5e7646d2SAndroid Build Coastguard Worker #  endif /* _CUPS_INLINE */
145*5e7646d2SAndroid Build Coastguard Worker 
146*5e7646d2SAndroid Build Coastguard Worker 
147*5e7646d2SAndroid Build Coastguard Worker /*
148*5e7646d2SAndroid Build Coastguard Worker  * Prototypes...
149*5e7646d2SAndroid Build Coastguard Worker  */
150*5e7646d2SAndroid Build Coastguard Worker 
151*5e7646d2SAndroid Build Coastguard Worker extern ssize_t	_cups_safe_vsnprintf(char *buffer, size_t bufsize, const char *format, va_list args) _CUPS_PRIVATE;
152*5e7646d2SAndroid Build Coastguard Worker extern void	_cups_strcpy(char *dst, const char *src) _CUPS_PRIVATE;
153*5e7646d2SAndroid Build Coastguard Worker 
154*5e7646d2SAndroid Build Coastguard Worker #  ifndef HAVE_STRDUP
155*5e7646d2SAndroid Build Coastguard Worker extern char	*_cups_strdup(const char *) _CUPS_PRIVATE;
156*5e7646d2SAndroid Build Coastguard Worker #    define strdup _cups_strdup
157*5e7646d2SAndroid Build Coastguard Worker #  endif /* !HAVE_STRDUP */
158*5e7646d2SAndroid Build Coastguard Worker 
159*5e7646d2SAndroid Build Coastguard Worker extern int	_cups_strcasecmp(const char *, const char *) _CUPS_PRIVATE;
160*5e7646d2SAndroid Build Coastguard Worker 
161*5e7646d2SAndroid Build Coastguard Worker extern int	_cups_strncasecmp(const char *, const char *, size_t n) _CUPS_PRIVATE;
162*5e7646d2SAndroid Build Coastguard Worker 
163*5e7646d2SAndroid Build Coastguard Worker #  ifndef HAVE_STRLCAT
164*5e7646d2SAndroid Build Coastguard Worker extern size_t _cups_strlcat(char *, const char *, size_t) _CUPS_PRIVATE;
165*5e7646d2SAndroid Build Coastguard Worker #    define strlcat _cups_strlcat
166*5e7646d2SAndroid Build Coastguard Worker #  endif /* !HAVE_STRLCAT */
167*5e7646d2SAndroid Build Coastguard Worker 
168*5e7646d2SAndroid Build Coastguard Worker #  ifndef HAVE_STRLCPY
169*5e7646d2SAndroid Build Coastguard Worker extern size_t _cups_strlcpy(char *, const char *, size_t) _CUPS_PRIVATE;
170*5e7646d2SAndroid Build Coastguard Worker #    define strlcpy _cups_strlcpy
171*5e7646d2SAndroid Build Coastguard Worker #  endif /* !HAVE_STRLCPY */
172*5e7646d2SAndroid Build Coastguard Worker 
173*5e7646d2SAndroid Build Coastguard Worker #  ifndef HAVE_SNPRINTF
174*5e7646d2SAndroid Build Coastguard Worker extern int	_cups_snprintf(char *, size_t, const char *, ...) _CUPS_FORMAT(3, 4) _CUPS_PRIVATE;
175*5e7646d2SAndroid Build Coastguard Worker #    define snprintf _cups_snprintf
176*5e7646d2SAndroid Build Coastguard Worker #  endif /* !HAVE_SNPRINTF */
177*5e7646d2SAndroid Build Coastguard Worker 
178*5e7646d2SAndroid Build Coastguard Worker #  ifndef HAVE_VSNPRINTF
179*5e7646d2SAndroid Build Coastguard Worker extern int	_cups_vsnprintf(char *, size_t, const char *, va_list) _CUPS_PRIVATE;
180*5e7646d2SAndroid Build Coastguard Worker #    define vsnprintf _cups_vsnprintf
181*5e7646d2SAndroid Build Coastguard Worker #  endif /* !HAVE_VSNPRINTF */
182*5e7646d2SAndroid Build Coastguard Worker 
183*5e7646d2SAndroid Build Coastguard Worker /*
184*5e7646d2SAndroid Build Coastguard Worker  * String pool functions...
185*5e7646d2SAndroid Build Coastguard Worker  */
186*5e7646d2SAndroid Build Coastguard Worker 
187*5e7646d2SAndroid Build Coastguard Worker extern char	*_cupsStrAlloc(const char *s) _CUPS_PRIVATE;
188*5e7646d2SAndroid Build Coastguard Worker extern void	_cupsStrFlush(void) _CUPS_PRIVATE;
189*5e7646d2SAndroid Build Coastguard Worker extern void	_cupsStrFree(const char *s) _CUPS_PRIVATE;
190*5e7646d2SAndroid Build Coastguard Worker extern char	*_cupsStrRetain(const char *s) _CUPS_PRIVATE;
191*5e7646d2SAndroid Build Coastguard Worker extern size_t	_cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes) _CUPS_PRIVATE;
192*5e7646d2SAndroid Build Coastguard Worker 
193*5e7646d2SAndroid Build Coastguard Worker 
194*5e7646d2SAndroid Build Coastguard Worker /*
195*5e7646d2SAndroid Build Coastguard Worker  * Floating point number functions...
196*5e7646d2SAndroid Build Coastguard Worker  */
197*5e7646d2SAndroid Build Coastguard Worker 
198*5e7646d2SAndroid Build Coastguard Worker extern char	*_cupsStrFormatd(char *buf, char *bufend, double number,
199*5e7646d2SAndroid Build Coastguard Worker 		                 struct lconv *loc) _CUPS_PRIVATE;
200*5e7646d2SAndroid Build Coastguard Worker extern double	_cupsStrScand(const char *buf, char **bufptr,
201*5e7646d2SAndroid Build Coastguard Worker 		              struct lconv *loc) _CUPS_PRIVATE;
202*5e7646d2SAndroid Build Coastguard Worker 
203*5e7646d2SAndroid Build Coastguard Worker 
204*5e7646d2SAndroid Build Coastguard Worker /*
205*5e7646d2SAndroid Build Coastguard Worker  * Date function...
206*5e7646d2SAndroid Build Coastguard Worker  */
207*5e7646d2SAndroid Build Coastguard Worker 
208*5e7646d2SAndroid Build Coastguard Worker extern char	*_cupsStrDate(char *buf, size_t bufsize, time_t timeval) _CUPS_PRIVATE;
209*5e7646d2SAndroid Build Coastguard Worker 
210*5e7646d2SAndroid Build Coastguard Worker 
211*5e7646d2SAndroid Build Coastguard Worker /*
212*5e7646d2SAndroid Build Coastguard Worker  * C++ magic...
213*5e7646d2SAndroid Build Coastguard Worker  */
214*5e7646d2SAndroid Build Coastguard Worker 
215*5e7646d2SAndroid Build Coastguard Worker #  ifdef __cplusplus
216*5e7646d2SAndroid Build Coastguard Worker }
217*5e7646d2SAndroid Build Coastguard Worker #  endif /* __cplusplus */
218*5e7646d2SAndroid Build Coastguard Worker 
219*5e7646d2SAndroid Build Coastguard Worker #endif /* !_CUPS_STRING_H_ */
220