unicode-display_width 1.6.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10ca31e7ad272c1de317efe8f06084454ab6c6237420a4b53ca7a3d971f97795
4
- data.tar.gz: 36040f82af948c1ff176fd7bbb5fe69573ca9964f2a67b792adea6781d7ae034
3
+ metadata.gz: c3945bec5d99b8d50f0cc813980a8b7e37c8f08c1d12fed49081f1b852714d91
4
+ data.tar.gz: 063dc046d0bb0f6b0cd5adba3aa62a67f0e0c561c8dbce24b532d5c9a961fa58
5
5
  SHA512:
6
- metadata.gz: e3301a45f349a743af722cdd4c75dbef7d34422b9f20618bc0c573a556866f6186c93673bc1ad55ef9c9be8a50f5f003456e87ddaa5b903f82bafb96f745ea71
7
- data.tar.gz: c1f3255554f9a14f913c8009222ca4064173bbc608b20c4132806b374d2215114d46e0b27e569027f2f9dd66f1c3afba04cb8565f78c2849495eca36ca4e12bb
6
+ metadata.gz: 37865fa1e94b4423cdbb276f3c9b9fb7c53012df5db61248c779316e038b581bb69513161ff27a708b796cffff3658dc98b29efb4de817b50e1ae0725e2c6396
7
+ data.tar.gz: deaebc021969062929c203c95bda9c4b23510b4153f78805729eefc7b3ce0444da3aba0d748a430b64786842c5a80bef5fad6778df03b35669cfcd10dd84495d
@@ -1,5 +1,38 @@
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
+
28
+ ## 1.7.0
29
+
30
+ - Unicode 13
31
+
32
+ ## 1.6.1
33
+
34
+ - Fix that ambiguous and overwrite options where ignored for emoji-measuring
35
+
3
36
  ## 1.6.0
4
37
 
5
38
  - Unicode 12.1
@@ -1,6 +1,6 @@
1
1
  The MIT LICENSE
2
2
 
3
- Copyright (c) 2011, 2015-2019 Jan Lelis
3
+ Copyright (c) 2011, 2015-2020 Jan Lelis
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
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
- Unicode version: **12.1.0** (May 2019)
5
+ Unicode version: **13.0.0** (March 2020)
6
6
 
7
- Supported Rubies: **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
 
@@ -118,7 +153,7 @@ See [unicode-x](https://github.com/janlelis/unicode-x) for more Unicode related
118
153
 
119
154
  ## Copyright & Info
120
155
 
121
- - Copyright (c) 2011, 2015-2019 Jan Lelis, https://janlelis.com, released under the MIT
156
+ - Copyright (c) 2011, 2015-2020 Jan Lelis, https://janlelis.com, released under the MIT
122
157
  license
123
158
  - Early versions based on runpaint's unicode-data interface: Copyright (c) 2009 Run Paint Run Run
124
159
  - Unicode data: https://www.unicode.org/copyright.html#Exhibit1
@@ -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 = {})
@@ -19,7 +21,7 @@ module Unicode
19
21
  total_width + (overwrite[codepoint] || width || 1)
20
22
  }
21
23
 
22
- res -= emoji_extra_width_of(string) if options[:emoji]
24
+ res -= emoji_extra_width_of(string, ambiguous, overwrite) if options[:emoji]
23
25
  res < 0 ? 0 : res
24
26
  end
25
27
 
@@ -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.6.0'
4
- UNICODE_VERSION = "12.1.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.6.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: 2019-05-08 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,17 +30,18 @@ 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'
41
- description: "[Unicode 12.1.0] Determines the monospace display width of a string
40
+ version: '13.0'
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
- email: mail@janlelis.de
43
+ email:
44
+ - hi@ruby.consulting
44
45
  executables: []
45
46
  extensions: []
46
47
  extra_rdoc_files:
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
- rubygems_version: 3.0.3
83
+ rubygems_version: 3.2.3
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: Determines the monospace display width of a string in Ruby.