Skip to content

Commit

Permalink
Merge pull request #149 from xopoc14/143-Multi-byte-character-titles-…
Browse files Browse the repository at this point in the history
…blank-out-citations

#143: Multi-byte character titles blank out citations.
  • Loading branch information
seboettg authored Feb 5, 2023
2 parents 063dbb7 + b0b3447 commit 676029f
Show file tree
Hide file tree
Showing 3 changed files with 1,269 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Util/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,18 @@ public static function keepLowerCase($word)
public static function mb_ucfirst($string, $encoding = 'UTF-8')
{// phpcs:enable
$strlen = mb_strlen($string, $encoding);
if ($strlen == 0) return '';
$firstChar = mb_substr($string, 0, 1, $encoding);
$then = mb_substr($string, 1, $strlen - 1, $encoding);

/** @noinspection PhpInternalEntityUsedInspection */
// We can not rely on mb_detect_encoding. See https://www.php.net/manual/en/function.mb-detect-encoding.php.
// We need to double-check if the first char is not a multibyte char otherwise mb_strtoupper() process it
// incorrectly, and it causes issues later. For example 'こ' transforms to 'Á�'.
$original_ord = mb_ord($firstChar, $encoding);
$encoding = mb_detect_encoding($firstChar, self::ISO_ENCODINGS, true);
return in_array($encoding, self::ISO_ENCODINGS) ?
$new_ord = mb_ord($firstChar, $encoding);
return $original_ord === $new_ord && in_array($encoding, self::ISO_ENCODINGS) ?
mb_strtoupper($firstChar, $encoding).$then : $firstChar.$then;
}
// phpcs:disable
Expand Down
Loading

0 comments on commit 676029f

Please sign in to comment.