diff options
author | Dries Buytaert <dries@buytaert.net> | 2006-12-07 17:02:25 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2006-12-07 17:02:25 +0000 |
commit | f28aa5f3ecbd729b53894d7e091db0dab1368ddc (patch) | |
tree | 5068b84da3b5fb23fe8f27b19c253040ecd09a14 /includes/common.inc | |
parent | 039453164e790bbebfb577732eb76c72caefb726 (diff) | |
download | brdo-f28aa5f3ecbd729b53894d7e091db0dab1368ddc.tar.gz brdo-f28aa5f3ecbd729b53894d7e091db0dab1368ddc.tar.bz2 |
- Patch #92059 by Steven et al: added a memory check to garland/color.module.
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc index 6d4ece2c0..703ca698a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -960,6 +960,27 @@ function format_plural($count, $singular, $plural) { } /** + * Parse a given byte count. + * + * @param $size + * The size expressed as a number of bytes with optional SI size and unit + * suffix (e.g. 2, 3K, 5MB, 10G). + * @return + * An integer representation of the size. + */ +function parse_size($size) { + $suffixes = array( + '' => 1, + 'k' => 1024, + 'm' => 1048576, // 1024 * 1024 + 'g' => 1073741824, // 1024 * 1024 * 1024 + ); + if (preg_match('/([0-9]+)\s*(k|m|g)?(b?(ytes?)?)/i', $size, $match)) { + return $match[1] * $suffixes[drupal_strtolower($match[2])]; + } +} + +/** * Generate a string representation for the given byte count. * * @param $size |