MagickCore 7.1.2-32
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
string-private.h
1/*
2 Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License. You may
6 obtain a copy of the License at
7
8 https://imagemagick.org/license/
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 MagickCore private string methods.
17*/
18#ifndef MAGICKCORE_STRING_PRIVATE_H
19#define MAGICKCORE_STRING_PRIVATE_H
20
21#include <string.h>
22#include "MagickCore/locale_.h"
23
24#if defined(__cplusplus) || defined(c_plusplus)
25extern "C" {
26#endif
27
28static inline int MagickSscanf(const char *buffer,const char *format,...)
29{
30 int
31 ret;
32
33 va_list
34 args;
35
36 /*
37 Custom implementation so we can use sscanf without defining
38 _CRT_SECURE_NO_WARNINGS.
39 */
40 va_start(args,format);
41#if defined(_MSC_VER)
42 #pragma warning(push)
43 #pragma warning(disable:4996)
44#endif
45 ret=vsscanf(buffer,format,args);
46#if defined(_MSC_VER)
47 #pragma warning(pop)
48#endif
49 va_end(args);
50 return(ret);
51}
52
53static inline double SiPrefixToDoubleInterval(const char *string,
54 const double interval)
55{
56 char
57 *q;
58
59 double
60 value;
61
62 value=InterpretSiPrefixValue(string,&q);
63 if (*q == '%')
64 value*=interval/100.0;
65 return(value);
66}
67
68static inline double StringToDouble(const char *magick_restrict string,
69 char *magick_restrict *sentinel)
70{
71 return(InterpretLocaleValue(string,sentinel));
72}
73
74static inline float StringToFloat(const char *magick_restrict string,
75 char *magick_restrict *sentinel)
76{
77 return((float) InterpretLocaleValue(string,sentinel));
78}
79
80static inline const char *StringLocateSubstring(const char *haystack,
81 const char *needle)
82{
83#if defined(MAGICKCORE_HAVE_STRCASESTR)
84 return(strcasestr(haystack,needle));
85#else
86 {
87 size_t
88 length_needle,
89 length_haystack;
90
91 size_t
92 i;
93
94 if (!haystack || !needle)
95 return(NULL);
96 length_needle=strlen(needle);
97 length_haystack=strlen(haystack)-length_needle+1;
98 for (i=0; i < length_haystack; i++)
99 {
100 size_t
101 j;
102
103 for (j=0; j < length_needle; j++)
104 {
105 unsigned char c1 = (unsigned char) haystack[i+j];
106 unsigned char c2 = (unsigned char) needle[j];
107 if (toupper((int) c1) != toupper((int) c2))
108 goto next;
109 }
110 return((char *) haystack+i);
111 next:
112 ;
113 }
114 return((char *) NULL);
115 }
116#endif
117}
118
119static inline double StringToDoubleInterval(const char *string,
120 const double interval)
121{
122 char
123 *q;
124
125 double
126 value;
127
128 value=InterpretLocaleValue(string,&q);
129 if (*q == '%')
130 value*=interval/100.0;
131 return(value);
132}
133
134static inline int StringToInteger(const char *magick_restrict value)
135{
136 if (value == (const char *) NULL)
137 return(0);
138 return((int) strtol(value,(char **) NULL,10));
139}
140
141static inline long StringToLong(const char *magick_restrict value)
142{
143 if (value == (const char *) NULL)
144 return(0);
145 return(strtol(value,(char **) NULL,10));
146}
147
148static inline MagickOffsetType StringToMagickOffsetType(const char *string,
149 const double interval)
150{
151 double
152 value;
153
154 value=SiPrefixToDoubleInterval(string,interval);
155 if (value >= (double) MagickULLConstant(~0))
156 return((MagickOffsetType) MagickULLConstant(~0));
157 return((MagickOffsetType) value);
158}
159
160static inline MagickSizeType StringToMagickSizeType(const char *string,
161 const double interval)
162{
163 double
164 value;
165
166 value=SiPrefixToDoubleInterval(string,interval);
167 if (value >= (double) MagickULLConstant(~0))
168 return(MagickULLConstant(~0));
169 return((MagickSizeType) value);
170}
171
172static inline size_t StringToSizeType(const char *string,const double interval)
173{
174 double
175 value;
176
177 value=SiPrefixToDoubleInterval(string,interval);
178 if (value >= (double) MagickULLConstant(~0))
179 return(~0UL);
180 return((size_t) value);
181}
182
183static inline unsigned long StringToUnsignedLong(
184 const char *magick_restrict value)
185{
186 if (value == (const char *) NULL)
187 return(0);
188 return(strtoul(value,(char **) NULL,10));
189}
190
191#if defined(__cplusplus) || defined(c_plusplus)
192}
193#endif
194
195#endif