00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef MAGICKCORE_STRING_PRIVATE_H
00019 #define MAGICKCORE_STRING_PRIVATE_H
00020
00021 #include "MagickCore/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 double StringToDouble(const char *magick_restrict string,
00043 char **magick_restrict sentinal)
00044 {
00045 return(InterpretLocaleValue(string,sentinal));
00046 }
00047
00048 static inline char *StringLocateSubstring(const char *haystack,
00049 const char *needle)
00050 {
00051 #if defined(MAGICKCORE_HAVE_STRCASESTR)
00052 return((char *) strcasestr(haystack,needle));
00053 #else
00054 {
00055 size_t
00056 length_needle,
00057 length_haystack;
00058
00059 register ssize_t
00060 i;
00061
00062 if (!haystack || !needle)
00063 return(NULL);
00064 length_needle=strlen(needle);
00065 length_haystack=strlen(haystack)-length_needle+1;
00066 for (i=0; i < length_haystack; i++)
00067 {
00068 register size_t
00069 j;
00070
00071 for (j=0; j < length_needle; j++)
00072 {
00073 unsigned char c1 = haystack[i+j];
00074 unsigned char c2 = needle[j];
00075 if (toupper(c1) != toupper(c2))
00076 goto next;
00077 }
00078 return((char *) haystack+i);
00079 next:
00080 ;
00081 }
00082 return((char *) NULL);
00083 }
00084 #endif
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 MagickSizeType StringToMagickSizeType(const char *string,
00113 const double interval)
00114 {
00115 double
00116 value;
00117
00118 value=SiPrefixToDoubleInterval(string,interval);
00119 if (value >= (double) MagickULLConstant(~0))
00120 return(MagickULLConstant(~0));
00121 return((MagickSizeType) value);
00122 }
00123
00124 static inline size_t StringToSizeType(const char *string,const double interval)
00125 {
00126 double
00127 value;
00128
00129 value=SiPrefixToDoubleInterval(string,interval);
00130 if (value >= (double) MagickULLConstant(~0))
00131 return(~0UL);
00132 return((size_t) value);
00133 }
00134
00135 static inline unsigned long StringToUnsignedLong(
00136 const char *magick_restrict value)
00137 {
00138 return(strtoul(value,(char **) NULL,10));
00139 }
00140
00141 #if defined(__cplusplus) || defined(c_plusplus)
00142 }
00143 #endif
00144
00145 #endif