Skip to content

Commit

Permalink
Fix most of the coding standards issues in I18n/
Browse files Browse the repository at this point in the history
There are a number of whitespace related issues in Multibyte, and
variable name related ones in I18n that cannot be easily changed.
  • Loading branch information
markstory committed Mar 4, 2012
1 parent 15e6e9d commit c5be343
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
17 changes: 10 additions & 7 deletions lib/Cake/I18n/I18n.php
Expand Up @@ -97,6 +97,8 @@ class I18n {
'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', 'LC_MESSAGES'
);

protected $_escape = null;

/**
* Constructor, use I18n::getInstance() to get the i18n translation object.
*
Expand Down Expand Up @@ -560,7 +562,7 @@ public static function loadLocaleDefinition($filename) {
$replacements = array_map('crc32', $mustEscape);
$value = str_replace($mustEscape, $replacements, $value);
$value = explode(';', $value);
$_this->__escape = $escape;
$_this->_escape = $escape;
foreach ($value as $i => $val) {
$val = trim($val, '"');
$val = preg_replace_callback('/(?:<)?(.[^>]*)(?:>)?/', array(&$_this, '_parseLiteralValue'), $val);
Expand All @@ -585,16 +587,16 @@ public static function loadLocaleDefinition($filename) {
*/
protected function _parseLiteralValue($string) {
$string = $string[1];
if (substr($string, 0, 2) === $this->__escape . 'x') {
$delimiter = $this->__escape . 'x';
if (substr($string, 0, 2) === $this->_escape . 'x') {
$delimiter = $this->_escape . 'x';
return join('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string)))));
}
if (substr($string, 0, 2) === $this->__escape . 'd') {
$delimiter = $this->__escape . 'd';
if (substr($string, 0, 2) === $this->_escape . 'd') {
$delimiter = $this->_escape . 'd';
return join('', array_map('chr', array_filter(explode($delimiter, $string))));
}
if ($string[0] === $this->__escape && isset($string[1]) && is_numeric($string[1])) {
$delimiter = $this->__escape;
if ($string[0] === $this->_escape && isset($string[1]) && is_numeric($string[1])) {
$delimiter = $this->_escape;
return join('', array_map('chr', array_filter(explode($delimiter, $string))));
}
if (substr($string, 0, 3) === 'U00') {
Expand Down Expand Up @@ -622,4 +624,5 @@ protected function _translateTime($format, $domain) {
}
return $format;
}

}
1 change: 1 addition & 0 deletions lib/Cake/I18n/L10n.php
Expand Up @@ -469,4 +469,5 @@ public function catalog($language = null) {
}
return $this->_l10nCatalog;
}

}
21 changes: 11 additions & 10 deletions lib/Cake/I18n/Multibyte.php
Expand Up @@ -240,7 +240,7 @@ function mb_substr($string, $start, $length = null, $encoding = null) {
* @return string A converted version of the string represented in ASCII.
*/
if (!function_exists('mb_encode_mimeheader')) {
function mb_encode_mimeheader($str, $charset = 'UTF-8', $transfer_encoding = 'B', $linefeed = "\r\n", $indent = 1) {
function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
return Multibyte::mimeEncode($str, $charset, $linefeed);
}
}
Expand Down Expand Up @@ -504,7 +504,7 @@ public static function strrchr($haystack, $needle, $part = false) {
if (isset($needle[0]) && $needle[0] === $check[$position]) {
for ($i = 1; $i < $needleCount; $i++) {
if ($needle[$i] !== $check[$position + $i]) {
if ($needle[$i] === $check[($position + $i) -1]) {
if ($needle[$i] === $check[($position + $i) - 1]) {
$found = true;
}
unset($parts[$position - 1]);
Expand Down Expand Up @@ -566,7 +566,7 @@ public static function strrichr($haystack, $needle, $part = false) {
if (isset($needle[0]) && $needle[0] === $check[$position]) {
for ($i = 1; $i < $needleCount; $i++) {
if ($needle[$i] !== $check[$position + $i]) {
if ($needle[$i] === $check[($position + $i) -1]) {
if ($needle[$i] === $check[($position + $i) - 1]) {
$found = true;
}
unset($parts[$position - 1]);
Expand Down Expand Up @@ -624,7 +624,7 @@ public static function strripos($haystack, $needle, $offset = 0) {
if (isset($needle[0]) && $needle[0] === $haystack[$position]) {
for ($i = 1; $i < $needleCount; $i++) {
if ($needle[$i] !== $haystack[$position + $i]) {
if ($needle[$i] === $haystack[($position + $i) -1]) {
if ($needle[$i] === $haystack[($position + $i) - 1]) {
$position--;
$found = true;
continue;
Expand Down Expand Up @@ -674,7 +674,7 @@ public static function strrpos($haystack, $needle, $offset = 0) {
if (isset($needle[0]) && $needle[0] === $haystack[$position]) {
for ($i = 1; $i < $needleCount; $i++) {
if ($needle[$i] !== $haystack[$position + $i]) {
if ($needle[$i] === $haystack[($position + $i) -1]) {
if ($needle[$i] === $haystack[($position + $i) - 1]) {
$position--;
$found = true;
continue;
Expand Down Expand Up @@ -767,13 +767,13 @@ public static function strtolower($string) {
$length = count($utf8Map);
$lowerCase = array();

for ($i = 0 ; $i < $length; $i++) {
for ($i = 0; $i < $length; $i++) {
$char = $utf8Map[$i];

if ($char < 128) {
$str = strtolower(chr($char));
$strlen = strlen($str);
for ($ii = 0 ; $ii < $strlen; $ii++) {
for ($ii = 0; $ii < $strlen; $ii++) {
$lower = ord(substr($str, $ii, 1));
}
$lowerCase[] = $lower;
Expand Down Expand Up @@ -812,13 +812,13 @@ public static function strtoupper($string) {
$replaced = array();
$upperCase = array();

for ($i = 0 ; $i < $length; $i++) {
for ($i = 0; $i < $length; $i++) {
$char = $utf8Map[$i];

if ($char < 128) {
$str = strtoupper(chr($char));
$strlen = strlen($str);
for ($ii = 0 ; $ii < $strlen; $ii++) {
for ($ii = 0; $ii < $strlen; $ii++) {
$upper = ord(substr($str, $ii, 1));
}
$upperCase[] = $upper;
Expand Down Expand Up @@ -1007,7 +1007,7 @@ public static function mimeEncode($string, $charset = null, $newline = "\r\n") {
* @return string
*/
protected static function _codepoint($decimal) {
if ($decimal > 128 && $decimal < 256) {
if ($decimal > 128 && $decimal < 256) {
$return = '0080_00ff'; // Latin-1 Supplement
} elseif ($decimal < 384) {
$return = '0100_017f'; // Latin Extended-A
Expand Down Expand Up @@ -1103,4 +1103,5 @@ public static function checkMultibyte($string) {
}
return false;
}

}

0 comments on commit c5be343

Please sign in to comment.