Skip to content

Commit

Permalink
Replaced substr_compare with strncmp where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Jul 29, 2014
1 parent 3a1e0f3 commit 100ba6c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
18 changes: 8 additions & 10 deletions build/controllers/PhpDocController.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected function fixFileDoc(&$lines)
foreach($lines as $i => $line) {
$line = trim($line);
if (!empty($line)) {
if (substr_compare($line, 'namespace', 0, 9) === 0) {
if (strncmp($line, 'namespace', 9) === 0) {
$namespace = $i;
$namespaceLine = $line;
} elseif ($namespace !== false) {
Expand Down Expand Up @@ -392,17 +392,15 @@ protected function updateClassPropertyDocs($file, $className, $propertyDoc)
// TODO move these checks to different action
$lines = explode("\n", $newDoc);
$firstLine = trim($lines[1]);
if ($firstLine === '*' || (!empty($firstLine) && substr_compare($firstLine, '* @', 0, 3) === 0)) {
if ($firstLine === '*' || strncmp($firstLine, '* @', 3) === 0) {
$this->stderr("[WARN] Class $className has no short description.\n", Console::FG_YELLOW, Console::BOLD);
}
foreach ($lines as $line) {
$line = trim($line);
if (!empty($line)) {
if (substr_compare($line, '* @since ', 0, 9) === 0) {
$seenSince = true;
} elseif (substr_compare($line, '* @author ', 0, 10) === 0) {
$seenAuthor = true;
}
if (strncmp($line, '* @since ', 9) === 0) {
$seenSince = true;
} elseif (strncmp($line, '* @author ', 10) === 0) {
$seenAuthor = true;
}
}

Expand Down Expand Up @@ -471,13 +469,13 @@ protected function updateDocComment($doc, $properties)
$propertyPosition = false;
foreach ($lines as $i => $line) {
$line = trim($line);
if (!empty($line) && substr_compare($line, '* @property ', 0, 12) === 0) {
if (strncmp($line, '* @property ', 12) === 0) {
$propertyPart = true;
} elseif ($propertyPart && $line == '*') {
$propertyPosition = $i;
$propertyPart = false;
}
if (!empty($line) && substr_compare($line, '* @author ', 0, 10) === 0 && $propertyPosition === false) {
if (strncmp($line, '* @author ', 10) === 0 && $propertyPosition === false) {
$propertyPosition = $i - 1;
$propertyPart = false;
}
Expand Down
6 changes: 3 additions & 3 deletions extensions/authclient/OpenId.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ protected function fetchAxAttributes()
} else {
// 'ax' prefix is either undefined, or points to another extension, so we search for another prefix
foreach ($this->data as $key => $value) {
if (substr_compare($key, 'openid_ns_', 0, 10) === 0 && $value == 'http://openid.net/srv/ax/1.0') {
if (strncmp($key, 'openid_ns_', 10) === 0 && $value == 'http://openid.net/srv/ax/1.0') {
$alias = substr($key, strlen('openid_ns_'));
break;
}
Expand All @@ -775,7 +775,7 @@ protected function fetchAxAttributes()
$attributes = [];
foreach ($this->data as $key => $value) {
$keyMatch = 'openid_' . $alias . '_value_';
if (substr_compare($key, $keyMatch, 0, strlen($keyMatch))) {
if (strncmp($key, $keyMatch, strlen($keyMatch))) {
continue;
}
$key = substr($key, strlen($keyMatch));
Expand All @@ -802,7 +802,7 @@ protected function fetchSregAttributes()
$sregToAx = array_flip($this->axToSregMap);
foreach ($this->data as $key => $value) {
$keyMatch = 'openid_sreg_';
if (substr_compare($key, $keyMatch, 0, strlen($keyMatch))) {
if (strncmp($key, $keyMatch, strlen($keyMatch))) {
continue;
}
$key = substr($key, strlen($keyMatch));
Expand Down
2 changes: 1 addition & 1 deletion framework/console/controllers/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ protected function saveMessagesCategoryToPHP($messages, $fileName, $overwrite, $
ksort($existingMessages);
foreach ($existingMessages as $message => $translation) {
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) {
if (!empty($translation) && substr_compare($translation, '@@', 0, 2) === 0 && substr_compare($translation, '@@', -2) === 0) {
if (!empty($translation) && strncmp($translation, '@@', 2) === 0 && substr_compare($translation, '@@', -2) === 0) {
$todo[$message] = $translation;
} else {
$todo[$message] = '@@' . $translation . '@@';
Expand Down
2 changes: 1 addition & 1 deletion framework/i18n/GettextMoFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function load($filePath, $context)
$separatorPosition = strpos($id, chr(4));


if (($context && $separatorPosition !== false && !empty($id) && substr_compare($id, $context, 0, $separatorPosition) === 0) ||
if (($context && $separatorPosition !== false && strncmp($id, $context, $separatorPosition) === 0) ||
(!$context && $separatorPosition === false)) {
if ($separatorPosition !== false) {
$id = substr($id, $separatorPosition+1);
Expand Down
2 changes: 1 addition & 1 deletion framework/i18n/MessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private function parseToken($token, $args, $locale)
}
$selector = trim($plural[$i++]);

if ($i == 1 && !empty($selector) && substr_compare($selector, 'offset:', 0, 7) === 0) {
if ($i == 1 && strncmp($selector, 'offset:', 7) === 0) {
$offset = (int) trim(mb_substr($selector, 7, ($pos = mb_strpos(str_replace(["\n", "\r", "\t"], ' ', $selector), ' ', 7)) - 7));
$selector = trim(mb_substr($selector, $pos + 1));
}
Expand Down

0 comments on commit 100ba6c

Please sign in to comment.