MagickCore  6.9.10
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 "magick/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 char *StringLocateSubstring(const char *haystack,
43  const char *needle)
44 {
45 #if defined(MAGICKCORE_HAVE_STRCASESTR)
46  return((char *) strcasestr(haystack,needle));
47 #else
48  {
49  size_t
50  length_needle,
51  length_haystack;
52 
53  register ssize_t
54  i;
55 
56  if (!haystack || !needle)
57  return(NULL);
58  length_needle=strlen(needle);
59  length_haystack=strlen(haystack)-length_needle+1;
60  for (i=0; i < length_haystack; i++)
61  {
62  register size_t
63  j;
64 
65  for (j=0; j < length_needle; j++)
66  {
67  unsigned char c1 = haystack[i+j];
68  unsigned char c2 = needle[j];
69  if (toupper(c1) != toupper(c2))
70  goto next;
71  }
72  return((char *) haystack+i);
73  next:
74  ;
75  }
76  return((char *) NULL);
77  }
78 #endif
79 }
80 
81 static inline double StringToDouble(const char *magick_restrict string,
82  char **magick_restrict sentinal)
83 {
84  return(InterpretLocaleValue(string,sentinal));
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 unsigned long StringToUnsignedLong(
113  const char *magick_restrict value)
114 {
115  return(strtoul(value,(char **) NULL,10));
116 }
117 
118 #if defined(__cplusplus) || defined(c_plusplus)
119 }
120 #endif
121 
122 #endif
#define magick_restrict
Definition: MagickCore.h:41
MagickExport double InterpretSiPrefixValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: string.c:1316
static unsigned long StringToUnsignedLong(const char *magick_restrict value)
Definition: string-private.h:112
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:81
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
static double StringToDoubleInterval(const char *string, const double interval)
Definition: string-private.h:87
static char * StringLocateSubstring(const char *haystack, const char *needle)
Definition: string-private.h:42
MagickExport double InterpretLocaleValue(const char *magick_restrict string, char **magick_restrict sentinal)
Definition: locale.c:1000