Commit 100ba6c3 by Alexander Makarov

Replaced substr_compare with strncmp where possible

parent 3a1e0f3a
...@@ -176,7 +176,7 @@ class PhpDocController extends Controller ...@@ -176,7 +176,7 @@ class PhpDocController extends Controller
foreach($lines as $i => $line) { foreach($lines as $i => $line) {
$line = trim($line); $line = trim($line);
if (!empty($line)) { if (!empty($line)) {
if (substr_compare($line, 'namespace', 0, 9) === 0) { if (strncmp($line, 'namespace', 9) === 0) {
$namespace = $i; $namespace = $i;
$namespaceLine = $line; $namespaceLine = $line;
} elseif ($namespace !== false) { } elseif ($namespace !== false) {
...@@ -392,17 +392,15 @@ class PhpDocController extends Controller ...@@ -392,17 +392,15 @@ class PhpDocController extends Controller
// TODO move these checks to different action // TODO move these checks to different action
$lines = explode("\n", $newDoc); $lines = explode("\n", $newDoc);
$firstLine = trim($lines[1]); $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); $this->stderr("[WARN] Class $className has no short description.\n", Console::FG_YELLOW, Console::BOLD);
} }
foreach ($lines as $line) { foreach ($lines as $line) {
$line = trim($line); $line = trim($line);
if (!empty($line)) { if (strncmp($line, '* @since ', 9) === 0) {
if (substr_compare($line, '* @since ', 0, 9) === 0) { $seenSince = true;
$seenSince = true; } elseif (strncmp($line, '* @author ', 10) === 0) {
} elseif (substr_compare($line, '* @author ', 0, 10) === 0) { $seenAuthor = true;
$seenAuthor = true;
}
} }
} }
...@@ -471,13 +469,13 @@ class PhpDocController extends Controller ...@@ -471,13 +469,13 @@ class PhpDocController extends Controller
$propertyPosition = false; $propertyPosition = false;
foreach ($lines as $i => $line) { foreach ($lines as $i => $line) {
$line = trim($line); $line = trim($line);
if (!empty($line) && substr_compare($line, '* @property ', 0, 12) === 0) { if (strncmp($line, '* @property ', 12) === 0) {
$propertyPart = true; $propertyPart = true;
} elseif ($propertyPart && $line == '*') { } elseif ($propertyPart && $line == '*') {
$propertyPosition = $i; $propertyPosition = $i;
$propertyPart = false; $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; $propertyPosition = $i - 1;
$propertyPart = false; $propertyPart = false;
} }
......
...@@ -761,7 +761,7 @@ class OpenId extends BaseClient implements ClientInterface ...@@ -761,7 +761,7 @@ class OpenId extends BaseClient implements ClientInterface
} else { } else {
// 'ax' prefix is either undefined, or points to another extension, so we search for another prefix // 'ax' prefix is either undefined, or points to another extension, so we search for another prefix
foreach ($this->data as $key => $value) { 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_')); $alias = substr($key, strlen('openid_ns_'));
break; break;
} }
...@@ -775,7 +775,7 @@ class OpenId extends BaseClient implements ClientInterface ...@@ -775,7 +775,7 @@ class OpenId extends BaseClient implements ClientInterface
$attributes = []; $attributes = [];
foreach ($this->data as $key => $value) { foreach ($this->data as $key => $value) {
$keyMatch = 'openid_' . $alias . '_value_'; $keyMatch = 'openid_' . $alias . '_value_';
if (substr_compare($key, $keyMatch, 0, strlen($keyMatch))) { if (strncmp($key, $keyMatch, strlen($keyMatch))) {
continue; continue;
} }
$key = substr($key, strlen($keyMatch)); $key = substr($key, strlen($keyMatch));
...@@ -802,7 +802,7 @@ class OpenId extends BaseClient implements ClientInterface ...@@ -802,7 +802,7 @@ class OpenId extends BaseClient implements ClientInterface
$sregToAx = array_flip($this->axToSregMap); $sregToAx = array_flip($this->axToSregMap);
foreach ($this->data as $key => $value) { foreach ($this->data as $key => $value) {
$keyMatch = 'openid_sreg_'; $keyMatch = 'openid_sreg_';
if (substr_compare($key, $keyMatch, 0, strlen($keyMatch))) { if (strncmp($key, $keyMatch, strlen($keyMatch))) {
continue; continue;
} }
$key = substr($key, strlen($keyMatch)); $key = substr($key, strlen($keyMatch));
......
...@@ -332,7 +332,7 @@ class MessageController extends Controller ...@@ -332,7 +332,7 @@ class MessageController extends Controller
ksort($existingMessages); ksort($existingMessages);
foreach ($existingMessages as $message => $translation) { foreach ($existingMessages as $message => $translation) {
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeUnused) { 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; $todo[$message] = $translation;
} else { } else {
$todo[$message] = '@@' . $translation . '@@'; $todo[$message] = '@@' . $translation . '@@';
......
...@@ -109,7 +109,7 @@ class GettextMoFile extends GettextFile ...@@ -109,7 +109,7 @@ class GettextMoFile extends GettextFile
$separatorPosition = strpos($id, chr(4)); $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)) { (!$context && $separatorPosition === false)) {
if ($separatorPosition !== false) { if ($separatorPosition !== false) {
$id = substr($id, $separatorPosition+1); $id = substr($id, $separatorPosition+1);
......
...@@ -392,7 +392,7 @@ class MessageFormatter extends Component ...@@ -392,7 +392,7 @@ class MessageFormatter extends Component
} }
$selector = trim($plural[$i++]); $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)); $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)); $selector = trim(mb_substr($selector, $pos + 1));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment