Skip to content

Commit

Permalink
Strip Hebrew vowel characters from real length calculation
Browse files Browse the repository at this point in the history
Hebrew writing has two separate accents / vowels under letters. In testing, all fonts properly handle this
  • Loading branch information
danielbachhuber committed Sep 10, 2014
1 parent f2bb69d commit 52d77b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cli/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ function safe_substr( $str, $start, $length = false ) {
* @return string
*/
function safe_str_pad( $string, $length ) {
// Hebrew vowel characters
$cleaned_string = preg_replace( '#[\x{591}-\x{5C7}]+#u', '', $string );
if ( function_exists( 'mb_strwidth' ) ) {
$real_length = mb_strwidth( $string, mb_detect_encoding( $string ) );
$real_length = mb_strwidth( $cleaned_string, mb_detect_encoding( $string ) );
} else {
$real_length = safe_strlen( $string );
$real_length = safe_strlen( $cleaned_string );
}
$diff = strlen( $string ) - $real_length;
$length += $diff;
Expand Down
1 change: 1 addition & 0 deletions tests/test-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function test_encoded_string_pad() {
$this->assertEquals( 6, strlen( \cli\Colors::pad( 'hello', 6 ) ) );
$this->assertEquals( 7, strlen( \cli\Colors::pad( 'óra', 6 ) ) ); // special characters take one byte
$this->assertEquals( 9, strlen( \cli\Colors::pad( '日本語', 6 ) ) ); // each character takes two bytes
$this->assertEquals( 17, strlen( \cli\Colors::pad( 'עִבְרִית', 6 ) ) ); // process Hebrew vowels

}

Expand Down

0 comments on commit 52d77b1

Please sign in to comment.