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 <string.h>
00022 #include "magick/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 const char *StringLocateSubstring(const char *haystack,
00044 const char *needle)
00045 {
00046 #if defined(MAGICKCORE_HAVE_STRCASESTR)
00047 return(strcasestr(haystack,needle));
00048 #else
00049 {
00050 size_t
00051 length_needle,
00052 length_haystack;
00053
00054 register ssize_t
00055 i;
00056
00057 if (!haystack || !needle)
00058 return(NULL);
00059 length_needle=strlen(needle);
00060 length_haystack=strlen(haystack)-length_needle+1;
00061 for (i=0; i < length_haystack; i++)
00062 {
00063 register size_t
00064 j;
00065
00066 for (j=0; j < length_needle; j++)
00067 {
00068 unsigned char c1 = haystack[i+j];
00069 unsigned char c2 = needle[j];
00070 if (toupper(c1) != toupper(c2))
00071 goto next;
00072 }
00073 return((char *) haystack+i);
00074 next:
00075 ;
00076 }
00077 return((char *) NULL);
00078 }
00079 #endif
00080 }
00081
00082 static inline double StringToDouble(const char *magick_restrict string,
00083 char **magick_restrict sentinal)
00084 {
00085 return(InterpretLocaleValue(string,sentinal));
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 size_t StringToSizeType(const char *string,const double interval)
00114 {
00115 double
00116 value;
00117
00118 value=SiPrefixToDoubleInterval(string,interval);
00119 if (value >= (double) MagickULLConstant(~0))
00120 return(~0UL);
00121 return((size_t) value);
00122 }
00123
00124 static inline unsigned long StringToUnsignedLong(
00125 const char *magick_restrict value)
00126 {
00127 return(strtoul(value,(char **) NULL,10));
00128 }
00129
00130 #if defined(__cplusplus) || defined(c_plusplus)
00131 }
00132 #endif
00133
00134 #endif