Commit 100ba6c3 by Alexander Makarov

Replaced substr_compare with strncmp where possible

parent 3a1e0f3a
......@@ -176,7 +176,7 @@ class PhpDocController extends Controller
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) {
......@@ -392,17 +392,15 @@ class PhpDocController extends Controller
// 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;
}
}
......@@ -471,13 +469,13 @@ class PhpDocController extends Controller
$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;
}
......
......@@ -761,7 +761,7 @@ class OpenId extends BaseClient implements ClientInterface
} 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;
}
......@@ -775,7 +775,7 @@ class OpenId extends BaseClient implements ClientInterface
$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));
......@@ -802,7 +802,7 @@ class OpenId extends BaseClient implements ClientInterface
$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));
......
......@@ -332,7 +332,7 @@ class MessageController extends Controller
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 . '@@';
......
......@@ -109,7 +109,7 @@ class GettextMoFile extends GettextFile
$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);
......
......@@ -392,7 +392,7 @@ class MessageFormatter extends Component
}
$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));
}
......
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