From 9b6663f87a7e679ffba691cf516191fc840cf978 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:20:36 -0800 Subject: Update to Kohana r4684 which is now Kohana 2.4 and has substantial changes. --- system/helpers/format.php | 54 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'system/helpers/format.php') diff --git a/system/helpers/format.php b/system/helpers/format.php index fb8a0294..9351afda 100644 --- a/system/helpers/format.php +++ b/system/helpers/format.php @@ -2,15 +2,32 @@ /** * Format helper class. * - * $Id: format.php 4070 2009-03-11 20:37:38Z Geert $ + * $Id: format.php 4679 2009-11-10 01:45:52Z isaiah $ * * @package Core * @author Kohana Team - * @copyright (c) 2007-2008 Kohana Team - * @license http://kohanaphp.com/license.html + * @copyright (c) 2007-2009 Kohana Team + * @license http://kohanaphp.com/license */ class format_Core { + /** + * Formats a number according to the current locale. + * + * @param float + * @param int|boolean number of fractional digits or TRUE to use the locale default + * @return string + */ + public static function number($number, $decimals = 0) + { + $locale = localeconv(); + + if ($decimals === TRUE) + return number_format($number, $locale['frac_digits'], $locale['decimal_point'], $locale['thousands_sep']); + + return number_format($number, $decimals, $locale['decimal_point'], $locale['thousands_sep']); + } + /** * Formats a phone number according to the specified format. * @@ -63,4 +80,35 @@ class format_Core { return $str; } + /** + * Normalizes a hexadecimal HTML color value. All values will be converted + * to lowercase, have a "#" prepended and contain six characters. + * + * @param string hexadecimal HTML color value + * @return string + */ + public static function color($str = '') + { + // Reject invalid values + if ( ! valid::color($str)) + return ''; + + // Convert to lowercase + $str = strtolower($str); + + // Prepend "#" + if ($str[0] !== '#') + { + $str = '#'.$str; + } + + // Expand short notation + if (strlen($str) === 4) + { + $str = '#'.$str[1].$str[1].$str[2].$str[2].$str[3].$str[3]; + } + + return $str; + } + } // End format \ No newline at end of file -- cgit v1.2.3