]> granicus.if.org Git - imagemagick/blob - magick/string-private.h
(no commit message)
[imagemagick] / magick / string-private.h
1 /*
2   Copyright 1999-2011 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.
6   obtain a copy of the License at
7
8     http://www.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 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24
25 static inline double SiPrefixToDouble(const char *string,const double interval)
26 {
27   char
28     *q;
29
30   double
31     scale,
32     value;
33
34   value=strtod(string,&q);
35   scale=1000.0;
36   if ((*q != '\0') && (tolower((int) ((unsigned char) *(q+1))) == 'i'))
37     scale=1024.0;
38   switch (tolower((int) ((unsigned char) *q)))
39   {
40     case '%': value*=pow(scale,0)*interval/100.0; break;
41     case 'k': value*=pow(scale,1); break;
42     case 'm': value*=pow(scale,2); break;
43     case 'g': value*=pow(scale,3); break;
44     case 't': value*=pow(scale,4); break;
45     case 'p': value*=pow(scale,5); break;
46     case 'e': value*=pow(scale,6); break;
47     case 'z': value*=pow(scale,7); break;
48     case 'y': value*=pow(scale,8); break;
49     default:  break;
50   }
51   return(value);
52 }
53
54 static inline double StringToDouble(const char *value)
55 {
56   return(strtod(value,(char **) NULL));
57 }
58
59 static inline int StringToInteger(const char *value)
60 {
61   return((int) strtol(value,(char **) NULL,10));
62 }
63
64 static inline long StringToLong(const char *value)
65 {
66   return(strtol(value,(char **) NULL,10));
67 }
68
69 static inline unsigned long StringToUnsignedLong(const char *value)
70 {
71   return(strtoul(value,(char **) NULL,10));
72 }
73
74 #if defined(__cplusplus) || defined(c_plusplus)
75 }
76 #endif
77
78 #endif