brakeman 3.3.5 → 3.4.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 +4 -4
- data/CHANGES +9 -0
- data/bundle/load.rb +2 -1
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/Gemfile +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/History.rdoc +13 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/Manifest +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/README.rdoc +1 -1
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/Rakefile +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/Todo.rdoc +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/examples/examples.rb +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table.rb +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/cell.rb +5 -2
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/import.rb +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/row.rb +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/separator.rb +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/style.rb +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/table.rb +13 -3
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/table_helper.rb +0 -0
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/version.rb +1 -1
- data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/terminal-table.gemspec +2 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/CHANGELOG.txt +73 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/MIT-LICENSE.txt +22 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/README.md +102 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/Rakefile +63 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/data/display_width.marshal.gz +0 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/lib/unicode/display_width.rb +30 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/lib/unicode/display_width/constants.rb +8 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/lib/unicode/display_width/index.rb +7 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/lib/unicode/display_width/no_string_ext.rb +7 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/lib/unicode/display_width/string_ext.rb +17 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/spec/display_width_spec.rb +126 -0
- data/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/unicode-display_width.gemspec +18 -0
- data/lib/brakeman.rb +18 -1
- data/lib/brakeman/options.rb +8 -4
- data/lib/brakeman/processors/output_processor.rb +8 -2
- data/lib/brakeman/processors/slim_template_processor.rb +20 -2
- data/lib/brakeman/report.rb +8 -1
- data/lib/brakeman/report/ignore/config.rb +18 -0
- data/lib/brakeman/report/ignore/interactive.rb +35 -0
- data/lib/brakeman/report/report_base.rb +5 -0
- data/lib/brakeman/report/report_json.rb +4 -1
- data/lib/brakeman/report/report_table.rb +1 -0
- data/lib/brakeman/report/report_text.rb +193 -0
- data/lib/brakeman/tracker.rb +5 -0
- data/lib/brakeman/version.rb +1 -1
- data/lib/brakeman/warning.rb +10 -0
- metadata +32 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0af994ff904b9ab144c23dfeb8e4f547cabcec39
|
|
4
|
+
data.tar.gz: eeb3ea20459025facc48074b483a35487eb9ba4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94a5d9d71cb022313833f3b2c364878f1f3e24e6f265023285fbdd38c90dd4f6f610498fae94fa24c9472ae74eb02d65126db1c4356d7a8c453bb15ef6de4173
|
|
7
|
+
data.tar.gz: bac267af1c2bf6fe1f4c5cb31a3935078c943879fd0b6a2cb76929d407591723322fdeda0fd3ee702b84c809eedfe3f4263dc10e47cda9ca4abd89b0ff5295ac
|
data/CHANGES
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# 3.4.0
|
|
2
|
+
|
|
3
|
+
* Add new `plain` report format
|
|
4
|
+
* Add option to prune ignore file with `-I`
|
|
5
|
+
* Improved Slim template support
|
|
6
|
+
* Show obsolete ignore entries in reports (Jonathan Cheatham)
|
|
7
|
+
* Support creating reports in non-existent paths
|
|
8
|
+
* Add `--no-exit-warn`
|
|
9
|
+
|
|
1
10
|
# 3.3.5
|
|
2
11
|
|
|
3
12
|
* Fix bug in reports when using --debug option
|
data/bundle/load.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
path = File.expand_path('../..', __FILE__)
|
|
2
2
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/haml-4.0.7/lib"
|
|
3
|
+
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/terminal-table-1.7.1/lib"
|
|
3
4
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/highline-1.7.8/lib"
|
|
4
5
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/temple-0.7.7/lib"
|
|
6
|
+
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/unicode-display_width-1.1.1/lib"
|
|
5
7
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/ruby_parser-3.8.2/lib"
|
|
6
8
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/ruby2ruby-2.3.0/lib"
|
|
7
9
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/sexp_processor-4.7.0/lib"
|
|
@@ -9,6 +11,5 @@ $:.unshift "#{path}/bundle/ruby/2.3.0/gems/slim-3.0.7/lib"
|
|
|
9
11
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/sass-3.4.22/lib"
|
|
10
12
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/sass-3.4.22/vendor/listen/lib"
|
|
11
13
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/erubis-2.7.0/lib"
|
|
12
|
-
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/terminal-table-1.6.0/lib"
|
|
13
14
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/safe_yaml-1.0.4/lib"
|
|
14
15
|
$:.unshift "#{path}/bundle/ruby/2.3.0/gems/tilt-2.0.5/lib"
|
|
File without changes
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
1.7.1 / 2016-08-29
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
* Update `unicode-display_width` to fix behavior with signal traps [#78, @jrmhaig]
|
|
5
|
+
|
|
6
|
+
1.7.0 / 2016-08-29
|
|
7
|
+
==================
|
|
8
|
+
|
|
9
|
+
All props to @vizv for this release!
|
|
10
|
+
|
|
11
|
+
* Fixed some spec failures
|
|
12
|
+
* Added support for full-width characters (East Asian alphabets, etc)
|
|
13
|
+
|
|
1
14
|
1.6.0 / 2016-06-06
|
|
2
15
|
==================
|
|
3
16
|
|
|
File without changes
|
|
@@ -190,7 +190,7 @@ And change styles on the fly:
|
|
|
190
190
|
|
|
191
191
|
To change the default style options:
|
|
192
192
|
|
|
193
|
-
Terminal::Style.defaults = {:width => 80}
|
|
193
|
+
Terminal::Table::Style.defaults = {:width => 80}
|
|
194
194
|
|
|
195
195
|
All Table objects created afterwards will inherit these defaults.
|
|
196
196
|
|
|
File without changes
|
|
File without changes
|
data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/examples/examples.rb
RENAMED
|
File without changes
|
data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table.rb
RENAMED
|
File without changes
|
data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/cell.rb
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'unicode/display_width'
|
|
2
|
+
|
|
1
3
|
module Terminal
|
|
2
4
|
class Table
|
|
3
5
|
class Cell
|
|
@@ -55,7 +57,8 @@ module Terminal
|
|
|
55
57
|
def render(line = 0)
|
|
56
58
|
left = " " * @table.style.padding_left
|
|
57
59
|
right = " " * @table.style.padding_right
|
|
58
|
-
|
|
60
|
+
display_width = Unicode::DisplayWidth.of(escape(lines[line]))
|
|
61
|
+
render_width = lines[line].to_s.size - display_width + width
|
|
59
62
|
align("#{left}#{lines[line]}#{right}", alignment, render_width + @table.cell_padding)
|
|
60
63
|
end
|
|
61
64
|
alias :to_s :render
|
|
@@ -65,7 +68,7 @@ module Terminal
|
|
|
65
68
|
# removes all ANSI escape sequences (e.g. color)
|
|
66
69
|
|
|
67
70
|
def value_for_column_width_recalc
|
|
68
|
-
lines.map{ |s| escape(s) }.max_by{ |s| s
|
|
71
|
+
lines.map{ |s| escape(s) }.max_by{ |s| Unicode::DisplayWidth.of(s) }
|
|
69
72
|
end
|
|
70
73
|
|
|
71
74
|
##
|
|
File without changes
|
data/bundle/ruby/2.3.0/gems/{terminal-table-1.6.0 → terminal-table-1.7.1}/lib/terminal-table/row.rb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'unicode/display_width'
|
|
2
|
+
|
|
1
3
|
module Terminal
|
|
2
4
|
class Table
|
|
3
5
|
|
|
@@ -57,7 +59,15 @@ module Terminal
|
|
|
57
59
|
|
|
58
60
|
def column n, method = :value, array = rows
|
|
59
61
|
array.map { |row|
|
|
60
|
-
|
|
62
|
+
# for each cells in a row, find the column with index
|
|
63
|
+
# just greater than the required one, and go back one.
|
|
64
|
+
index = col = 0
|
|
65
|
+
row.cells.each do |cell|
|
|
66
|
+
break if index > n
|
|
67
|
+
index += cell.colspan
|
|
68
|
+
col += 1
|
|
69
|
+
end
|
|
70
|
+
cell = row[col - 1]
|
|
61
71
|
cell && method ? cell.__send__(method) : cell
|
|
62
72
|
}.compact
|
|
63
73
|
end
|
|
@@ -126,7 +136,7 @@ module Terminal
|
|
|
126
136
|
buffer += @rows
|
|
127
137
|
buffer << separator
|
|
128
138
|
end
|
|
129
|
-
buffer.map { |r| style.margin_left + r.render }.join("\n")
|
|
139
|
+
buffer.map { |r| style.margin_left + r.render.rstrip }.join("\n")
|
|
130
140
|
end
|
|
131
141
|
alias :to_s :render
|
|
132
142
|
|
|
@@ -192,7 +202,7 @@ module Terminal
|
|
|
192
202
|
colspan = cell.colspan
|
|
193
203
|
cell_value = cell.value_for_column_width_recalc
|
|
194
204
|
colspan.downto(1) do |j|
|
|
195
|
-
cell_length = cell_value.to_s
|
|
205
|
+
cell_length = Unicode::DisplayWidth.of(cell_value.to_s)
|
|
196
206
|
if colspan > 1
|
|
197
207
|
spacing_length = cell_spacing * (colspan - 1)
|
|
198
208
|
length_in_columns = (cell_length - spacing_length)
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
* Always load index into memory, fixes #9
|
|
6
|
+
|
|
7
|
+
## 1.1.0
|
|
8
|
+
|
|
9
|
+
* Support Unicode 9.0
|
|
10
|
+
|
|
11
|
+
## 1.0.5
|
|
12
|
+
|
|
13
|
+
* Actually include new index from 1.0.4
|
|
14
|
+
|
|
15
|
+
## 1.0.4
|
|
16
|
+
|
|
17
|
+
* New index format (much smaller) and internal API changes
|
|
18
|
+
* Move index generation to a builder plugin for the unicoder gem
|
|
19
|
+
* No public API changes
|
|
20
|
+
|
|
21
|
+
## 1.0.3
|
|
22
|
+
|
|
23
|
+
* Avoid circular dependency warning
|
|
24
|
+
|
|
25
|
+
## 1.0.2
|
|
26
|
+
|
|
27
|
+
* Fix error that gemspec might be invalid under some circumstances (see gh#6)
|
|
28
|
+
|
|
29
|
+
## 1.0.1
|
|
30
|
+
|
|
31
|
+
* Inofficially allow Ruby 1.9
|
|
32
|
+
|
|
33
|
+
## 1.0.0
|
|
34
|
+
|
|
35
|
+
* Faster than 0.3.1
|
|
36
|
+
* Advanced determination of character width
|
|
37
|
+
* This includes: Treat width of most chars of general categories (Mn, Me, Cf) as 0
|
|
38
|
+
* This includes: Introduce list of characters with special widths
|
|
39
|
+
* Allow custom overrides for specific codepoints
|
|
40
|
+
* Set required Ruby version to 2.0
|
|
41
|
+
* Add NO_STRING_EXT mode to disable monkey patching
|
|
42
|
+
* Internal API & index format changed drastically
|
|
43
|
+
* Remove require 'unicode/display_size' (use 'unicode/display_width' instead)
|
|
44
|
+
|
|
45
|
+
## 0.3.1
|
|
46
|
+
|
|
47
|
+
* Faster than 0.3.0
|
|
48
|
+
* Deprecate usage of aliases: String#display_size and String#display_length
|
|
49
|
+
* Eliminate Ruby warnings (@amatsuda)
|
|
50
|
+
|
|
51
|
+
## 0.3.0
|
|
52
|
+
|
|
53
|
+
* Update EastAsianWidth from 7.0 to 8.0
|
|
54
|
+
* Add rake task to update EastAsianWidth.txt
|
|
55
|
+
* Move code to generate index from library to Rakefile
|
|
56
|
+
* Update project's meta files
|
|
57
|
+
* Deprecate requiring 'unicode-display_size'
|
|
58
|
+
|
|
59
|
+
## 0.2.0
|
|
60
|
+
|
|
61
|
+
* Update EastAsianWidth from 6.0 to 7.0
|
|
62
|
+
* Don't build index table automatically when not available
|
|
63
|
+
* Don't include EastAsianWidth.txt in gem (only index)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## 0.1.0
|
|
67
|
+
|
|
68
|
+
* Fix github issue #1
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## 0.1.0
|
|
72
|
+
|
|
73
|
+
* Initial release
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2011, 2015-2016 Jan Lelis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
## Unicode::DisplayWidth [![[version]](https://badge.fury.io/rb/unicode-display_width.svg)](http://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)
|
|
2
|
+
|
|
3
|
+
Determines the monospace display width of a string in Ruby. Implementation based on [EastAsianWidth.txt](http://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.
|
|
4
|
+
|
|
5
|
+
Unicode version: **9.0.0**
|
|
6
|
+
|
|
7
|
+
## Introduction to Character Widths
|
|
8
|
+
|
|
9
|
+
Guesing the correct space a character will consume on terminals is not easy. There is no single standard. Most implementations combine data from [East Asian Width](http://www.unicode.org/reports/tr11/), some [General Categories](https://en.wikipedia.org/wiki/Unicode_character_property#General_Category), and hand-picked adjustments.
|
|
10
|
+
|
|
11
|
+
### How this Library Handles Widths
|
|
12
|
+
|
|
13
|
+
Further at the top means higher precedence. Please expect changes to this algorithm with every MINOR version update (the X in 1.X.0)!
|
|
14
|
+
|
|
15
|
+
Width | Characters | Comment
|
|
16
|
+
-------|------------------------------|--------------------------------------------------
|
|
17
|
+
X | (user defined) | Overwrites any other values
|
|
18
|
+
-1 | `"\b"` | Backspace (total width never below 0)
|
|
19
|
+
0 | `"\0"`, `"\x05"`, `"\a"`, `"\n"`, `"\v"`, `"\f"`, `"\r"`, `"\x0E"`, `"\x0F"` | [C0 control codes](https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0_.28ASCII_and_derivatives.29) that do not change horizontal width
|
|
20
|
+
1 | `"\u{00AD}"` | SOFT HYPHEN
|
|
21
|
+
2 | `"\u{2E3A}"` | TWO-EM DASH
|
|
22
|
+
3 | `"\u{2E3B}"` | THREE-EM DASH
|
|
23
|
+
0 | General Categories: Mn, Me, Cf (non-arabic) | Excludes ARABIC format characters
|
|
24
|
+
0 | `"\u{1160}".."\u{11FF}"` | HANGUL JUNGSEONG
|
|
25
|
+
2 | East Asian Width: F, W | Full-width characters
|
|
26
|
+
1 or 2 | East Asian Width: A | Ambiguous characters, user defined, default: 1
|
|
27
|
+
1 | All other codepoints | -
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
Install the gem with:
|
|
32
|
+
|
|
33
|
+
gem install unicode-display_width
|
|
34
|
+
|
|
35
|
+
Or add to your Gemfile:
|
|
36
|
+
|
|
37
|
+
gem 'unicode-display_width'
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'unicode/display_width'
|
|
43
|
+
|
|
44
|
+
Unicode::DisplayWidth.of("⚀") # => 1
|
|
45
|
+
Unicode::DisplayWidth.of("一") # => 2
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Ambiguous Characters
|
|
49
|
+
|
|
50
|
+
The second parameter defines the value returned by characterrs defined as ambiguous:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
Unicode::DisplayWidth.of("·", 1) # => 1
|
|
54
|
+
Unicode::DisplayWidth.of("·", 2) # => 2
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Custom Overwrites
|
|
58
|
+
|
|
59
|
+
You can overwrite how to handle specific code points by passing a hash (or even a proc) as third parameter:
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
Unicode::DisplayWidth.of("a\tb", 1, 0x09 => 10)) # => 12
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Usage with String Extension
|
|
66
|
+
|
|
67
|
+
Activated by default. Will be deactivated in version 2.0:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
require 'unicode/display_width/string_ext'
|
|
71
|
+
|
|
72
|
+
"⚀".display_width #=> 1
|
|
73
|
+
'一'.display_width #=> 2
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
You can actively opt-out from the string extension with: `require 'unicode/display_width/no_string_ext'`
|
|
77
|
+
|
|
78
|
+
### Usage From the CLI
|
|
79
|
+
|
|
80
|
+
Use this one-liner to print out display widths for strings from the command-line:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
$ gem install unicode-display_width
|
|
84
|
+
$ ruby -r unicode/display_width -e 'puts Unicode::DisplayWidth.of $*[0]' -- "一"
|
|
85
|
+
```
|
|
86
|
+
Replace "一" with the actual string to measure
|
|
87
|
+
|
|
88
|
+
## Other Implementations & Discussion
|
|
89
|
+
|
|
90
|
+
- Python: https://github.com/jquast/wcwidth
|
|
91
|
+
- JavaScript: https://github.com/mycoboco/wcwidth.js
|
|
92
|
+
- C: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
|
|
93
|
+
- C for Julia: https://github.com/JuliaLang/utf8proc/issues/2
|
|
94
|
+
|
|
95
|
+
See [unicode-x](https://github.com/janlelis/unicode-x) for more Unicode related micro libraries.
|
|
96
|
+
|
|
97
|
+
## Copyright & Info
|
|
98
|
+
|
|
99
|
+
- Copyright (c) 2011, 2015-2016 Jan Lelis, http://janlelis.com, released under the MIT
|
|
100
|
+
license
|
|
101
|
+
- Early versions based on runpaint's unicode-data interface: Copyright (c) 2009 Run Paint Run Run
|
|
102
|
+
- Unicode data: http://www.unicode.org/copyright.html#Exhibit1
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# # #
|
|
2
|
+
# Get gemspec info
|
|
3
|
+
|
|
4
|
+
gemspec_file = Dir['*.gemspec'].first
|
|
5
|
+
gemspec = eval File.read(gemspec_file), binding, gemspec_file
|
|
6
|
+
info = "#{gemspec.name} | #{gemspec.version} | " \
|
|
7
|
+
"#{gemspec.runtime_dependencies.size} dependencies | " \
|
|
8
|
+
"#{gemspec.files.size} files"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# # #
|
|
12
|
+
# Gem build and install task
|
|
13
|
+
|
|
14
|
+
desc info
|
|
15
|
+
task :gem do
|
|
16
|
+
puts info + "\n\n"
|
|
17
|
+
print " "; sh "gem build #{gemspec_file}"
|
|
18
|
+
FileUtils.mkdir_p 'pkg'
|
|
19
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
|
20
|
+
puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# # #
|
|
25
|
+
# Start an IRB session with the gem loaded
|
|
26
|
+
|
|
27
|
+
desc "#{gemspec.name} | IRB"
|
|
28
|
+
task :irb do
|
|
29
|
+
sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# # #
|
|
33
|
+
# Run all specs
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
desc "#{gemspec.name} | Test"
|
|
37
|
+
task :test do
|
|
38
|
+
sh "rspec spec"
|
|
39
|
+
end
|
|
40
|
+
task :default => :test
|
|
41
|
+
|
|
42
|
+
# # #
|
|
43
|
+
# Update index table
|
|
44
|
+
|
|
45
|
+
namespace :update do
|
|
46
|
+
desc "#{gemspec.name} | Update index"
|
|
47
|
+
task :index do
|
|
48
|
+
require File.dirname(__FILE__) + '/lib/unicode/display_width/index_builder'
|
|
49
|
+
Unicode::DisplayWidth::IndexBuilder.build!
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# # #
|
|
54
|
+
# Update data file
|
|
55
|
+
|
|
56
|
+
namespace :update do
|
|
57
|
+
desc "#{gemspec.name} | Update unicode data"
|
|
58
|
+
task :data do
|
|
59
|
+
require File.dirname(__FILE__) + '/lib/unicode/display_width/index_builder'
|
|
60
|
+
Unicode::DisplayWidth::IndexBuilder.fetch!
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require_relative 'display_width/constants'
|
|
2
|
+
require_relative 'display_width/index'
|
|
3
|
+
|
|
4
|
+
module Unicode
|
|
5
|
+
module DisplayWidth
|
|
6
|
+
def self.of(string, ambiguous = 1, overwrite = {})
|
|
7
|
+
res = string.unpack('U*').inject(0){ |total_width, codepoint|
|
|
8
|
+
index_or_value = INDEX
|
|
9
|
+
codepoint_depth_offset = codepoint
|
|
10
|
+
[0x10000, 0x1000, 0x100, 0x10].each{ |depth|
|
|
11
|
+
index_or_value = index_or_value[codepoint_depth_offset / depth]
|
|
12
|
+
codepoint_depth_offset = codepoint_depth_offset % depth
|
|
13
|
+
break unless index_or_value.is_a? Array
|
|
14
|
+
}
|
|
15
|
+
width = index_or_value.is_a?(Array) ? index_or_value[codepoint_depth_offset] : index_or_value
|
|
16
|
+
width = ambiguous if width == :A
|
|
17
|
+
total_width + (overwrite[codepoint] || width || 1)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
res < 0 ? 0 : res
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Allows you to opt-out of the default string extension. Will eventually be removed,
|
|
26
|
+
# so you must opt-in for the core extension by requiring 'display_width/string_ext'
|
|
27
|
+
unless defined?(Unicode::DisplayWidth::NO_STRING_EXT) && Unicode::DisplayWidth::NO_STRING_EXT
|
|
28
|
+
require_relative 'display_width/string_ext'
|
|
29
|
+
end
|
|
30
|
+
|