unicode-display_width 1.8.0 → 2.1.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: 482905db9c50997ae4a1a05a972fe17d4d7c547297b1052e61de95ca2cc8c9fa
4
- data.tar.gz: f65af84de6f278a23626f5777d6453267cf8882b77a4752bb7bcec520b6788d1
3
+ metadata.gz: 83f868860aad325832499e0994c9b727daac6bc8f2f2059a2c3762d947372c80
4
+ data.tar.gz: f7e6c78087266834cd0edd4e4728b0742455309cc1f83dd6562efbfcd62dac92
5
5
  SHA512:
6
- metadata.gz: cf8867e9e4d81cea462399f1a7cb00c4875806033d66d3b8744f39741f0f0d0a1bc2853abf8e02d4799bdb0f052d00293626c07f57333d9b66459fb831250771
7
- data.tar.gz: eb82ce51aaa94fe4038f000122f2dc38f83ae93dade3183a25be60ad4018d937c3482e9bfe29d4e2ddd0679ec3c01fa89ae2eebd0a64819ce1e70e0f5f6244ca
6
+ metadata.gz: 1c765285a14f5b45fed8add2fa4d35e144465de2e1943d0d4e8aaab54e1f225fca88858408e24ac7ad110ec9b71fb14d4ea1165282e3f9aae733b34962cacb4d
7
+ data.tar.gz: 585579fa0a392c9005a8ef43aaba4c6f69ca2282c5474f873f5287d39604cf042eaa1448edc818de5f4bacd94a1522a3f9dfbd3b7c9b2630aa30d696fe82c2d4
data/CHANGELOG.md CHANGED
@@ -1,9 +1,38 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.1.0
4
+
5
+ - Unicode 14.0
6
+
7
+ ## 2.0.0
8
+
9
+ - Release 2.0.0
10
+ - Supports Ruby 3.0
11
+
12
+ ## 2.0.0.pre2
13
+
14
+ - Update 2.0 branch to Unicode 13
15
+
16
+ ## 2.0.0.pre1
17
+
18
+ Will be published as non-pre version on rubygems.org when Ruby 3.0 is released (December 2020)
19
+
20
+ - Introduce new class-based API, which remembers your string-width configuration. See README for details.
21
+ - Remove auto-loading of string extension
22
+ - You can: `require "unicode/display_width/string_ext"` to continue to use the string extension
23
+ - The manual opt-out `require "unicode/display_width/no_string_ext"` is not needed anymore and will
24
+ issue a warning in the future
25
+ - Remove (already deprecated) String#display_size and String#display_width aliases
26
+
27
+ Refactorings / Internal Changes:
28
+
29
+ - Freeze string literals
30
+ - The Unicode::DisplayWidth now is class, instead of a module, this enables the new config-object API
31
+
3
32
  ## 1.8.0
4
-
33
+
5
34
  - Unicode 14.0 (last release of 1.x)
6
-
35
+
7
36
  ## 1.7.0
8
37
 
9
38
  - Unicode 13
data/MIT-LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT LICENSE
2
2
 
3
- Copyright (c) 2011, 2015-2020 Jan Lelis
3
+ Copyright (c) 2011, 2015-2021 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
5
  Unicode version: **14.0.0** (September 2021)
6
6
 
7
- Supported Rubies: **2.7**, **2.6**, **2.5**, **2.4**
7
+ Supported Rubies: **3.0**, **2.7**
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.6**, **2.5**, **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-2020 Jan Lelis, https://janlelis.com, released under the MIT
156
+ - Copyright (c) 2011, 2015-2021 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
Binary file
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Unicode
2
- module DisplayWidth
3
- VERSION = '1.8.0'
4
+ class DisplayWidth
5
+ VERSION = "2.1.0"
4
6
  UNICODE_VERSION = "14.0.0"
5
- DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + '/../../../data/').freeze
6
- INDEX_FILENAME = (DATA_DIRECTORY + '/display_width.marshal.gz').freeze
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
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicode-display_width
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
@@ -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 14.0.0] Determines the monospace display width of a string
42
42
  using EastAsianWidth.txt, Unicode general category, and other data."
43
43
  email: