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