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 "magick/locale_.h"
00022 
00023 #if defined(__cplusplus) || defined(c_plusplus)
00024 extern "C" {
00025 #endif
00026 
00027 static inline double SiPrefixToDoubleInterval(const char *string,
00028   const double interval)
00029 {
00030   char
00031     *q;
00032 
00033   double
00034     value;
00035 
00036   value=InterpretSiPrefixValue(string,&q);
00037   if (*q == '%')
00038     value*=interval/100.0;
00039   return(value);
00040 }
00041 
00042 static inline char *StringLocateSubstring(const char *haystack,
00043   const char *needle)
00044 {
00045 #if defined(MAGICKCORE_HAVE_STRCASESTR)
00046   return((char *) strcasestr(haystack,needle));
00047 #else
00048   {
00049     size_t
00050       length_needle,
00051       length_haystack;
00052 
00053     register ssize_t
00054       i;
00055 
00056     if (!haystack || !needle)
00057       return(NULL);
00058     length_needle=strlen(needle);
00059     length_haystack=strlen(haystack)-length_needle+1;
00060     for (i=0; i < length_haystack; i++)
00061     {
00062       register size_t
00063         j;
00064 
00065       for (j=0; j < length_needle; j++)
00066       {
00067         unsigned char c1 = haystack[i+j];
00068         unsigned char c2 = needle[j];
00069         if (toupper(c1) != toupper(c2))
00070           goto next;
00071       }
00072       return((char *) haystack+i);
00073       next:
00074        ;
00075     }
00076     return((char *) NULL);
00077   }
00078 #endif
00079 }
00080 
00081 static inline double StringToDouble(const char *magick_restrict string,
00082   char **magick_restrict sentinal)
00083 {
00084   return(InterpretLocaleValue(string,sentinal));
00085 }
00086 
00087 static inline double StringToDoubleInterval(const char *string,
00088   const double interval)
00089 {
00090   char
00091     *q;
00092 
00093   double
00094     value;
00095 
00096   value=InterpretLocaleValue(string,&q);
00097   if (*q == '%')
00098     value*=interval/100.0;
00099   return(value);
00100 }
00101 
00102 static inline int StringToInteger(const char *magick_restrict value)
00103 {
00104   return((int) strtol(value,(char **) NULL,10));
00105 }
00106 
00107 static inline long StringToLong(const char *magick_restrict value)
00108 {
00109   return(strtol(value,(char **) NULL,10));
00110 }
00111 
00112 static inline unsigned long StringToUnsignedLong(
00113   const char *magick_restrict value)
00114 {
00115   return(strtoul(value,(char **) NULL,10));
00116 }
00117 
00118 #if defined(__cplusplus) || defined(c_plusplus)
00119 }
00120 #endif
00121 
00122 #endif

Generated on 16 Nov 2019 for MagickCore by  doxygen 1.6.1