MagickCore 7.1.1-43
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/script/license.php
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
28/* Custom implementation so we can use sscanf without defining _CRT_SECURE_NO_WARNINGS */
29static inline int MagickSscanf(const char* buffer,const char* format, ...)
30{
31 int
32 ret;
33
34 va_list
35 args;
36 va_start(args,format);
37#if _MSC_VER
38 #pragma warning(push)
39 #pragma warning(disable:4996)
40#endif
41 ret=vsscanf(buffer,format,args);
42#if _MSC_VER
43 #pragma warning(pop)
44#endif
45 va_end(args);
46 return(ret);
47}
48
49static inline double SiPrefixToDoubleInterval(const char *string,
50 const double interval)
51{
52 char
53 *q;
54
55 double
56 value;
57
58 value=InterpretSiPrefixValue(string,&q);
59 if (*q == '%')
60 value*=interval/100.0;
61 return(value);
62}
63
64static inline double StringToDouble(const char *magick_restrict string,
65 char *magick_restrict *sentinel)
66{
67 return(InterpretLocaleValue(string,sentinel));
68}
69
70static inline const char *StringLocateSubstring(const char *haystack,
71 const char *needle)
72{
73#if defined(MAGICKCORE_HAVE_STRCASESTR)
74 return(strcasestr(haystack,needle));
75#else
76 {
77 size_t
78 length_needle,
79 length_haystack;
80
81 size_t
82 i;
83
84 if (!haystack || !needle)
85 return(NULL);
86 length_needle=strlen(needle);
87 length_haystack=strlen(haystack)-length_needle+1;
88 for (i=0; i < length_haystack; i++)
89 {
90 size_t
91 j;
92
93 for (j=0; j < length_needle; j++)
94 {
95 unsigned char c1 = (unsigned char) haystack[i+j];
96 unsigned char c2 = (unsigned char) needle[j];
97 if (toupper((int) c1) != toupper((int) c2))
98 goto next;
99 }
100 return((char *) haystack+i);
101 next:
102 ;
103 }
104 return((char *) NULL);
105 }
106#endif
107}
108
109static inline double StringToDoubleInterval(const char *string,
110 const double interval)
111{
112 char
113 *q;
114
115 double
116 value;
117
118 value=InterpretLocaleValue(string,&q);
119 if (*q == '%')
120 value*=interval/100.0;
121 return(value);
122}
123
124static inline int StringToInteger(const char *magick_restrict value)
125{
126 if (value == (const char *) NULL)
127 return(0);
128 return((int) strtol(value,(char **) NULL,10));
129}
130
131static inline long StringToLong(const char *magick_restrict value)
132{
133 if (value == (const char *) NULL)
134 return(0);
135 return(strtol(value,(char **) NULL,10));
136}
137
138static inline MagickOffsetType StringToMagickOffsetType(const char *string,
139 const double interval)
140{
141 double
142 value;
143
144 value=SiPrefixToDoubleInterval(string,interval);
145 if (value >= (double) MagickULLConstant(~0))
146 return((MagickOffsetType) MagickULLConstant(~0));
147 return((MagickOffsetType) value);
148}
149
150static inline MagickSizeType StringToMagickSizeType(const char *string,
151 const double interval)
152{
153 double
154 value;
155
156 value=SiPrefixToDoubleInterval(string,interval);
157 if (value >= (double) MagickULLConstant(~0))
158 return(MagickULLConstant(~0));
159 return((MagickSizeType) value);
160}
161
162static inline size_t StringToSizeType(const char *string,const double interval)
163{
164 double
165 value;
166
167 value=SiPrefixToDoubleInterval(string,interval);
168 if (value >= (double) MagickULLConstant(~0))
169 return(~0UL);
170 return((size_t) value);
171}
172
173static inline unsigned long StringToUnsignedLong(
174 const char *magick_restrict value)
175{
176 if (value == (const char *) NULL)
177 return(0);
178 return(strtoul(value,(char **) NULL,10));
179}
180
181#if defined(__cplusplus) || defined(c_plusplus)
182}
183#endif
184
185#endif