unisec 0.0.1 → 0.0.2

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: 1496d192c32a345de077d1643d041f15f960095f4931165a19b1250a52c5897e
4
- data.tar.gz: 553ce1f9fa9d21895d31c144dc15fc73483a7301ececa1046138eec9b51a8707
3
+ metadata.gz: ce2d8764170d8ac6976db2dd115a0d31c232b1c933de4d9b55b47cc7d8af9f1e
4
+ data.tar.gz: 29279259ec14a9ff8d1752d5554c601259999d10fcd447795b2bdcbd6be984af
5
5
  SHA512:
6
- metadata.gz: ae33d34f6bdf6ae0c5a3dd97ffdb3beaf9b2b7a3d3d48697502b272a8db4fc17a6f91bec5596b12c83d7cc609f0b3f7c9a80b7da09d5584537388868364810a5
7
- data.tar.gz: c440d1868a5a97a8d6a126c66541d5627ea039086f85d90347dcb52910c32ebc9d1c97f28ce3e0fef62b209f0c982e24414edce98a32406bbc1f802f42bd8ef4
6
+ metadata.gz: 1e23f9ec4a267c592d4caad37fd452c0ee9498ed4d06578868acc69022ebf55cd5614ef18b0099272de040be7eb85f34d9e1f6f0665112407189835e879ccd3a
7
+ data.tar.gz: 42a10be34f6f3ee20288d5896971acabdd6082fd9c739e9edb7173c2246f44f609a59d677977d4f50dbaafcbd3603b30174bf0115fe718c5381048754b665607
@@ -4,6 +4,8 @@ require 'unisec/cli/surrogates'
4
4
  require 'unisec/cli/hexdump'
5
5
  require 'unisec/cli/properties'
6
6
  require 'unisec/cli/confusables'
7
+ require 'unisec/cli/versions'
8
+ require 'unisec/cli/size'
7
9
 
8
10
  module Unisec
9
11
  # Module used to create the CLI for the executable
@@ -22,6 +24,8 @@ module Unisec
22
24
  register 'properties char', Properties::Char
23
25
  register 'confusables list', Confusables::List
24
26
  register 'confusables randomize', Confusables::Randomize
27
+ register 'versions', Versions
28
+ register 'size', Size
25
29
  end
26
30
  end
