string-private.h

Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization
00003   dedicated to making software imaging solutions freely available.
00004 
00005   You may not use this file except in compliance with the License.  You may
00006   obtain a copy of the License at
00007 
00008     https://imagemagick.org/script/license.php
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   MagickCore private string methods.
00017 */
00018 #ifndef MAGICKCORE_STRING_PRIVATE_H
00019 #define MAGICKCORE_STRING_PRIVATE_H
00020 
00021 #include <string.h>
00022 #include "MagickCore/locale_.h"
00023 
00024 #if defined(__cplusplus) || defined(c_plusplus)
00025 extern "C" {
00026 #endif
00027 
00028 static inline double SiPrefixToDoubleInterval(const char *string,
00029   const double interval)
00030 {
00031   char
00032     *q;
00033 
00034   double
00035     value;
00036 
00037   value=InterpretSiPrefixValue(string,&q);
00038   if (*q == '%')
00039     value*=interval/100.0;
00040   return(value);
00041 }
00042 
00043 static inline double StringToDouble(const char *magick_restrict string,
00044   char **magick_restrict sentinal)
00045 {
00046   return(InterpretLocaleValue(string,sentinal));
00047 }
00048 
00049 static inline char *StringLocateSubstring(const char *haystack,
00050   const char *needle)
00051 {
00052 #if defined(MAGICKCORE_HAVE_STRCASESTR)
00053   return((char *) strcasestr(haystack,needle));
00054 #else
00055   {
00056     size_t
00057       length_needle,
00058       length_haystack;
00059 
00060     register ssize_t
00061       i;
00062 
00063     if (!haystack || !needle)
00064       return(NULL);
00065     length_needle=strlen(needle);
00066     length_haystack=strlen(haystack)-length_needle+1;
00067     for (i=0; i < length_haystack; i++)
00068     {
00069       register size_t
00070         j;
00071 
00072       for (j=0; j < length_needle; j++)
00073       {
00074         unsigned char c1 = haystack[i+j];
00075         unsigned char c2 = needle[j];
00076         if (toupper(c1) != toupper(c2))
00077           goto next;
00078       }
00079       return((char *) haystack+i);
00080       next:
00081        ;
00082     }
00083     return((char *) NULL);
00084   }
00085 #endif
00086 }
00087 
00088 static inline double StringToDoubleInterval(const char *string,
00089   const double interval)
00090 {
00091   char
00092     *q;
00093 
00094   double
00095     value;
00096 
00097   value=InterpretLocaleValue(string,&q);
00098   if (*q == '%')
00099     value*=interval/100.0;
00100   return(value);
00101 }
00102 
00103 static inline int StringToInteger(const char *magick_restrict value)
00104 {
00105   return((int) strtol(value,(char **) NULL,10));
00106 }
00107 
00108 static inline long StringToLong(const char *magick_restrict value)
00109 {
00110   return(strtol(value,(char **) NULL,10));
00111 }
00112 
00113 static inline MagickSizeType StringToMagickSizeType(const char *string,
00114   const double interval)
00115 {
00116   double
00117     value;
00118 
00119   value=SiPrefixToDoubleInterval(string,interval);
00120   if (value >= (double) MagickULLConstant(~0))
00121     return(MagickULLConstant(~0));
00122   return((MagickSizeType) value);
00123 }
00124 
00125 static inline size_t StringToSizeType(const char *string,const double interval)
00126 {
00127   double
00128     value;
00129 
00130   value=SiPrefixToDoubleInterval(string,interval);
00131   if (value >= (double) MagickULLConstant(~0))
00132     return(~0UL);
00133   return((size_t) value);
00134 }
00135 
00136 static inline unsigned long StringToUnsignedLong(
00137   const char *magick_restrict value)
00138 {
00139   return(strtoul(value,(char **) NULL,10));
00140 }
00141 
00142 #if defined(__cplusplus) || defined(c_plusplus)
00143 }
00144 #endif
00145 
00146 #endif

Generated on 18 Nov 2019 for MagickCore by  doxygen 1.6.1