blob: 95b5187fdfb822d8ba66bfba1f30d8349d60360a [file] [log] [blame]
cristyf2f27272009-12-17 14:48:46 +00001/*
2 Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
cristye27293e2009-12-18 02:53:20 +00004
cristyf2f27272009-12-17 14:48:46 +00005 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
cristye27293e2009-12-18 02:53:20 +00007
cristyf2f27272009-12-17 14:48:46 +00008 http://www.imagemagick.org/script/license.php
cristye27293e2009-12-18 02:53:20 +00009
cristyf2f27272009-12-17 14:48:46 +000010 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)
22extern "C" {
23#endif
24
25static inline double SiPrefixToDouble(const char *string,const double interval)
26{
27 char
28 *q;
29
30 double
31 scale,
32 value;
33
cristyf2f27272009-12-17 14:48:46 +000034 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
54static inline double StringToDouble(const char *value)
55{
56 return(strtod(value,(char **) NULL));
57}
58
cristy7ce14bc2010-01-17 00:01:01 +000059static inline int StringToInteger(const char *value)
60{
61 return((int) strtol(value,(char **) NULL,10));
62}
63
cristy963bbf92010-05-31 00:38:47 +000064static inline long StringToLong(const char *value)
cristyf2f27272009-12-17 14:48:46 +000065{
cristy963bbf92010-05-31 00:38:47 +000066 return(strtol(value,(char **) NULL,10));
cristyf2f27272009-12-17 14:48:46 +000067}
68
cristy963bbf92010-05-31 00:38:47 +000069static inline unsigned long StringToUnsignedLong(const char *value)
cristye27293e2009-12-18 02:53:20 +000070{
cristy963bbf92010-05-31 00:38:47 +000071 return(strtoul(value,(char **) NULL,10));
cristye27293e2009-12-18 02:53:20 +000072}
73
cristyf2f27272009-12-17 14:48:46 +000074#if defined(__cplusplus) || defined(c_plusplus)
75}
76#endif
77
78#endif