blob: da1696b3f6b92bbe51b713e75b2fb2b380e51835 [file] [log] [blame]
cristyf2f27272009-12-17 14:48:46 +00001/*
cristy7e41fe82010-12-04 23:12:08 +00002 Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization
cristyf2f27272009-12-17 14:48:46 +00003 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
cristyb51dff52011-05-19 16:55:47 +000034 value=LocaleToDouble(string,&q);
cristyf2f27272009-12-17 14:48:46 +000035 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
cristy7ce14bc2010-01-17 00:01:01 +000054static inline int StringToInteger(const char *value)
55{
56 return((int) strtol(value,(char **) NULL,10));
57}
58
cristy963bbf92010-05-31 00:38:47 +000059static inline long StringToLong(const char *value)
cristyf2f27272009-12-17 14:48:46 +000060{
cristy963bbf92010-05-31 00:38:47 +000061 return(strtol(value,(char **) NULL,10));
cristyf2f27272009-12-17 14:48:46 +000062}
63
cristy963bbf92010-05-31 00:38:47 +000064static inline unsigned long StringToUnsignedLong(const char *value)
cristye27293e2009-12-18 02:53:20 +000065{
cristy963bbf92010-05-31 00:38:47 +000066 return(strtoul(value,(char **) NULL,10));
cristye27293e2009-12-18 02:53:20 +000067}
68
cristyf2f27272009-12-17 14:48:46 +000069#if defined(__cplusplus) || defined(c_plusplus)
70}
71#endif
72
73#endif