27
31
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/cli'
4
+ require 'unisec'
5
+
6
+ module Unisec
7
+ module CLI
8
+ module Commands
9
+ # CLI command `unisec size` for the class {Unisec::Size} from the lib.
10
+ #
11
+ # Example:
12
+ #
13
+ # ```plaintext
14
+ # $ unisec size 🧑🏼‍🔬
15
+ # Code point(s): 4
16
+ # Grapheme(s): 1
17
+ # UTF-8 byte(s): 15
18
+ # UTF-16 byte(s): 14
19
+ # UTF-32 byte(s): 16
20
+ # UTF-8 unit(s): 15
21
+ # UTF-16 unit(s): 7
22
+ # UTF-32 unit(s): 4
23
+ # ```
24
+ class Size < Dry::CLI::Command
25
+ desc 'All kinf of size information about a Unicode string'
26
+
27
+ argument :input, required: true,
28
+ desc: 'String input'
29
+
30
+ # All kinf of size information about a Unicode string.
31
+ # @param input [String] Input sting we want to know the size of
32
+ def call(input: nil, **)
33
+ puts Unisec::Size.new(input).display
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/cli'
4
+ require 'unisec'
5
+
6
+ module Unisec
7
+ module CLI
8
+ module Commands
9
+ # CLI command `unisec versions` for the class {Unisec::Versions} from the lib.
10
+ #
11
+ # Example:
12
+ #
13
+ # ```plaintext
14
+ # $ unisec versions
15
+ # Unicode:
16
+ # Unicode (Ruby) 15.0.0
17
+ # Unicode (twitter_cldr gem) 14.0.0
18
+ # Unicode (unicode-confusable gem) 15.0.0
19
+ # ICU (twitter_cldr gem) 70.1
20
+ # CLDR (twitter_cldr gem) 40
21
+ # Unicode emoji (Ruby) 15.0
22
+ #
23
+ # Gems:
24
+ # unisec 0.0.1
25
+ # twitter_cldr gem 6.11.5
26
+ # unicode-confusable gem 1.9.0
27
+ # ```
28
+ class Versions < Dry::CLI::Command
29
+ desc 'Version of anything related to Unicode as used in unisec'
30
+
31
+ # Version of anything related to Unicode as used in unisec.
32
+ def call(**)
33
+ puts Unisec::Versions.display
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'paint'
4
+
5
+ module Unisec
6
+ # All kinf of size information about a Unicode string
7
+ class Size
8
+ # Number of code points
9
+ # @return [Integer] number of code points
10
+ # @example
11
+ # us = Unisec::Size.new('👩‍❤️‍👩')
12
+ # us.code_points_size # => 6
13
+ attr_reader :code_points_size
14
+
15
+ # Number of graphemes
16
+ # @return [Integer] number of graphemes
17
+ # @example
18
+ # us = Unisec::Size.new('👩‍❤️‍👩')
19
+ # us.grapheme_size # => 1
20
+ attr_reader :grapheme_size
21
+
22
+ # UTF-8 size in bytes
23
+ # @return [Integer] UTF-8 size in bytes
24
+ # @example
25
+ # us = Unisec::Size.new('👩‍❤️‍👩')
26
+ # us.utf8_bytesize # => 20
27
+ attr_reader :utf8_bytesize
28
+
29
+ # UTF-16 size in bytes
30
+ # @return [Integer] UTF-16 size in bytes
31
+ # @example
32
+ # us = Unisec::Size.new('👩‍❤️‍👩')
33
+ # us.utf16_bytesize # => 16
34
+ attr_reader :utf16_bytesize
35
+
36
+ # UTF-32 size in bytes
37
+ # @return [Integer] UTF-32 size in bytes
38
+ # @example
39
+ # us = Unisec::Size.new('👩‍❤️‍👩')
40
+ # us.utf32_bytesize # => 24
41
+ attr_reader :utf32_bytesize
42
+
43
+ # Number of UTF-8 units
44
+ # @return [Integer] number of UTF-8 units
45
+ # @example
46
+ # us = Unisec::Size.new('👩‍❤️‍👩')
47
+ # us.utf8_unitsize # => 20
48
+ attr_reader :utf8_unitsize
49
+
50
+ # Number of UTF-16 units
51
+ # @return [Integer] number of UTF-16 units
52
+ # @example
53
+ # us = Unisec::Size.new('👩‍❤️‍👩')
54
+ # us.utf16_unitsize # => 8
55
+ attr_reader :utf16_unitsize
56
+
57
+ # Number of UTF-32 units
58
+ # @return [Integer] number of UTF-32 units
59
+ # @example
60
+ # us = Unisec::Size.new('👩‍❤️‍👩')
61
+ # us.utf32_unitsize # => 6
62
+ attr_reader :utf32_unitsize
63
+
64
+ def initialize(str)
65
+ @code_points_size = Size.code_points_size(str)
66
+ @grapheme_size = Size.grapheme_size(str)
67
+ @utf8_bytesize = Size.utf8_bytesize(str)
68
+ @utf16_bytesize = Size.utf16_bytesize(str)
69
+ @utf32_bytesize = Size.utf32_bytesize(str)
70
+ @utf8_unitsize = Size.utf8_unitsize(str)
71
+ @utf16_unitsize = Size.utf16_unitsize(str)
72
+ @utf32_unitsize = Size.utf32_unitsize(str)
73
+ end
74
+
75
+ # Number of code points
76
+ # @param str [String] Input sting we want to know the size of
77
+ # @return [Integer] number of code points
78
+ # @example
79
+ # Unisec::Size.code_points_size('👩‍❤️‍👩') # => 6
80
+ def self.code_points_size(str)
81
+ str.size
82
+ end
83
+
84
+ # Number of graphemes
85
+ # @param str [String] Input sting we want to know the size of
86
+ # @return [Integer] number of graphemes
87
+ # @example
88
+ # Unisec::Size.grapheme_size('👩‍❤️‍👩') # => 1
89
+ def self.grapheme_size(str)
90
+ str.grapheme_clusters.size
91
+ end
92
+
93
+ # UTF-8 size in bytes
94
+ # @param str [String] Input sting we want to know the size of
95
+ # @return [Integer] UTF-8 size in bytes
96
+ # @example
97
+ # Unisec::Size.utf8_bytesize('👩‍❤️‍👩') # => 20
98
+ def self.utf8_bytesize(str)
99
+ str.bytesize
100
+ end
101
+
102
+ # UTF-16 size in bytes
103
+ # @param str [String] Input sting we want to know the size of
104
+ # @return [Integer] UTF-16 size in bytes
105
+ # @example
106
+ # Unisec::Size.utf16_bytesize('👩‍❤️‍👩') # => 16
107
+ def self.utf16_bytesize(str)
108
+ str.encode('UTF-16BE').bytesize
109
+ end
110
+
111
+ # UTF-32 size in bytes
112
+ # @param str [String] Input sting we want to know the size of
113
+ # @return [Integer] UTF-32 size in bytes
114
+ # @example
115
+ # Unisec::Size.utf32_bytesize('👩‍❤️‍👩') # => 24
116
+ def self.utf32_bytesize(str)
117
+ str.encode('UTF-32BE').bytesize
118
+ end
119
+
120
+ # Number of UTF-8 units
121
+ # @param str [String] Input sting we want to know the size of
122
+ # @return [Integer] number of UTF-8 units
123
+ # @example
124
+ # Unisec::Size.utf8_unitsize('👩‍❤️‍👩') # => 20
125
+ def self.utf8_unitsize(str)
126
+ utf8_bytesize(str)
127
+ end
128
+
129
+ # Number of UTF-16 units
130
+ # @param str [String] Input sting we want to know the size of
131
+ # @return [Integer] number of UTF-16 units
132
+ # @example
133
+ # Unisec::Size.utf16_unitsize('👩‍❤️‍👩') # => 8
134
+ def self.utf16_unitsize(str)
135
+ utf16_bytesize(str) / 2
136
+ end
137
+
138
+ # Number of UTF-32 units
139
+ # @param str [String] Input sting we want to know the size of
140
+ # @return [Integer] number of UTF-32 units
141
+ # @example
142
+ # Unisec::Size.utf32_unitsize('👩‍❤️‍👩') # => 6
143
+ def self.utf32_unitsize(str)
144
+ utf32_bytesize(str) / 4
145
+ end
146
+
147
+ # Display a CLI-friendly output summurizing the size information about a Unicode string.
148
+ # @example
149
+ # Unisec::Size.new('👩‍❤️‍👨').display
150
+ # # =>
151
+ # # Code point(s): 6
152
+ # # Grapheme(s): 1
153
+ # # UTF-8 byte(s): 20
154
+ # # UTF-16 byte(s): 16
155
+ # # UTF-32 byte(s): 24
156
+ # # UTF-8 unit(s): 20
157
+ # # UTF-16 unit(s): 8
158
+ # # UTF-32 unit(s): 6
159
+ def display
160
+ display = ->(key, value) { puts Paint[key, :red, :bold].ljust(27) + " #{value}" }
161
+ display.call('Code point(s):', @code_points_size)
162
+ display.call('Grapheme(s):', @grapheme_size)
163
+ display.call('UTF-8 byte(s):', @utf8_bytesize)
164
+ display.call('UTF-16 byte(s):', @utf16_bytesize)
165
+ display.call('UTF-32 byte(s):', @utf32_bytesize)
166
+ display.call('UTF-8 unit(s):', @utf8_unitsize)
167
+ display.call('UTF-16 unit(s):', @utf16_unitsize)
168
+ display.call('UTF-32 unit(s):', @utf32_unitsize)
169
+ end
170
+ end
171
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Unisec
4
4
  # Version of unisec library and app
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'twitter_cldr'
4
+ require 'unicode/confusable'
5
+ require 'paint'
6
+
7
+ module Unisec
8
+ # Version information related to Unicode used in Unisec
9
+ class Versions
10
+ # Version and label of anything related to Unicode used in Unisec
11
+ # @return [Hash] versions of each component
12
+ # @example
13
+ # Unisec::Versions.versions
14
+ # # =>
15
+ # # {:unisec=>{:version=>"0.0.1", :label=>"unisec"},
16
+ # # … }
17
+ def self.versions # rubocop:disable Metrics/MethodLength
18
+ {
19
+ unisec: {
20
+ version: Unisec::VERSION,
21
+ label: 'unisec'
22
+ },
23
+ ruby_unicode: {
24
+ version: RbConfig::CONFIG['UNICODE_VERSION'],
25
+ label: 'Unicode (Ruby)'
26
+ },
27
+ ruby_unicode_emoji: {
28
+ version: RbConfig::CONFIG['UNICODE_EMOJI_VERSION'],
29
+ label: 'Unicode emoji (Ruby)'
30
+ },
31
+ twittercldr_cldr: {
32
+ version: TwitterCldr::Versions::CLDR_VERSION,
33
+ label: 'CLDR (twitter_cldr gem)'
34
+ },
35
+ twittercldr_icu: {
36
+ version: TwitterCldr::Versions::ICU_VERSION,
37
+ label: 'ICU (twitter_cldr gem)'
38
+ },
39
+ twittercldr_unicode: {
40
+ version: TwitterCldr::Versions::UNICODE_VERSION,
41
+ label: 'Unicode (twitter_cldr gem)'
42
+ },
43
+ twittercldr: {
44
+ version: TwitterCldr::VERSION,
45
+ label: 'twitter_cldr gem'
46
+ },
47
+ unicodeconfusable: {
48
+ version: Unicode::Confusable::VERSION,
49
+ label: 'unicode-confusable gem'
50
+ },
51
+ unicodeconfusable_unicode: {
52
+ version: Unicode::Confusable::UNICODE_VERSION,
53
+ label: 'Unicode (unicode-confusable gem)'
54
+ }
55
+ }
56
+ end
57
+
58
+ # Display a CLI-friendly output of the version of anything related to Unicode used in unisec
59
+ # @example
60
+ # Unisec::Versions.display
61
+ # # =>
62
+ # # Unicode:
63
+ # # Unicode (Ruby) 15.0.0
64
+ # # …
65
+ # #
66
+ # # Gems:
67
+ # # unisec 0.0.1
68
+ # # …
69
+ def self.display # rubocop:disable Metrics/AbcSize
70
+ data = versions
71
+ display = ->(node) { puts Paint[data[node][:label], :red, :bold].ljust(44) + " #{data[node][:version]}" }
72
+ puts Paint['Unicode:', :underline]
73
+ display.call(:ruby_unicode)
74
+ display.call(:twittercldr_unicode)
75
+ display.call(:unicodeconfusable_unicode)
76
+ display.call(:twittercldr_icu)
77
+ display.call(:twittercldr_cldr)
78
+ display.call(:ruby_unicode_emoji)
79
+ puts Paint["\nGems:", :underline]
80
+ display.call(:unisec)
81
+ display.call(:twittercldr)
82
+ display.call(:unicodeconfusable)
83
+ end
84
+ end
85
+ end
data/lib/unisec.rb CHANGED
@@ -6,3 +6,5 @@ require 'unisec/surrogates'
6
6
  require 'unisec/hexdump'
7
7
  require 'unisec/properties'
8
8
  require 'unisec/confusables'
9
+ require 'unisec/versions'
10
+ require 'unisec/size'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unisec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre ZANNI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-21 00:00:00.000000000 Z
11
+ date: 2023-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ctf-party
@@ -100,13 +100,17 @@ files:
100
100
  - lib/unisec/cli/confusables.rb
101
101
  - lib/unisec/cli/hexdump.rb
102
102
  - lib/unisec/cli/properties.rb
103
+ - lib/unisec/cli/size.rb
103
104
  - lib/unisec/cli/surrogates.rb
105
+ - lib/unisec/cli/versions.rb
104
106
  - lib/unisec/confusables.rb
105
107
  - lib/unisec/hexdump.rb
106
108
  - lib/unisec/properties.rb
109
+ - lib/unisec/size.rb
107
110
  - lib/unisec/surrogates.rb
108
111
  - lib/unisec/utils.rb
109
112
  - lib/unisec/version.rb
113
+ - lib/unisec/versions.rb
110
114
  homepage: https://github.com/Acceis/unisec
111
115
  licenses:
112
116
  - MIT