]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/string-private.h
Merge changes from CUPS 1.6svn-r9968.
[thirdparty/cups.git] / cups / string-private.h
CommitLineData
ef416fc2 1/*
71e16022 2 * "$Id$"
ef416fc2 3 *
71e16022 4 * Private string definitions for CUPS.
ef416fc2 5 *
88f9aafc 6 * Copyright 2007-2011 by Apple Inc.
4400e98d 7 * Copyright 1997-2006 by Easy Software Products.
ef416fc2 8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
ef416fc2 14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 */
17
71e16022
MS
18#ifndef _CUPS_STRING_PRIVATE_H_
19# define _CUPS_STRING_PRIVATE_H_
ef416fc2 20
21/*
22 * Include necessary headers...
23 */
24
ef416fc2 25# include <stdio.h>
a74454a7 26# include <stdlib.h>
ef416fc2 27# include <stdarg.h>
28# include <ctype.h>
71e16022 29# include <errno.h>
757d2cad 30# include <locale.h>
ef416fc2 31
71e16022 32# include "config.h"
a74454a7 33
ef416fc2 34# ifdef HAVE_STRING_H
35# include <string.h>
36# endif /* HAVE_STRING_H */
37
38# ifdef HAVE_STRINGS_H
39# include <strings.h>
40# endif /* HAVE_STRINGS_H */
41
42# ifdef HAVE_BSTRING_H
43# include <bstring.h>
44# endif /* HAVE_BSTRING_H */
45
46
ef416fc2 47/*
48 * C++ magic...
49 */
50
51# ifdef __cplusplus
52extern "C" {
53# endif /* __cplusplus */
54
55
4400e98d 56/*
57 * String pool structures...
58 */
59
745129be
MS
60# define _CUPS_STR_GUARD 0x12344321
61
4400e98d 62typedef struct _cups_sp_item_s /**** String Pool Item ****/
63{
745129be
MS
64# ifdef DEBUG_GUARDS
65 unsigned int guard; /* Guard word */
66# endif /* DEBUG_GUARDS */
4400e98d 67 unsigned int ref_count; /* Reference count */
426c6a59 68 char str[1]; /* String */
4400e98d 69} _cups_sp_item_t;
70
71
7cf5915e
MS
72/*
73 * Replacements for the ctype macros that are not affected by locale, since we
74 * really only care about testing for ASCII characters when parsing files, etc.
7cf5915e
MS
75 *
76 * The _CUPS_INLINE definition controls whether we get an inline function body,
77 * and external function body, or an external definition.
78 */
79
80# if defined(__GNUC__) || __STDC_VERSION__ >= 199901L
81# define _CUPS_INLINE static inline
82# elif defined(_MSC_VER)
83# define _CUPS_INLINE static __inline
84# elif defined(_CUPS_STRING_C_)
85# define _CUPS_INLINE
86# endif /* __GNUC__ || __STDC_VERSION__ */
87
88# ifdef _CUPS_INLINE
89_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
90_cups_isalnum(int ch) /* I - Character to test */
91{
92 return ((ch >= '0' && ch <= '9') ||
93 (ch >= 'A' && ch <= 'Z') ||
94 (ch >= 'a' && ch <= 'z'));
95}
96
97_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
98_cups_isalpha(int ch) /* I - Character to test */
99{
100 return ((ch >= 'A' && ch <= 'Z') ||
101 (ch >= 'a' && ch <= 'z'));
102}
103
104_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
105_cups_isspace(int ch) /* I - Character to test */
106{
107 return (ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' ||
108 ch == '\v');
109}
110
111_CUPS_INLINE int /* O - 1 on match, 0 otherwise */
112_cups_isupper(int ch) /* I - Character to test */
113{
114 return (ch >= 'A' && ch <= 'Z');
115}
88f9aafc
MS
116
117_CUPS_INLINE int /* O - Converted character */
118_cups_tolower(int ch) /* I - Character to convert */
119{
120 return (_cups_isupper(ch) ? ch - 'A' + 'a' : ch);
121}
7cf5915e
MS
122# else
123extern int _cups_isalnum(int ch);
124extern int _cups_isalpha(int ch);
125extern int _cups_isspace(int ch);
126extern int _cups_isupper(int ch);
88f9aafc 127extern int _cups_tolower(int ch);
7cf5915e
MS
128# endif /* _CUPS_INLINE */
129
130
ef416fc2 131/*
132 * Prototypes...
133 */
134
135extern void _cups_strcpy(char *dst, const char *src);
136
137# ifndef HAVE_STRDUP
138extern char *_cups_strdup(const char *);
139# define strdup _cups_strdup
140# endif /* !HAVE_STRDUP */
141
ef416fc2 142extern int _cups_strcasecmp(const char *, const char *);
ef416fc2 143
ef416fc2 144extern int _cups_strncasecmp(const char *, const char *, size_t n);
ef416fc2 145
146# ifndef HAVE_STRLCAT
147extern size_t _cups_strlcat(char *, const char *, size_t);
148# define strlcat _cups_strlcat
149# endif /* !HAVE_STRLCAT */
150
151# ifndef HAVE_STRLCPY
152extern size_t _cups_strlcpy(char *, const char *, size_t);
153# define strlcpy _cups_strlcpy
154# endif /* !HAVE_STRLCPY */
155
156# ifndef HAVE_SNPRINTF
157extern int _cups_snprintf(char *, size_t, const char *, ...)
85dda01c 158 __attribute__ ((__format__ (__printf__, 3, 4)));
ef416fc2 159# define snprintf _cups_snprintf
160# endif /* !HAVE_SNPRINTF */
161
162# ifndef HAVE_VSNPRINTF
163extern int _cups_vsnprintf(char *, size_t, const char *, va_list);
164# define vsnprintf _cups_vsnprintf
165# endif /* !HAVE_VSNPRINTF */
166
4400e98d 167/*
168 * String pool functions...
169 */
170
757d2cad 171extern char *_cupsStrAlloc(const char *s);
d6ae789d 172extern void _cupsStrFlush(void);
757d2cad 173extern void _cupsStrFree(const char *s);
e07d4801 174extern char *_cupsStrRetain(const char *s);
757d2cad 175extern size_t _cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes);
176
177
178/*
179 * Floating point number functions...
180 */
181
182extern char *_cupsStrFormatd(char *buf, char *bufend, double number,
183 struct lconv *loc);
184extern double _cupsStrScand(const char *buf, char **bufptr,
185 struct lconv *loc);
4400e98d 186
ef416fc2 187
188/*
189 * C++ magic...
190 */
191
192# ifdef __cplusplus
193}
194# endif /* __cplusplus */
195
196#endif /* !_CUPS_STRING_H_ */
197
198/*
71e16022 199 * End of "$Id$".
ef416fc2 200 */