Add strwidth(), called by safe_str_pad(). Add unicode/regex.php.#107
Merged
Merged
Add strwidth(), called by safe_str_pad(). Add unicode/regex.php.#107
Conversation
schlessera
requested changes
Jul 23, 2017
| * @return int | ||
| */ | ||
| static public function width($string) { | ||
| if (isset(self::$_string_cache[md5($string)]['decolorized'])) { |
Member
There was a problem hiding this comment.
The md5($string) should only be computed once.
schlessera
approved these changes
Jul 23, 2017
This was referenced Jul 23, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #103
Adds
strwidth()to calculate the spacing width, and uses it insafe_str_pad(). Usesgrapheme_strlen(),preg_match_all( '/\X/u' ),mb_strwidth()orsafe_strlen()depending on availability/charset.To account for East Asian double-width characters, and (in the unlikely case of falling back to
mb_strwidth()for UTF-8) for Mark characters, it uses a generatedunicode/regex.phpfile containing regexs, generated usingtools/gen_east_asian_width.phpandtools/gen_cat_regex_alts.php, which currently reside at https://github.com/gitlost/unfc-normalize as they use a library developed for that plugin, but can be adapted and brought over tophp-cli-toolsif desired.Also fixes an issue with printing fields with percents in them when
shouldColorize()is disabled (after wp-cli/wp-cli#2458).Edit: also adds
Colors::width()and uses it andstrwidth()to calculate table widths, fixing padding.