From f28aa5f3ecbd729b53894d7e091db0dab1368ddc Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 7 Dec 2006 17:02:25 +0000 Subject: - Patch #92059 by Steven et al: added a memory check to garland/color.module. --- includes/common.inc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'includes/common.inc') diff --git a/includes/common.inc b/includes/common.inc index 6d4ece2c0..703ca698a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -959,6 +959,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. * -- cgit v1.2.3