unicode-display_width 1.7.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6717dfd17f33fb2c2baa553461b99081d0bb4c3db3213a63cb8a318e9b4982be
4
- data.tar.gz: 2f844904759852d6e32a4fe89212c5f6e965a6482fdbdb182a8eeeedce917ad8
3
+ metadata.gz: c3945bec5d99b8d50f0cc813980a8b7e37c8f08c1d12fed49081f1b852714d91
4
+ data.tar.gz: 063dc046d0bb0f6b0cd5adba3aa62a67f0e0c561c8dbce24b532d5c9a961fa58
5
5
  SHA512:
6
- metadata.gz: d73355d6e5c63118502dc5129a84be7935320fc8ca3deb435ae2bf2e9b710ab08e21bde5470624d78c83928598429e97b95e71ea51e8d158ddd37b4236913fc1
7
- data.tar.gz: 65c27dfb5b47af40e04665cfaefd152a8432aca44052fa3a92a1e141001bd542f578e5e53b323331f0432f4412491a45bebc9f5341347ba8a43d422be76f13f4
6
+ metadata.gz: 37865fa1e94b4423cdbb276f3c9b9fb7c53012df5db61248c779316e038b581bb69513161ff27a708b796cffff3658dc98b29efb4de817b50e1ae0725e2c6396
7
+ data.tar.gz: deaebc021969062929c203c95bda9c4b23510b4153f78805729eefc7b3ce0444da3aba0d748a430b64786842c5a80bef5fad6778df03b35669cfcd10dd84495d
@@ -1,5 +1,30 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.0.0
4
+
5
+ - Release 2.0.0
6
+ - Supports Ruby 3.0
7
+
8
+ ## 2.0.0.pre2
9
+
10
+ - Update 2.0 branch to Unicode 13
11
+
12
+ ## 2.0.0.pre1
13
+
14
+ Will be published as non-pre version on rubygems.org when Ruby 3.0 is released (December 2020)
15
+
16
+ - Introduce new class-based API, which remembers your string-width configuration. See README for details.
17
+ - Remove auto-loading of string extension
18
+ - You can: `require "unicode/display_width/string_ext"` to continue to use the string extension
19
+ - The manual opt-out `require "unicode/display_width/no_string_ext"` is not needed anymore and will
20
+ issue a warning in the future
21
+ - Remove (already deprecated) String#display_size and String#display_width aliases
22
+
23
+ Refactorings / Internal Changes:
24
+
25
+ - Freeze string literals
26
+ - The Unicode::DisplayWidth now is class, instead of a module, this enables the new config-object API
27
+
3
28
  ## 1.7.0
4
29
 
5
30
  - Unicode 13
data/README.md CHANGED
@@ -1,12 +1,31 @@
1
- ## Unicode::DisplayWidth [![[version]](https://badge.fury.io/rb/unicode-display_width.svg)](https://badge.fury.io/rb/unicode-display_width) [<img src="https://travis-ci.org/janlelis/unicode-display_width.png" />](https://travis-ci.org/janlelis/unicode-display_width)
1
+ ## Unicode::DisplayWidth [![[version]](https://badge.fury.io/rb/unicode-display_width.svg)](https://badge.fury.io/rb/unicode-display_width) [<img src="https://github.com/janlelis/unicode-display_width/workflows/Test/badge.svg" />](https://github.com/janlelis/unicode-display_width/actions?query=workflow%3ATest)
2
2
 
