1 /*
2 Copyright 1999-2019 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 "MagickCore/locale_.h"
22
23 #if defined(__cplusplus) || defined(c_plusplus)
24 extern "C" {
25 #endif
26
SiPrefixToDoubleInterval(const char * string,const double interval)27 static inline double SiPrefixToDoubleInterval(const char *string,
28 const double interval)
29 {
30 char
31 *q;
32
33 double
34 value;
35
36 value=InterpretSiPrefixValue(string,&q);
37 if (*q == '%')
38 value*=interval/100.0;
39 return(value);
40 }
41
StringToDouble(const char * magick_restrict string,char ** magick_restrict sentinal)42 static inline double StringToDouble(const char *magick_restrict string,
43 char **magick_restrict sentinal)
44 {
45 return(InterpretLocaleValue(string,sentinal));
46 }
47
StringToDoubleInterval(const char * string,const double interval)48 static inline double StringToDoubleInterval(const char *string,
49 const double interval)
50 {
51 char
52 *q;
53
54 double
55 value;
56
57 value=InterpretLocaleValue(string,&q);
58 if (*q == '%')
59 value*=interval/100.0;
60 return(value);
61 }
62
StringToInteger(const char * magick_restrict value)63 static inline int StringToInteger(const char *magick_restrict value)
64 {
65 return((int) strtol(value,(char **) NULL,10));
66 }
67
StringToLong(const char * magick_restrict value)68 static inline long StringToLong(const char *magick_restrict value)
69 {
70 return(strtol(value,(char **) NULL,10));
71 }
72
StringToMagickSizeType(const char * string,const double interval)73 static inline MagickSizeType StringToMagickSizeType(const char *string,
74 const double interval)
75 {
76 double
77 value;
78
79 value=SiPrefixToDoubleInterval(string,interval);
80 if (value >= (double) MagickULLConstant(~0))
81 return(MagickULLConstant(~0));
82 return((MagickSizeType) value);
83 }
84
StringToSizeType(const char * string,const double interval)85 static inline size_t StringToSizeType(const char *string,
86 const double interval)
87 {
88 double
89 value;
90
91 value=SiPrefixToDoubleInterval(string,interval);
92 if (value >= (double) MagickULLConstant(~0))
93 return((size_t) MagickULLConstant(~0));
94 return((size_t) value);
95 }
96
StringToUnsignedLong(const char * magick_restrict value)97 static inline unsigned long StringToUnsignedLong(
98 const char *magick_restrict value)
99 {
100 return(strtoul(value,(char **) NULL,10));
101 }
102
103 #if defined(__cplusplus) || defined(c_plusplus)
104 }
105 #endif
106
107 #endif
108