Skip to content

Commit

Permalink
Merge pull request #1 from mlocati/use-isset-instead-of-strlen-fixes
Browse files Browse the repository at this point in the history
Correct replacement of strlen with isset
  • Loading branch information
LukasReschke committed Jan 18, 2015
2 parents af84c0a + f1c7dea commit dca5f5b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions code/Data.php
Expand Up @@ -254,7 +254,7 @@ public static function guessFullLocale($language = '', $script = '')
foreach ($keys as $key) {
if (isset($data[$key])) {
$result = $data[$key];
if (isset($script[1]) && (stripos($result, "$language-$script-") !== 0)) {
if (isset($script[0]) && (stripos($result, "$language-$script-") !== 0)) {
$parts = static::explodeLocale($result);
if (!is_null($parts)) {
$result = "{$parts['language']}-$script-{$parts['territory']}";
Expand Down Expand Up @@ -407,13 +407,13 @@ public static function explodeLocale($locale)
$chunkCount = count($chunks);
for ($i = 1; $ok && ($i < $chunkCount); $i++) {
if (preg_match('/^[a-z]{4}$/', $chunks[$i])) {
if (isset($script[1])) {
if (isset($script[0])) {
$ok = false;
} else {
$script = ucfirst($chunks[$i]);
}
} elseif (preg_match('/^([a-z]{2})|([0-9]{3})$/', $chunks[$i])) {
if (isset($territory[1])) {
if (isset($territory[0])) {
$ok = false;
} else {
$territory = strtoupper($chunks[$i]);
Expand Down Expand Up @@ -495,7 +495,7 @@ protected static function getLocaleAlternatives($locale, $addFallback = true)
}
}
$territories = array();
while (isset($territory[1])) {
while (isset($territory[0])) {
$territories[] = $territory;
$territory = \Punic\Territory::getParentTerritoryCode($territory);
}
Expand Down
2 changes: 1 addition & 1 deletion code/Misc.php
Expand Up @@ -169,7 +169,7 @@ public static function getBrowserLocales($ignoreCache = false)
public static function parseHttpAcceptLanguage($httpAcceptLanguages)
{
$result = array();
if (is_string($httpAcceptLanguages) && (isset($httpAcceptLanguages[1]))) {
if (is_string($httpAcceptLanguages) && (isset($httpAcceptLanguages[0]))) {
foreach (explode(',', $httpAcceptLanguages) as $httpAcceptLanguage) {
if (preg_match('/^([a-z]{2,3}(?:[_\\-][a-z]+)*)(?:\\s*;(?:\\s*q(?:\\s*=(?:\\s*([\\d.]+))?)?)?)?$/', strtolower(trim($httpAcceptLanguage, " \t")), $m)) {
if (count($m) > 2) {
Expand Down
4 changes: 2 additions & 2 deletions code/Unit.php
Expand Up @@ -131,7 +131,7 @@ public static function getMeasurementSystemFor($territoryCode)
public static function getCountriesWithMeasurementSystem($measurementSystem)
{
$result = array();
if (is_string($measurementSystem) && (isset($measurementSystem[1]))) {
if (is_string($measurementSystem) && (isset($measurementSystem[0]))) {
$someGroup = false;
$data = \Punic\Data::getGeneric('measurementData');
foreach ($data['measurementSystem'] as $territory => $ms) {
Expand Down Expand Up @@ -195,7 +195,7 @@ public static function getPaperSizeFor($territoryCode)
public static function getCountriesWithPaperSize($paperSize)
{
$result = array();
if (is_string($paperSize) && (isset($paperSize[1]))) {
if (is_string($paperSize) && (isset($paperSize[0]))) {
$someGroup = false;
$data = \Punic\Data::getGeneric('measurementData');
foreach ($data['paperSize'] as $territory => $ms) {
Expand Down

0 comments on commit dca5f5b

Please sign in to comment.