3
- Determines the monospace display width of a string in Ruby. Implementation based on [EastAsianWidth.txt](https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) and other data, 100% in Ruby. Other than [wcwidth()](https://github.com/janlelis/wcswidth-ruby), which fulfills a similar purpose, it does not rely on the OS vendor to provide an up-to-date method for measuring string width.
3
+ Determines the monospace display width of a string in Ruby. Implementation based on [EastAsianWidth.txt](https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) and other data, 100% in Ruby. It does not rely on the OS vendor (like [wcwidth()](https://github.com/janlelis/wcswidth-ruby)) to provide an up-to-date method for measuring string width.
4
4
 
5
5
  Unicode version: **13.0.0** (March 2020)
6
6
 
7
- Supported Rubies: **2.7**, **2.6**, **2.5**, **2.4**
7
+ Supported Rubies: **3.0**, **2.7**, **2.6**, **2.5**
8
8
 
9
- Old Rubies that might still work: **2.3**, **2.2**, **2.1**, **2.0**, **1.9**
9
+ Old Rubies which might still work: **2.4**, **2.3**, **2.2**, **2.1**, **2.0**, **1.9**
10
+
11
+ ## Version 2.0 — Breaking Changes
12
+
13
+ Some features of this library were marked deprecated for a long time and have been removed with Version 2.0:
14
+
15
+ - Aliases of display_width (…\_size, …\_length) have been removed
16
+ - Auto-loading of string core extension has been removed:
17
+
18
+ If you are relying on the `String#display_width` string extension to be automatically loaded (old behavior), please load it explicitly now:
19
+
20
+ ```ruby
21
+ require "unicode/display_width/string_ext"
22
+ ```
23
+
24
+ You could also change your `Gemfile` line to achieve this:
25
+
26
+ ```ruby
27
+ gem "unicode-display_width", require: "unicode/display_width/string_ext"
28
+ ```
10
29
 
11
30
  ## Introduction to Character Widths
12
31
 
@@ -44,6 +63,8 @@ Or add to your Gemfile:
44
63
 
45
64
  ## Usage
46
65
 
66
+ ### Classic API
67
+
47
68
  ```ruby
48
69
  require 'unicode/display_width'
49
70
 
@@ -51,7 +72,7 @@ Unicode::DisplayWidth.of("⚀") # => 1
51
72
  Unicode::DisplayWidth.of("一") # => 2
52
73
  ```
53
74
 
54
- ### Ambiguous Characters
75
+ #### Ambiguous Characters
55
76
 
56
77
  The second parameter defines the value returned by characters defined as ambiguous:
57
78
 
@@ -60,42 +81,56 @@ Unicode::DisplayWidth.of("·", 1) # => 1
60
81
  Unicode::DisplayWidth.of("·", 2) # => 2
61
82
  ```
62
83
 
63
- ### Custom Overwrites
84
+ #### Custom Overwrites
64
85
 
65
86
  You can overwrite how to handle specific code points by passing a hash (or even a proc) as third parameter:
66
87
 
67
88
  ```ruby
68
- Unicode::DisplayWidth.of("a\tb", 1, 0x09 => 10)) # => 12
89
+ Unicode::DisplayWidth.of("a\tb", 1, "\t".ord => 10)) # => tab counted as 10, so result is 12
69
90
  ```
70
91
 
71
- ### Emoji Support
92
+ #### Emoji Support
72
93
 
73
- Experimental emoji support is included. It will adjust the string's size for modifier and zero-width joiner sequences. You will need to add the [unicode-emoji](https://github.com/janlelis/unicode-emoji) gem to your Gemfile:
94
+ Emoji width support is included, but in must be activated manually. It will adjust the string's size for modifier and zero-width joiner sequences. You also need to add the [unicode-emoji](https://github.com/janlelis/unicode-emoji) gem to your Gemfile:
74
95
 
75
96
  ```ruby
76
97
  gem 'unicode-display_width'
77
98
  gem 'unicode-emoji'
78
99
  ```
79
100
 
80
- You can then activate the emoji string width adjustments by passing `emoji: true` as fourth parameter:
101
+ Enable the emoji string width adjustments by passing `emoji: true` as fourth parameter:
81
102
 
82
103
  ```ruby
83
104
  Unicode::DisplayWidth.of "🤾🏽‍♀️" # => 5
84
105
  Unicode::DisplayWidth.of "🤾🏽‍♀️", 1, {}, emoji: true # => 2
85
106
  ```
86
107
 
87
- ### Usage with String Extension
88
-
89
- Activated by default. Will be deactivated in version 2.0:
108
+ #### Usage with String Extension
90
109
 
91
110
  ```ruby
92
111
  require 'unicode/display_width/string_ext'
93
112
 
94
- "⚀".display_width #=> 1
95
- '一'.display_width #=> 2
113
+ "⚀".display_width # => 1
114
+ '一'.display_width # => 2
96
115
  ```
97
116
 
98
- You can actively opt-out from the string extension with: `require 'unicode/display_width/no_string_ext'`
117
+ ### Modern API: Keyword-arguments Based Config Object
118
+
119
+ Version 2.0 introduces a keyword-argument based API, which allows you to save your configuration for later-reuse. This requires an extra line of code, but has the advantage that you'll need to define your string-width options only once:
120
+
121
+ ```ruby
122
+ require 'unicode/display_width'
123
+
124
+ display_width = Unicode::DisplayWidth.new(
125
+ # ambiguous: 1,
126
+ overwrite: { "A".ord => 100 },
127
+ emoji: true,
128
+ )
129
+
130
+ display_width.of "⚀" # => 1
131
+ display_width.of "🤾🏽‍♀️" # => 2
132
+ display_width.of "A" # => 100
133
+ ```
99
134
 
100
135
  ### Usage From the CLI
101
136
 
@@ -1,8 +1,10 @@
1
- require_relative 'display_width/constants'
2
- require_relative 'display_width/index'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "display_width/constants"
4
+ require_relative "display_width/index"
3
5
 
4
6
  module Unicode
5
- module DisplayWidth
7
+ class DisplayWidth
6
8
  DEPTHS = [0x10000, 0x1000, 0x100, 0x10].freeze
7
9
 
8
10
  def self.of(string, ambiguous = 1, overwrite = {}, options = {})
@@ -40,12 +42,24 @@ module Unicode
40
42
 
41
43
  extra_width
42
44
  end
43
- end
44
- end
45
45
 
46
- # Allows you to opt-out of the default string extension. Will eventually be removed,
47
- # so you must opt-in for the core extension by requiring 'display_width/string_ext'
48
- unless defined?(Unicode::DisplayWidth::NO_STRING_EXT) && Unicode::DisplayWidth::NO_STRING_EXT
49
- require_relative 'display_width/string_ext'
46
+ def initialize(ambiguous: 1, overwrite: {}, emoji: false)
47
+ @ambiguous = ambiguous
48
+ @overwrite = overwrite
49
+ @emoji = emoji
50
+ end
51
+
52
+ def get_config(**kwargs)
53
+ [
54
+ kwargs[:ambiguous] || @ambiguous,
55
+ kwargs[:overwrite] || @overwrite,
56
+ { emoji: kwargs[:emoji] || @emoji },
57
+ ]
58
+ end
59
+
60
+ def of(string, **kwargs)
61
+ self.class.of(string, *get_config(**kwargs))
62
+ end
63
+ end
50
64
  end
51
65
 
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Unicode
2
- module DisplayWidth
3
- VERSION = '1.7.0'
4
- UNICODE_VERSION = "13.0.0".freeze
5
- DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + '/../../../data/').freeze
6
- INDEX_FILENAME = (DATA_DIRECTORY + '/display_width.marshal.gz').freeze
4
+ class DisplayWidth
5
+ VERSION = "2.0.0"
6
+ UNICODE_VERSION = "13.0.0"
7
+ DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + "/../../../data/")
8
+ INDEX_FILENAME = DATA_DIRECTORY + "/display_width.marshal.gz"
7
9
  end
8
10
  end
@@ -1,8 +1,10 @@
1
- require 'zlib'
2
- require_relative 'constants'
1
+ # frozen_string_literal: true
2
+
3
+ require "zlib"
4
+ require_relative "constants"
3
5
 
4
6
  module Unicode
5
- module DisplayWidth
7
+ class DisplayWidth
6
8
  File.open(INDEX_FILENAME, "rb") do |file|
7
9
  serialized_data = Zlib::GzipReader.new(file).read
8
10
  serialized_data.force_encoding Encoding::BINARY
@@ -1,7 +1,8 @@
1
- module Unicode
2
- module DisplayWidth
3
- NO_STRING_EXT = true
4
- end
5
- end
1
+ # frozen_string_literal: true
6
2
 
7
- require_relative '../display_width'
3
+ warn "You are loading 'unicode-display_width/no_string_ext'\n" \
4
+ "Beginning with version 2.0, this is not necessary anymore\n"\
5
+ "You can just require 'unicode-display_width' now and no\n"\
6
+ "string extension will be loaded"
7
+
8
+ require_relative "../display_width"
@@ -1,17 +1,9 @@
1
- require_relative '../display_width' unless defined? Unicode::DisplayWidth
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../display_width" unless defined? Unicode::DisplayWidth
2
4
 
3
5
  class String
4
6
  def display_width(ambiguous = 1, overwrite = {}, options = {})
5
7
  Unicode::DisplayWidth.of(self, ambiguous, overwrite, options)
6
8
  end
7
-
8
- def display_size(*args)
9
- warn "Deprecation warning: Please use `String#display_width` instead of `String#display_size`"
10
- display_width(*args)
11
- end
12
-
13
- def display_length(*args)
14
- warn "Deprecation warning: Please use `String#display_width` instead of `String#display_length`"
15
- display_width(*args)
16
- end
17
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicode-display_width
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-11 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.4'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.4'
40
+ version: '13.0'
41
41
  description: "[Unicode 13.0.0] Determines the monospace display width of a string
42
42
  using EastAsianWidth.txt, Unicode general category, and other data."
43
43
  email:
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.1.2
83
+ rubygems_version: 3.2.3
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Determines the monospace display width of a string in Ruby.