summaryrefslogtreecommitdiff
path: root/framework/I18N
diff options
context:
space:
mode:
authorxue <>2007-03-04 02:20:16 +0000
committerxue <>2007-03-04 02:20:16 +0000
commit391edbb22addfe835c62a506266ca694a9abc3e3 (patch)
tree14977cd9368f556aa54ee208e682bc3cdb58bf2f /framework/I18N
parent3f970f4c8caf67e1dc2fc21ad27a217017a1fbd3 (diff)
Fixed #555.
Diffstat (limited to 'framework/I18N')
-rw-r--r--framework/I18N/core/NumberFormatInfo.php270
1 files changed, 135 insertions, 135 deletions
diff --git a/framework/I18N/core/NumberFormatInfo.php b/framework/I18N/core/NumberFormatInfo.php
index 3531cc7f..2d0d5a36 100644
--- a/framework/I18N/core/NumberFormatInfo.php
+++ b/framework/I18N/core/NumberFormatInfo.php
@@ -16,7 +16,7 @@
* @version $Revision: 1.3 $ $Date: 2005/08/04 05:27:19 $
* @package System.I18N.core
*/
-
+
/**
* Get the CultureInfo class file.
*/
@@ -24,21 +24,21 @@ require_once(dirname(__FILE__).'/CultureInfo.php');
/**
* NumberFormatInfo class
- *
+ *
* Defines how numeric values are formatted and displayed,
* depending on the culture. Numeric values are formatted using
- * standard or custom patterns stored in the properties of a
- * NumberFormatInfo.
+ * standard or custom patterns stored in the properties of a
+ * NumberFormatInfo.
*
- * This class contains information, such as currency, decimal
+ * This class contains information, such as currency, decimal
* separators, and other numeric symbols.
*
- * To create a NumberFormatInfo for a specific culture,
+ * To create a NumberFormatInfo for a specific culture,
* create a CultureInfo for that culture and retrieve the
- * CultureInfo->NumberFormat property. Or use
+ * CultureInfo->NumberFormat property. Or use
* NumberFormatInfo::getInstance($culture).
- * To create a NumberFormatInfo for the invariant culture, use the
- * InvariantInfo::getInvariantInfo().
+ * To create a NumberFormatInfo for the invariant culture, use the
+ * InvariantInfo::getInvariantInfo().
*
*
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
@@ -50,19 +50,19 @@ class NumberFormatInfo
/**
* ICU number formatting data.
- * @var array
+ * @var array
*/
private $data = array();
/**
* A list of properties that are accessable/writable.
- * @var array
+ * @var array
*/
protected $properties = array();
-
+
/**
* The number pattern.
- * @var array
+ * @var array
*/
protected $pattern = array();
@@ -76,7 +76,7 @@ class NumberFormatInfo
* as an attribute/property to retrieve the value.
* @return mixed
*/
- function __get($name)
+ public function __get($name)
{
$getProperty = 'get'.$name;
if(in_array($getProperty, $this->properties))
@@ -84,75 +84,75 @@ class NumberFormatInfo
else
throw new Exception('Property '.$name.' does not exists.');
}
-
+
/**
* Allow functions that begins with 'set' to be called directly
* as an attribute/property to set the value.
*/
- function __set($name, $value)
+ public function __set($name, $value)
{
$setProperty = 'set'.$name;
if(in_array($setProperty, $this->properties))
$this->$setProperty($value);
else
throw new Exception('Property '.$name.' can not be set.');
- }
-
+ }
+
/**
- * Initializes a new writable instance of the NumberFormatInfo class
+ * Initializes a new writable instance of the NumberFormatInfo class
* that is dependent on the ICU data for number, decimal, and currency
- * formatting information. <b>N.B.</b>You should not initialize this
- * class directly unless you know what you are doing. Please use use
+ * formatting information. <b>N.B.</b>You should not initialize this
+ * class directly unless you know what you are doing. Please use use
* NumberFormatInfo::getInstance() to create an instance.
* @param array ICU data for date time formatting.
* @see getInstance()
*/
- function __construct($data=array(), $type=NumberFormatInfo::DECIMAL)
+ public function __construct($data=array(), $type=NumberFormatInfo::DECIMAL)
{
- $this->properties = get_class_methods($this);
-
+ $this->properties = get_class_methods($this);
+
if(empty($data))
throw new Exception('Please provide the ICU data to initialize.');
-
+
$this->data = $data;
-
+
$this->setPattern($type);
}
-
+
/**
* Set the pattern for a specific number pattern. The validate patterns
* NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
* NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
* @param int pattern type.
*/
- function setPattern($type=NumberFormatInfo::DECIMAL)
+ public function setPattern($type=NumberFormatInfo::DECIMAL)
{
if(is_int($type))
- $this->pattern =
+ $this->pattern =
$this->parsePattern($this->data['NumberPatterns'][$type]);
else
$this->pattern = $this->parsePattern($type);
-
- $this->pattern['negInfty'] =
+
+ $this->pattern['negInfty'] =
$this->data['NumberElements'][6].
$this->data['NumberElements'][9];
-
- $this->pattern['posInfty'] =
+
+ $this->pattern['posInfty'] =
$this->data['NumberElements'][11].
- $this->data['NumberElements'][9];
+ $this->data['NumberElements'][9];
}
-
- function getPattern()
+
+ public function getPattern()
{
return $this->pattern;
}
-
+
/**
- * Gets the default NumberFormatInfo that is culture-independent
+ * Gets the default NumberFormatInfo that is culture-independent
* (invariant).
- * @return NumberFormatInfo default NumberFormatInfo.
+ * @return NumberFormatInfo default NumberFormatInfo.
*/
- public function getInvariantInfo($type=NumberFormatInfo::DECIMAL)
+ public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL)
{
static $invariant;
if(is_null($invariant))
@@ -167,16 +167,16 @@ class NumberFormatInfo
/**
* Returns the NumberFormatInfo associated with the specified culture.
* @param CultureInfo the culture that gets the NumberFormat property.
- * @param int the number formatting type, it should be
+ * @param int the number formatting type, it should be
* NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY,
* NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC
- * @return NumberFormatInfo NumberFormatInfo for the specified
- * culture.
+ * @return NumberFormatInfo NumberFormatInfo for the specified
+ * culture.
* @see getCurrencyInstance();
* @see getPercentageInstance();
* @see getScientificInstance();
*/
- public static function getInstance($culture=null,
+ public static function getInstance($culture=null,
$type=NumberFormatInfo::DECIMAL)
{
if ($culture instanceof CultureInfo)
@@ -198,14 +198,14 @@ class NumberFormatInfo
$formatInfo = $cultureInfo->NumberFormat;
$formatInfo->setPattern($type);
return $formatInfo;
- }
+ }
}
-
+
/**
* Returns the currency format info associated with the specified culture.
* @param CultureInfo the culture that gets the NumberFormat property.
- * @return NumberFormatInfo NumberFormatInfo for the specified
- * culture.
+ * @return NumberFormatInfo NumberFormatInfo for the specified
+ * culture.
*/
public static function getCurrencyInstance($culture=null)
{
@@ -215,25 +215,25 @@ class NumberFormatInfo
/**
* Returns the percentage format info associated with the specified culture.
* @param CultureInfo the culture that gets the NumberFormat property.
- * @return NumberFormatInfo NumberFormatInfo for the specified
- * culture.
+ * @return NumberFormatInfo NumberFormatInfo for the specified
+ * culture.
*/
public static function getPercentageInstance($culture=null)
{
return self::getInstance($culture, self::PERCENTAGE);
- }
-
+ }
+
/**
* Returns the scientific format info associated with the specified culture.
* @param CultureInfo the culture that gets the NumberFormat property.
- * @return NumberFormatInfo NumberFormatInfo for the specified
- * culture.
+ * @return NumberFormatInfo NumberFormatInfo for the specified
+ * culture.
*/
public static function getScientificInstance($culture=null)
{
return self::getInstance($culture, self::SCIENTIFIC);
- }
-
+ }
+
/**
* Parse the given pattern and return a list of known properties.
* @param string a number pattern.
@@ -242,7 +242,7 @@ class NumberFormatInfo
protected function parsePattern($pattern)
{
$pattern = explode(';',$pattern);
-
+
$negative = null;
if(count($pattern) > 1)
$negative = $pattern[1];
@@ -254,9 +254,9 @@ class NumberFormatInfo
$hash = '#';
//find the first group point, and decimal point
- $groupPos1 = strrpos($pattern,$comma);
+ $groupPos1 = strrpos($pattern,$comma);
$decimalPos = strrpos($pattern,$dot);
-
+
$groupPos2 = false;
$groupSize1 = false;
$groupSize2 = false;
@@ -264,9 +264,9 @@ class NumberFormatInfo
$info['negPref'] = $this->data['NumberElements'][6];
$info['negPost'] = '';
-
+
$info['negative'] = $negative;
- $info['positive'] = $pattern;
+ $info['positive'] = $pattern;
//find the negative prefix and postfix
if($negative)
@@ -275,7 +275,7 @@ class NumberFormatInfo
$info['negPref'] = $prefixPostfix[0];
$info['negPost'] = $prefixPostfix[1];
}
-
+
$posfix = $this->getPrePostfix($pattern);
$info['posPref'] = $posfix[0];
$info['posPost'] = $posfix[1];
@@ -286,12 +286,12 @@ class NumberFormatInfo
{
//get the second group
$groupPos2 = strrpos(substr($pattern,0,$groupPos1),$comma);
-
+
//get the number of decimal digits
if(is_int($decimalPos))
{
$groupSize1 = $decimalPos - $groupPos1-1;
-
+
}
else
{
@@ -306,7 +306,7 @@ class NumberFormatInfo
}
}
}
-
+
//get the second group size
if(is_int($groupPos2))
$groupSize2 = $groupPos1 - $groupPos2-1;
@@ -324,12 +324,12 @@ class NumberFormatInfo
}
}
}
-
+
if(is_int($decimalPos))
$digitPattern = substr($pattern,0,$decimalPos);
else
$digitPattern = $pattern;
-
+
$digitPattern = preg_replace('/[^0]/','',$digitPattern);
$info['groupPos1'] = $groupPos1;
@@ -341,20 +341,20 @@ class NumberFormatInfo
$info['digitSize'] = strlen($digitPattern);
return $info;
}
-
+
/**
* Get the prefix and postfix of a pattern.
* @param string pattern
- * @return array of prefix and postfix, array(prefix,postfix).
+ * @return array of prefix and postfix, array(prefix,postfix).
*/
protected function getPrePostfix($pattern)
- {
+ {
$regexp = '/[#,\.0]+/';
$result = preg_split($regexp, $pattern);
return array($result[0],$result[1]);
}
-
-
+
+
/**
* Indicates the number of decimal places.
* @return int number of decimal places.
@@ -363,7 +363,7 @@ class NumberFormatInfo
{
return $this->pattern['decimalPoints'];
}
-
+
/**
* Set the number of decimal places.
* @param int number of decimal places.
@@ -372,17 +372,17 @@ class NumberFormatInfo
{
return $this->pattern['decimalPoints'] = $value;
}
-
+
function getDigitSize()
{
return $this->pattern['digitSize'];
}
-
+
function setDigitSize($value)
{
$this->pattern['digitSize'] = $value;
}
-
+
/**
* Gets the string to use as the decimal separator.
* @return string decimal separator.
@@ -391,7 +391,7 @@ class NumberFormatInfo
{
return $this->data['NumberElements'][0];
}
-
+
/**
* Set the string to use as the decimal separator.
* @param string the decimal point
@@ -400,18 +400,18 @@ class NumberFormatInfo
{
return $this->data['NumberElements'][0] = $value;
}
-
+
/**
- * Gets the string that separates groups of digits to the left
+ * Gets the string that separates groups of digits to the left
* of the decimal in currency values.
* @param parameter
- * @return string currency group separator.
+ * @return string currency group separator.
*/
function getGroupSeparator()
{
return $this->data['NumberElements'][1];
}
-
+
/**
* Set the string to use as the group separator.
* @param string the group separator.
@@ -420,40 +420,40 @@ class NumberFormatInfo
{
return $this->data['NumberElements'][1] = $value;
}
-
+
/**
* Gets the number of digits in each group to the left of the decimal
* There can be two grouping sizes, this fucntion
* returns <b>array(group1, group2)</b>, if there is only 1 grouping size,
* group2 will be false.
- * @return array grouping size(s).
+ * @return array grouping size(s).
*/
function getGroupSizes()
{
$group1 = $this->pattern['groupSize1'];
$group2 = $this->pattern['groupSize2'];
-
+
return array($group1, $group2);
}
-
+
/**
* Set the number of digits in each group to the left of the decimal.
* There can be two grouping sizes, the value should
* be an <b>array(group1, group2)</b>, if there is only 1 grouping size,
* group2 should be false.
- * @param array grouping size(s).
- */
+ * @param array grouping size(s).
+ */
function setGroupSizes($groupSize)
{
$this->pattern['groupSize1'] = $groupSize[0];
- $this->pattern['groupSize2'] = $groupSize[1];
+ $this->pattern['groupSize2'] = $groupSize[1];
}
-
+
/**
* Gets the format pattern for negative values.
* The negative pattern is composed of a prefix, and postfix.
* This function returns <b>array(prefix, postfix)</b>.
- * @return arary negative pattern.
+ * @return arary negative pattern.
*/
function getNegativePattern()
{
@@ -461,57 +461,57 @@ class NumberFormatInfo
$postfix = $this->pattern['negPost'];
return array($prefix, $postfix);
}
-
+
/**
* Set the format pattern for negative values.
* The negative pattern is composed of a prefix, and postfix in the form
* <b>array(prefix, postfix)</b>.
- * @param arary negative pattern.
+ * @param arary negative pattern.
*/
function setNegativePattern($pattern)
{
$this->pattern['negPref'] = $pattern[0];
$this->pattern['negPost'] = $pattern[1];
- }
-
+ }
+
/**
* Gets the format pattern for positive values.
* The positive pattern is composed of a prefix, and postfix.
* This function returns <b>array(prefix, postfix)</b>.
- * @return arary positive pattern.
+ * @return arary positive pattern.
*/
function getPositivePattern()
{
$prefix = $this->pattern['posPref'];
$postfix = $this->pattern['posPost'];
- return array($prefix, $postfix);
+ return array($prefix, $postfix);
}
-
+
/**
* Set the format pattern for positive values.
* The positive pattern is composed of a prefix, and postfix in the form
* <b>array(prefix, postfix)</b>.
- * @param arary positive pattern.
+ * @param arary positive pattern.
*/
function setPositivePattern($pattern)
{
$this->pattern['posPref'] = $pattern[0];
$this->pattern['posPost'] = $pattern[1];
- }
-
+ }
+
/**
* Gets the string to use as the currency symbol.
- * @return string currency symbol.
+ * @return string currency symbol.
*/
function getCurrencySymbol($currency='USD')
- {
+ {
if(isset($this->pattern['symbol']))
return $this->pattern['symbol'];
else
- return $this->data['Currencies'][$currency][0];
+ return $this->data['Currencies'][$currency][0];
}
-
+
/**
* Set the string to use as the currency symbol.
* @param string currency symbol.
@@ -520,78 +520,78 @@ class NumberFormatInfo
{
$this->pattern['symbol'] = $symbol;
}
-
+
/**
* Gets the string that represents negative infinity.
- * @return string negative infinity.
+ * @return string negative infinity.
*/
function getNegativeInfinitySymbol()
{
- return $this->pattern['negInfty'];
- }
-
+ return $this->pattern['negInfty'];
+ }
+
/**
* Set the string that represents negative infinity.
- * @param string negative infinity.
+ * @param string negative infinity.
*/
function setNegativeInfinitySymbol($value)
{
$this->pattern['negInfty'] = $value;
- }
-
+ }
+
/**
* Gets the string that represents positive infinity.
- * @return string positive infinity.
+ * @return string positive infinity.
*/
function getPositiveInfinitySymbol()
{
- return $this->pattern['posInfty'];
- }
-
+ return $this->pattern['posInfty'];
+ }
+
/**
* Set the string that represents positive infinity.
- * @param string positive infinity.
+ * @param string positive infinity.
*/
function setPositiveInfinitySymbol($value)
{
$this->pattern['posInfty'] = $value;
}
-
+
/**
* Gets the string that denotes that the associated number is negative.
- * @return string negative sign.
+ * @return string negative sign.
*/
function getNegativeSign()
{
return $this->data['NumberElements'][6];
}
-
+
/**
* Set the string that denotes that the associated number is negative.
- * @param string negative sign.
+ * @param string negative sign.
*/
function setNegativeSign($value)
{
$this->data['NumberElements'][6] = $value;
- }
-
+ }
+
/**
* Gets the string that denotes that the associated number is positive.
- * @return string positive sign.
+ * @return string positive sign.
*/
function getPositiveSign()
{
return $this->data['NumberElements'][11];
}
-
+
/**
* Set the string that denotes that the associated number is positive.
- * @param string positive sign.
+ * @param string positive sign.
*/
function setPositiveSign($value)
{
$this->data['NumberElements'][11] = $value;
- }
+ }
/**
* Gets the string that represents the IEEE NaN (not a number) value.
@@ -601,7 +601,7 @@ class NumberFormatInfo
{
return $this->data['NumberElements'][10];
}
-
+
/**
* Set the string that represents the IEEE NaN (not a number) value.
* @param string NaN symbol.
@@ -609,8 +609,8 @@ class NumberFormatInfo
function setNaNSymbol($value)
{
$this->data['NumberElements'][10] = $value;
- }
-
+ }
+
/**
* Gets the string to use as the percent symbol.
* @return string percent symbol.
@@ -619,7 +619,7 @@ class NumberFormatInfo
{
return $this->data['NumberElements'][3];
}
-
+
/**
* Set the string to use as the percent symbol.
* @param string percent symbol.
@@ -627,8 +627,8 @@ class NumberFormatInfo
function setPercentSymbol($value)
{
$this->data['NumberElements'][3] = $value;
- }
-
+ }
+
/**
* Gets the string to use as the per mille symbol.
* @return string percent symbol.
@@ -637,7 +637,7 @@ class NumberFormatInfo
{
return $this->data['NumberElements'][8];
}
-
+
/**
* Set the string to use as the per mille symbol.
* @param string percent symbol.
@@ -645,7 +645,7 @@ class NumberFormatInfo
function setPerMilleSymbol($value)
{
$this->data['NumberElements'][8] = $value;
- }
+ }
}
?> \ No newline at end of file