MagickCore  7.0.9
Convert, Edit, Or Compose Bitmap Images
string-private.h
Go to the documentation of this file.
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 
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 
42 static inline double StringToDouble(const char *magick_restrict string,
43  char **magick_restrict sentinal)
44 {
45  return(InterpretLocaleValue(string,sentinal));
46 }
47 
48 static inline char *StringLocateSubstring(const char *haystack,
49  const char *needle)
50 {
51 #if defined(MAGICKCORE_HAVE_STRCASESTR)
52  return((char *) strcasestr(haystack,needle));
53 #else
54  {
55  size_t
56  length_needle,
57  length_haystack;
58 
59  register ssize_t
60  i;
61 
62  if (!haystack || !needle)
63  return(NULL);
64  length_needle=strlen(needle);
65  length_haystack=strlen(haystack)-length_needle+1;
66  for (i=0; i < length_haystack; i++)
67  {
68  register size_t
69  j;
70 
71  for (j=0; j < length_needle; j++)
72  {
73  unsigned char c1 = haystack[i+j];
74  unsigned char c2 = needle[j];
75  if (toupper(c1) != toupper(c2))
76  goto next;
77  }
78  return((char *) haystack+i);
79  next:
80  ;
81  }
82  return((char *) NULL);
83  }
84 #endif
85 }
86 
87 static inline double StringToDoubleInterval(const char *string,
88  const double interval)
89 {
90  char
91  *q;
92 
93  double
94  value;
95 
96  value=InterpretLocaleValue(string,&q);
97  if (*q == '%')
98  value*=interval/100.0;
99  return(value);
100 }
101 
102 static inline int StringToInteger(const char *magick_restrict value)
103 {
104  return((int) strtol(value,(char **) NULL,10));
105 }
106 
107 static inline long StringToLong(const char *magick_restrict value)
108 {
109  return(strtol(value,(char **) NULL,10));
110 }
111 
112 static inline MagickSizeType StringToMagickSizeType(const char *string,
113  const double interval)
114 {
115  double
116  value;
117 
118  value=SiPrefixToDoubleInterval(string,interval);
119  if (value >= (double) MagickULLConstant(~0))
120  return(MagickULLConstant(~0));
121  return((MagickSizeType) value);
122 }
123 
124 static inline size_t StringToSizeType(const char *string,const double interval)
125 {
126  double
127  value;
128 
129  value=SiPrefixToDoubleInterval(string,interval);
130  if (value >= (double) MagickULLConstant(~0))
131  return(~0UL);
132  return((size_t) value);
133 }
134 
135 static inline unsigned long StringToUnsignedLong(
136  const char *magick_restrict value)
137 {
138  return(strtoul(value,(char **) NULL,10));
139 }
140 
141 #if defined(__cplusplus) || defined(c_plusplus)
142 }
143 #endif
144 
145 #endif
#define magick_restrict
Definition: MagickCore.h:41
MagickExport double InterpretSiPrefixValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: string.c:1336
static size_t StringToSizeType(const char *string, const double interval)
Definition: string-private.h:124
static unsigned long StringToUnsignedLong(const char *magick_restrict value)
Definition: string-private.h:135
#define MagickULLConstant(c)
Definition: magick-type.h:36
static int StringToInteger(const char *magick_restrict value)
Definition: string-private.h:102
static double StringToDouble(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: string-private.h:42
static long StringToLong(const char *magick_restrict value)
Definition: string-private.h:107
static double SiPrefixToDoubleInterval(const char *string, const double interval)
Definition: string-private.h:27
size_t MagickSizeType
Definition: magick-type.h:130
static double StringToDoubleInterval(const char *string, const double interval)
Definition: string-private.h:87
static MagickSizeType StringToMagickSizeType(const char *string, const double interval)
Definition: string-private.h:112
static char * StringLocateSubstring(const char *haystack, const char *needle)
Definition: string-private.h:48
MagickExport double InterpretLocaleValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: locale.c:1003