cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization |
| 3 | dedicated to making software imaging solutions freely available. |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 4 | |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5 | You may not use this file except in compliance with the License. |
| 6 | obtain a copy of the License at |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 7 | |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 8 | http://www.imagemagick.org/script/license.php |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 9 | |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 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 | |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 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 | |
cristy | 7ce14bc | 2010-01-17 00:01:01 +0000 | [diff] [blame] | 59 | static inline int StringToInteger(const char *value) |
| 60 | { |
| 61 | return((int) strtol(value,(char **) NULL,10)); |
| 62 | } |
| 63 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 64 | static inline ssize_t StringToLong(const char *value) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 65 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 66 | return((ssize_t) strtol(value,(char **) NULL,10)); |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 67 | } |
| 68 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 69 | static inline size_t StringToUnsignedLong(const char *value) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 70 | { |
cristy | 5ed838e | 2010-05-31 00:05:35 +0000 | [diff] [blame] | 71 | return((size_t) strtoul(value,(char **) NULL,10)); |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 72 | } |
| 73 | |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 74 | #if defined(__cplusplus) || defined(c_plusplus) |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | #endif |