From 52d77b17fb1b120cd054b7d9334c574a222777ce Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 10 Sep 2014 05:04:52 -0700 Subject: [PATCH] Strip Hebrew vowel characters from real length calculation Hebrew writing has two separate accents / vowels under letters. In testing, all fonts properly handle this --- lib/cli/cli.php | 6 ++++-- tests/test-cli.php | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/cli/cli.php b/lib/cli/cli.php index b320553..c20d47b 100755 --- a/lib/cli/cli.php +++ b/lib/cli/cli.php @@ -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; diff --git a/tests/test-cli.php b/tests/test-cli.php index 0d84c1a..c9b0f25 100644 --- a/tests/test-cli.php +++ b/tests/test-cli.php @@ -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 }