Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown: Remove shim for mb_strlen now that the minimum supported PHP version includes it #8869

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions _inc/lib/markdown/extra.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ function __construct() {
#
# Constructor function. Initialize appropriate member variables.
#
$this->_initDetab();
$this->prepareItalicsAndBold();

$this->nested_brackets_re =
Expand Down Expand Up @@ -1481,10 +1480,6 @@ function outdent($text) {
}


# String length function for detab. `_initDetab` will create a function to
# hanlde UTF-8 if the default function does not exist.
public $utf8_strlen = 'mb_strlen';

function detab($text) {
#
# Replace tabs with the appropriate amount of space.
Expand All @@ -1500,7 +1495,6 @@ function detab($text) {
}
function _detab_callback($matches) {
$line = $matches[0];
$strlen = $this->utf8_strlen; # strlen function for UTF-8.

# Split in blocks.
$blocks = explode("\t", $line);
Expand All @@ -1510,24 +1504,11 @@ function _detab_callback($matches) {
foreach ($blocks as $block) {
# Calculate amount of space, insert spaces, insert block.
$amount = $this->tab_width -
$strlen($line, 'UTF-8') % $this->tab_width;
mb_strlen($line, 'UTF-8') % $this->tab_width;
$line .= str_repeat(" ", $amount) . $block;
}
return $line;
}
function _initDetab() {
#
# Check for the availability of the function in the `utf8_strlen` property
# (initially `mb_strlen`). If the function is not available, create a
# function that will loosely count the number of UTF-8 characters with a
# regular expression.
#
if (function_exists($this->utf8_strlen)) return;
$this->utf8_strlen = create_function('$text', 'return preg_match_all(
"/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/",
$text, $m);');
}


function unhash($text) {
#
Expand Down Expand Up @@ -2157,8 +2138,7 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) {

# Calculate indent before tag.
if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) {
$strlen = $this->utf8_strlen;
$indent = $strlen($matches[1], 'UTF-8');
$indent = mb_strlen($matches[1], 'UTF-8');
} else {
$indent = 0;
}
Expand Down