Skip to content

Commit

Permalink
Group native and mb string functions into classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushchd committed Jun 20, 2013
1 parent e475fa3 commit 2e542c4
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 157 deletions.
8 changes: 4 additions & 4 deletions browse_foreigners.php
Expand Up @@ -241,7 +241,7 @@ function formupdate(fieldmd5, key) {

$val_ordered_current_row++;

if (PMA_strlen($val_ordered_current_val) <= $cfg['LimitChars']) {
if ($GLOBALS['PMA_String']::strlen($val_ordered_current_val) <= $cfg['LimitChars']) {
$val_ordered_current_val = htmlspecialchars(
$val_ordered_current_val
);
Expand All @@ -251,11 +251,11 @@ function formupdate(fieldmd5, key) {
$val_ordered_current_val
);
$val_ordered_current_val = htmlspecialchars(
PMA_substr($val_ordered_current_val, 0, $cfg['LimitChars'])
$GLOBALS['PMA_String']::substr($val_ordered_current_val, 0, $cfg['LimitChars'])
. '...'
);
}
if (PMA_strlen($key_ordered_current_val) <= $cfg['LimitChars']) {
if ($GLOBALS['PMA_String']::strlen($key_ordered_current_val) <= $cfg['LimitChars']) {
$key_ordered_current_val = htmlspecialchars(
$key_ordered_current_val
);
Expand All @@ -265,7 +265,7 @@ function formupdate(fieldmd5, key) {
$key_ordered_current_val
);
$key_ordered_current_val = htmlspecialchars(
PMA_substr(
$GLOBALS['PMA_String']::substr(
$key_ordered_current_val, 0, $cfg['LimitChars']
) . '...'
);
Expand Down
18 changes: 9 additions & 9 deletions libraries/DisplayResults.class.php
Expand Up @@ -3657,11 +3657,11 @@ private function _getDataCellForBlobColumns(

// if a transform function for blob is set, none of these
// replacements will be made
if ((PMA_strlen($column) > $GLOBALS['cfg']['LimitChars'])
if (($GLOBALS['PMA_String']::strlen($column) > $GLOBALS['cfg']['LimitChars'])
&& ($_SESSION['tmp_user_values']['display_text'] == self::DISPLAY_PARTIAL_TEXT)
&& ! $this->_isNeedToSyntaxHighlight(strtolower($meta->name))
) {
$column = PMA_substr($column, 0, $GLOBALS['cfg']['LimitChars'])
$column = $GLOBALS['PMA_String']::substr($column, 0, $GLOBALS['cfg']['LimitChars'])
. '...';
$is_field_truncated = true;
}
Expand Down Expand Up @@ -3748,10 +3748,10 @@ private function _getDataCellForGeometryColumns(
// Convert to WKT format
$wktval = PMA_Util::asWKT($column);

if ((PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars'])
if (($GLOBALS['PMA_String']::strlen($wktval) > $GLOBALS['cfg']['LimitChars'])
&& ($_SESSION['tmp_user_values']['display_text'] == self::DISPLAY_PARTIAL_TEXT)
) {
$wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars'])
$wktval = $GLOBALS['PMA_String']::substr($wktval, 0, $GLOBALS['cfg']['LimitChars'])
. '...';
$is_field_truncated = true;
}
Expand All @@ -3772,11 +3772,11 @@ private function _getDataCellForGeometryColumns(

$wkbval = $this->_displayBinaryAsPrintable($column, 'binary', 8);

if ((PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars'])
if (($GLOBALS['PMA_String']::strlen($wkbval) > $GLOBALS['cfg']['LimitChars'])
&& ($_SESSION['tmp_user_values']['display_text'] == self::DISPLAY_PARTIAL_TEXT)
) {
$wkbval
= PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars'])
= $GLOBALS['PMA_String']::substr($wkbval, 0, $GLOBALS['cfg']['LimitChars'])
. '...';
$is_field_truncated = true;
}
Expand Down Expand Up @@ -3859,12 +3859,12 @@ private function _getDataCellForNonNumericAndNonBlobColumns(

// Cut all fields to $GLOBALS['cfg']['LimitChars']
// (unless it's a link-type transformation)
if (PMA_strlen($column) > $GLOBALS['cfg']['LimitChars']
if ($GLOBALS['PMA_String']::strlen($column) > $GLOBALS['cfg']['LimitChars']
&& ($_SESSION['tmp_user_values']['display_text'] == self::DISPLAY_PARTIAL_TEXT)
&& gettype($transformation_plugin) == "object"
&& ! strpos($transformation_plugin->getName(), 'Link') === true
) {
$column = PMA_substr($column, 0, $GLOBALS['cfg']['LimitChars'])
$column = $GLOBALS['PMA_String']::substr($column, 0, $GLOBALS['cfg']['LimitChars'])
. '...';
$is_field_truncated = true;
}
Expand Down Expand Up @@ -6015,7 +6015,7 @@ private function _displayBinaryAsPrintable(
) {
$content = bin2hex($content);
if ($hexlength !== null) {
$content = PMA_substr($content, $hexlength);
$content = $GLOBALS['PMA_String']::substr($content, $hexlength);
}
} else {
$content = htmlspecialchars(
Expand Down
2 changes: 1 addition & 1 deletion libraries/operations.lib.php
Expand Up @@ -334,7 +334,7 @@ function PMA_getSqlQueryAndCreateDbBeforeCopy()
'SHOW VARIABLES LIKE "lower_case_table_names"', 0, 1
);
if ($lower_case_table_names === '1') {
$_REQUEST['newname'] = PMA_strtolower($_REQUEST['newname']);
$_REQUEST['newname'] = $GLOBALS['PMA_String']::strtolower($_REQUEST['newname']);
}
}

Expand Down
Expand Up @@ -64,9 +64,9 @@ public function applyTransformation($buffer, $options = array(), $meta = '')

$newtext = '';
if ($options[1] != 'all') {
$newtext = PMA_substr($buffer, $options[0], $options[1]);
$newtext = $GLOBALS['PMA_String']::substr($buffer, $options[0], $options[1]);
} else {
$newtext = PMA_substr($buffer, $options[0]);
$newtext = $GLOBALS['PMA_String']::substr($buffer, $options[0]);
}

$length = strlen($newtext);
Expand Down
2 changes: 1 addition & 1 deletion libraries/relation.lib.php
Expand Up @@ -970,7 +970,7 @@ function PMA_buildForeignDropdown($foreign, $data, $mode)
}

foreach ($foreign as $key => $value) {
if (PMA_strlen($value) <= $GLOBALS['cfg']['LimitChars']) {
if ($GLOBALS['PMA_String']::strlen($value) <= $GLOBALS['cfg']['LimitChars']) {
$vtitle = '';
$value = htmlspecialchars($value);
} else {
Expand Down
4 changes: 2 additions & 2 deletions libraries/server_bin_log.lib.php
Expand Up @@ -234,9 +234,9 @@ function PMA_getAllLogItemInfo($result, $dontlimitchars)
$odd_row = true;
while ($value = $GLOBALS['dbi']->fetchAssoc($result)) {
if (! $dontlimitchars
&& PMA_strlen($value['Info']) > $GLOBALS['cfg']['LimitChars']
&& $GLOBALS['PMA_String']::strlen($value['Info']) > $GLOBALS['cfg']['LimitChars']
) {
$value['Info'] = PMA_substr(
$value['Info'] = $GLOBALS['PMA_String']::substr(
$value['Info'], 0, $GLOBALS['cfg']['LimitChars']
) . '...';
}
Expand Down
72 changes: 36 additions & 36 deletions libraries/sqlparser.lib.php
Expand Up @@ -229,7 +229,7 @@ function PMA_SQP_parse($sql)
$sql = str_replace("\r\n", "\n", $sql);
$sql = str_replace("\r", "\n", $sql);

$len = PMA_strlen($sql);
$len = $GLOBALS['PMA_String']::strlen($sql);
if ($len == 0) {
return array();
}
Expand Down Expand Up @@ -295,7 +295,7 @@ function PMA_SQP_parse($sql)
$this_was_quote = false;

while ($count2 < $len) {
$c = PMA_substr($sql, $count2, 1);
$c = $GLOBALS['PMA_String']::substr($sql, $count2, 1);
$count1 = $count2;

$previous_was_space = $this_was_space;
Expand Down Expand Up @@ -327,11 +327,11 @@ function PMA_SQP_parse($sql)
// MySQL style #
// C style /* */
// ANSI style --
$next_c = PMA_substr($sql, $count2 + 1, 1);
$next_c = $GLOBALS['PMA_String']::substr($sql, $count2 + 1, 1);
if (($c == '#')
|| (($count2 + 1 < $len) && ($c == '/') && ($next_c == '*'))
|| (($count2 + 2 == $len) && ($c == '-') && ($next_c == '-'))
|| (($count2 + 2 < $len) && ($c == '-') && ($next_c == '-') && ((PMA_substr($sql, $count2 + 2, 1) <= ' ')))
|| (($count2 + 2 < $len) && ($c == '-') && ($next_c == '-') && (($GLOBALS['PMA_String']::substr($sql, $count2 + 2, 1) <= ' ')))
) {
$count2++;
$pos = 0;
Expand All @@ -341,32 +341,32 @@ function PMA_SQP_parse($sql)
$type = 'mysql';
case '-':
$type = 'ansi';
$pos = PMA_strpos($sql, "\n", $count2);
$pos = $GLOBALS['PMA_String']::strpos($sql, "\n", $count2);
break;
case '/':
$type = 'c';
$pos = PMA_strpos($sql, '*/', $count2);
$pos = $GLOBALS['PMA_String']::strpos($sql, '*/', $count2);
$pos += 2;
break;
default:
break;
} // end switch
$count2 = ($pos < $count2) ? $len : $pos;
$str = PMA_substr($sql, $count1, $count2 - $count1);
$str = $GLOBALS['PMA_String']::substr($sql, $count1, $count2 - $count1);
PMA_SQP_arrayAdd($sql_array, 'comment_' . $type, $str, $arraysize);
continue;
} // end if

// Checks for something inside quotation marks
if (PMA_strpos($quote_list, $c) !== false) {
if ($GLOBALS['PMA_String']::strpos($quote_list, $c) !== false) {
$startquotepos = $count2;
$quotetype = $c;
$count2++;
$pos = $count2;
$oldpos = 0;
do {
$oldpos = $pos;
$pos = PMA_strpos(' ' . $sql, $quotetype, $oldpos + 1) - 1;
$pos = $GLOBALS['PMA_String']::strpos(' ' . $sql, $quotetype, $oldpos + 1) - 1;
// ($pos === false)
if ($pos < 0) {
if ($c == '`') {
Expand All @@ -381,7 +381,7 @@ function PMA_SQP_parse($sql)
*
* SELECT * FROM `table`
*/
$pos_quote_separator = PMA_strpos(
$pos_quote_separator = $GLOBALS['PMA_String']::strpos(
' ' . $sql, $GLOBALS['sql_delimiter'], $oldpos + 1
) - 1;
if ($pos_quote_separator < 0) {
Expand All @@ -391,8 +391,8 @@ function PMA_SQP_parse($sql)
$pos = $len;
} else {
$len += 1;
$sql = PMA_substr($sql, 0, $pos_quote_separator)
. '`' . PMA_substr($sql, $pos_quote_separator);
$sql = $GLOBALS['PMA_String']::substr($sql, 0, $pos_quote_separator)
. '`' . $GLOBALS['PMA_String']::substr($sql, $pos_quote_separator);
$sql_array['raw'] = $sql;
$pos = $pos_quote_separator;
}
Expand Down Expand Up @@ -427,8 +427,8 @@ function PMA_SQP_parse($sql)
$pos ++;
continue;
} elseif (($pos + 1 < $len)
&& (PMA_substr($sql, $pos, 1) == $quotetype)
&& (PMA_substr($sql, $pos + 1, 1) == $quotetype)
&& ($GLOBALS['PMA_String']::substr($sql, $pos, 1) == $quotetype)
&& ($GLOBALS['PMA_String']::substr($sql, $pos + 1, 1) == $quotetype)
) {
$pos = $pos + 2;
continue;
Expand Down Expand Up @@ -456,27 +456,27 @@ function PMA_SQP_parse($sql)
default:
break;
} // end switch
$data = PMA_substr($sql, $count1, $count2 - $count1);
$data = $GLOBALS['PMA_String']::substr($sql, $count1, $count2 - $count1);
PMA_SQP_arrayAdd($sql_array, $type, $data, $arraysize);
continue;
}

// Checks for brackets
if (PMA_strpos($bracket_list, $c) !== false) {
if ($GLOBALS['PMA_String']::strpos($bracket_list, $c) !== false) {
// All bracket tokens are only one item long
$this_was_bracket = true;
$count2++;
$type_type = '';
if (PMA_strpos('([{', $c) !== false) {
if ($GLOBALS['PMA_String']::strpos('([{', $c) !== false) {
$type_type = 'open';
} else {
$type_type = 'close';
}

$type_style = '';
if (PMA_strpos('()', $c) !== false) {
if ($GLOBALS['PMA_String']::strpos('()', $c) !== false) {
$type_style = 'round';
} elseif (PMA_strpos('[]', $c) !== false) {
} elseif ($GLOBALS['PMA_String']::strpos('[]', $c) !== false) {
$type_style = 'square';
} else {
$type_style = 'curly';
Expand All @@ -492,7 +492,7 @@ function PMA_SQP_parse($sql)
var_dump(PMA_STR_isSqlIdentifier($c, false));
var_dump($c == '@');
var_dump($c == '.');
var_dump(PMA_STR_isDigit(PMA_substr($sql, $count2 + 1, 1)));
var_dump(PMA_STR_isDigit($GLOBALS['PMA_String']::substr($sql, $count2 + 1, 1)));
var_dump($previous_was_space);
var_dump($previous_was_bracket);
var_dump($previous_was_listsep);
Expand All @@ -503,11 +503,11 @@ function PMA_SQP_parse($sql)
if (PMA_STR_isSqlIdentifier($c, false)
|| $c == '@'
|| ($c == '.'
&& PMA_STR_isDigit(PMA_substr($sql, $count2 + 1, 1))
&& PMA_STR_isDigit($GLOBALS['PMA_String']::substr($sql, $count2 + 1, 1))
&& ($previous_was_space || $previous_was_bracket || $previous_was_listsep))
) {
/* DEBUG
echo PMA_substr($sql, $count2);
echo $GLOBALS['PMA_String']::substr($sql, $count2);
echo '<hr />';
*/

Expand All @@ -530,7 +530,7 @@ function PMA_SQP_parse($sql)
$is_digit
&& $c == '0'
&& $count2 < $len
&& PMA_substr($sql, $count2, 1) == 'x'
&& $GLOBALS['PMA_String']::substr($sql, $count2, 1) == 'x'
);
$is_float_digit = $c == '.';
$is_float_digit_exponent = false;
Expand Down Expand Up @@ -560,8 +560,8 @@ function PMA_SQP_parse($sql)
unset($pos);
}

while (($count2 < $len) && PMA_STR_isSqlIdentifier(PMA_substr($sql, $count2, 1), ($is_sql_variable || $is_digit))) {
$c2 = PMA_substr($sql, $count2, 1);
while (($count2 < $len) && PMA_STR_isSqlIdentifier($GLOBALS['PMA_String']::substr($sql, $count2, 1), ($is_sql_variable || $is_digit))) {
$c2 = $GLOBALS['PMA_String']::substr($sql, $count2, 1);
if ($is_sql_variable && ($c2 == '.')) {
$count2++;
continue;
Expand All @@ -575,7 +575,7 @@ function PMA_SQP_parse($sql)
$debugstr = __('Invalid Identifer')
. ' @ ' . ($count1+1) . "\n"
. 'STR: ' . htmlspecialchars(
PMA_substr($sql, $count1, $count2 - $count1)
$GLOBALS['PMA_String']::substr($sql, $count1, $count2 - $count1)
);
PMA_SQP_throwError($debugstr, $sql);
return $sql_array;
Expand Down Expand Up @@ -604,7 +604,7 @@ function PMA_SQP_parse($sql)
} // end while

$l = $count2 - $count1;
$str = PMA_substr($sql, $count1, $l);
$str = $GLOBALS['PMA_String']::substr($sql, $count1, $l);

$type = '';
if ($is_digit || $is_float_digit || $is_hex_digit) {
Expand All @@ -629,15 +629,15 @@ function PMA_SQP_parse($sql)
}

// Checks for punct
if (PMA_strpos($allpunct_list, $c) !== false) {
while (($count2 < $len) && PMA_strpos($allpunct_list, PMA_substr($sql, $count2, 1)) !== false) {
if ($GLOBALS['PMA_String']::strpos($allpunct_list, $c) !== false) {
while (($count2 < $len) && $GLOBALS['PMA_String']::strpos($allpunct_list, $GLOBALS['PMA_String']::substr($sql, $count2, 1)) !== false) {
$count2++;
}
$l = $count2 - $count1;
if ($l == 1) {
$punct_data = $c;
} else {
$punct_data = PMA_substr($sql, $count1, $l);
$punct_data = $GLOBALS['PMA_String']::substr($sql, $count1, $l);
}

// Special case, sometimes, althought two characters are
Expand Down Expand Up @@ -678,12 +678,12 @@ function PMA_SQP_parse($sql)
if (($first == ',') || ($first == ';') || ($first == '.') || ($first == '*')) {
$count2 = $count1 + 1;
$punct_data = $first;
} elseif (($last2 == '/*') || (($last2 == '--') && ($count2 == $len || PMA_substr($sql, $count2, 1) <= ' '))) {
} elseif (($last2 == '/*') || (($last2 == '--') && ($count2 == $len || $GLOBALS['PMA_String']::substr($sql, $count2, 1) <= ' '))) {
$count2 -= 2;
$punct_data = PMA_substr($sql, $count1, $count2 - $count1);
$punct_data = $GLOBALS['PMA_String']::substr($sql, $count1, $count2 - $count1);
} elseif (($last == '-') || ($last == '+') || ($last == '!')) {
$count2--;
$punct_data = PMA_substr($sql, $count1, $count2 - $count1);
$punct_data = $GLOBALS['PMA_String']::substr($sql, $count1, $count2 - $count1);
} elseif ($last != '~') {
/**
* @todo for negation operator, split in 2 tokens ?
Expand All @@ -706,7 +706,7 @@ function PMA_SQP_parse($sql)
$count2++;

$debugstr = 'C1 C2 LEN: ' . $count1 . ' ' . $count2 . ' ' . $len . "\n"
. 'STR: ' . PMA_substr($sql, $count1, $count2 - $count1) . "\n";
. 'STR: ' . $GLOBALS['PMA_String']::substr($sql, $count1, $count2 - $count1) . "\n";
PMA_SQP_bug($debugstr, $sql);
return $sql_array;

Expand Down Expand Up @@ -1809,10 +1809,10 @@ function PMA_SQP_analyze($arr)
$seen_order_by = true;
// Here we assume that the ORDER BY keywords took
// exactly 8 characters.
// We use PMA_substr() to be charset-safe; otherwise
// We use $GLOBALS['PMA_String']::substr() to be charset-safe; otherwise
// if the table name contains accents, the unsorted
// query would be missing some characters.
$unsorted_query = PMA_substr(
$unsorted_query = $GLOBALS['PMA_String']::substr(
$arr['raw'], 0, $arr[$i]['pos'] - 8
);
$in_order_by = true;
Expand Down

0 comments on commit 2e542c4

Please sign in to comment.