MagickCore  6.9.11-60
Convert, Edit, Or Compose Bitmap Images
string-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2021 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 "magick/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 const char *StringLocateSubstring(const char *haystack,
44  const char *needle)
45 {
46 #if defined(MAGICKCORE_HAVE_STRCASESTR)
47  return(strcasestr(haystack,needle));
48 #else
49  {
50  size_t
51  length_needle,
52  length_haystack;
53 
54  size_t
55  i;
56 
57  if (!haystack || !needle)
58  return(NULL);
59  length_needle=strlen(needle);
60  length_haystack=strlen(haystack)-length_needle+1;
61  for (i=0; i < length_haystack; i++)
62  {
63  size_t
64  j;
65 
66  for (j=0; j < length_needle; j++)
67  {
68  unsigned char c1 = (unsigned char) haystack[i+j];
69  unsigned char c2 = (unsigned char) needle[j];
70  if (toupper((int) c1) != toupper((int) c2))
71  goto next;
72  }
73  return((char *) haystack+i);
74  next:
75  ;
76  }
77  return((char *) NULL);
78  }
79 #endif
80 }
81 
82 static inline double StringToDouble(const char *magick_restrict string,
83  char **magick_restrict sentinal)
84 {
85  return(InterpretLocaleValue(string,sentinal));
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 size_t StringToSizeType(const char *string,const double interval)
114 {
115  double
116  value;
117 
118  value=SiPrefixToDoubleInterval(string,interval);
119  if (value >= (double) MagickULLConstant(~0))
120  return(~0UL);
121  return((size_t) value);
122 }
123 
124 static inline MagickSizeType StringToMagickSizeType(const char *string,
125  const double interval)
126 {
127  double
128  value;
129 
130  value=SiPrefixToDoubleInterval(string,interval);
131  if (value >= (double) MagickULLConstant(~0))
132  return(MagickULLConstant(~0));
133  return((MagickSizeType) value);
134 }
135 
136 
137 static inline unsigned long StringToUnsignedLong(
138  const char *magick_restrict value)
139 {
140  return(strtoul(value,(char **) NULL,10));
141 }
142 
143 #if defined(__cplusplus) || defined(c_plusplus)
144 }
145 #endif
146 
147 #endif
#define magick_restrict
Definition: MagickCore.h:41
MagickExport double InterpretLocaleValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: locale.c:1000
#define MagickULLConstant(c)
Definition: magick-type.h:39
size_t MagickSizeType
Definition: magick-type.h:140
static MagickSizeType StringToMagickSizeType(const char *string, const double interval)
Definition: string-private.h:124
static size_t StringToSizeType(const char *string, const double interval)
Definition: string-private.h:113
static long StringToLong(const char *magick_restrict value)
Definition: string-private.h:108
static double SiPrefixToDoubleInterval(const char *string, const double interval)
Definition: string-private.h:28
static double StringToDouble(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: string-private.h:82
static const char * StringLocateSubstring(const char *haystack, const char *needle)
Definition: string-private.h:43
static int StringToInteger(const char *magick_restrict value)
Definition: string-private.h:103
static unsigned long StringToUnsignedLong(const char *magick_restrict value)
Definition: string-private.h:137
static double StringToDoubleInterval(const char *string, const double interval)
Definition: string-private.h:88
MagickExport double InterpretSiPrefixValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: string.c:1321