Skip to content

Commit

Permalink
use iconv fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Oct 30, 2018
1 parent 3cc4700 commit bff5592
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
12 changes: 11 additions & 1 deletion lib/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,17 @@ public function parse($input) {

if ( ! function_exists( 'ucs2length' ) ) {
function ucs2length( $string ) {
return (int) strlen( iconv( 'UTF-8', 'UTF-16le', $string ) ) / 2;
if ( function_exists( 'iconv' ) ) {
return (int) strlen( iconv( 'UTF-8', 'UTF-16LE', $string ) ) / 2;
}

if ( function_exists( 'iconv_fallback' ) ) {
return (int) strlen( iconv_fallback( 'UTF-8', 'UTF16-LE', $string ) );
}

// what should we do here?
// this is wrong.
return (int) strlen( $string );
}
}

Expand Down
12 changes: 11 additions & 1 deletion packages/block-serialization-default-parser/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ function add_block_from_stack( $end_offset = null ) {
}

static function ucs2length( $string ) {
return (int) strlen( iconv( 'UTF-8', 'UTF-16le', $string ) ) / 2;
if ( function_exists( 'iconv' ) ) {
return (int) strlen( iconv( 'UTF-8', 'UTF-16LE', $string ) ) / 2;
}

if ( function_exists( 'iconv_fallback' ) ) {
return (int) strlen( iconv_fallback( 'UTF-8', 'UTF16-LE', $string ) );
}

// what should we do here?
// this is wrong.
return (int) strlen( $string );
}
}
12 changes: 11 additions & 1 deletion packages/block-serialization-spec-parser/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@
if ( ! function_exists( 'ucs2length' ) ) {
function ucs2length( $string ) {
return (int) strlen( iconv( 'UTF-8', 'UTF-16le', $string ) ) / 2;
if ( function_exists( 'iconv' ) ) {
return (int) strlen( iconv( 'UTF-8', 'UTF-16LE', $string ) ) / 2;
}
if ( function_exists( 'iconv_fallback' ) ) {
return (int) strlen( iconv_fallback( 'UTF-8', 'UTF16-LE', $string ) );
}
// what should we do here?
// this is wrong.
return (int) strlen( $string );
}
}
Expand Down
12 changes: 11 additions & 1 deletion packages/block-serialization-spec-parser/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bff5592

Please sign in to comment.