char_size 0.2.1 → 0.2.2
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/Rakefile +1 -1
- data/ext/char_size/char_size.c +18 -1
- data/lib/char_size/version.rb +1 -1
- data/lib/char_size.rb +0 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ff09b048174c469587fd7401ff10443c309a425
|
4
|
+
data.tar.gz: 03160e3cdfb739d42c06cedb046c97657f155b10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b1d680bc421595c1a61d9a3fa2f35946c5cfa701835af569d9c34a70e9a6a6a2fb4f2c08831645df839b6979b69bb0ea53ce2ac8a41bf6302d1a6ebd439bbc2
|
7
|
+
data.tar.gz: d44b11ddb4595c050b6e1b8b8dfc77617fc9ea68d9d1c6448a9f35fefe1b0e5ae84bfcb822e1b100b44914b9f4fcdad2ca6796cc1f0ea3dba63b6fc248335e53
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require "rake/extensiontask"
|
|
5
5
|
require "rake/testtask"
|
6
6
|
require "yard"
|
7
7
|
|
8
|
-
CLEAN.include
|
8
|
+
CLEAN.include("lib/char_size/char_size.#{RbConfig::CONFIG['DLEXT']}")
|
9
9
|
|
10
10
|
Rake::ExtensionTask.new :char_size, Bundler::GemHelper.gemspec do |ext|
|
11
11
|
ext.lib_dir = "lib/char_size"
|
data/ext/char_size/char_size.c
CHANGED
@@ -27,9 +27,26 @@ static VALUE max(VALUE class, VALUE encoding_or_name)
|
|
27
27
|
return INT2NUM(ONIGENC_MBC_MAXLEN(rb_to_encoding(encoding_or_name)));
|
28
28
|
}
|
29
29
|
|
30
|
-
|
30
|
+
/*
|
31
|
+
* Gets the minimum and maximum character size (in bytes) for an encoding.
|
32
|
+
* @param encoding_or_name [Encoding, String] the encoding or its name
|
33
|
+
* @return [Array<(Integer, Integer)>] the minimum and maximum character size
|
34
|
+
* @example
|
35
|
+
* CharSize.minmax("UTF-8") # => [1, 6]
|
36
|
+
* CharSize.minmax(Encoding::UTF_8) # => [1, 6]
|
37
|
+
*/
|
38
|
+
static VALUE minmax(VALUE class, VALUE encoding_or_name)
|
39
|
+
{
|
40
|
+
rb_encoding *enc = rb_to_encoding(encoding_or_name);
|
41
|
+
VALUE min = INT2NUM(ONIGENC_MBC_MINLEN(enc));
|
42
|
+
VALUE max = INT2NUM(ONIGENC_MBC_MAXLEN(enc));
|
43
|
+
return rb_assoc_new(min, max);
|
44
|
+
}
|
45
|
+
|
46
|
+
void Init_char_size(void)
|
31
47
|
{
|
32
48
|
VALUE CharSize = rb_define_module("CharSize");
|
33
49
|
rb_define_singleton_method(CharSize, "min", min, 1);
|
34
50
|
rb_define_singleton_method(CharSize, "max", max, 1);
|
51
|
+
rb_define_singleton_method(CharSize, "minmax", minmax, 1);
|
35
52
|
}
|
data/lib/char_size/version.rb
CHANGED
data/lib/char_size.rb
CHANGED
@@ -2,17 +2,3 @@
|
|
2
2
|
|
3
3
|
require "char_size/char_size"
|
4
4
|
require "char_size/version"
|
5
|
-
|
6
|
-
# The +CharSize+ module provides functions that return the character size limits
|
7
|
-
# of encodings.
|
8
|
-
module CharSize
|
9
|
-
# Gets the minimum and maximum character size (in bytes) for an encoding.
|
10
|
-
# @param encoding_or_name [Encoding, String] the encoding or its name
|
11
|
-
# @return [Array<(Integer, Integer)>] the minimum and maximum character size
|
12
|
-
# @example
|
13
|
-
# CharSize.minmax("UTF-8") # => [1, 6]
|
14
|
-
# CharSize.minmax(Encoding::UTF_8) # => [1, 6]
|
15
|
-
def self.minmax(encoding_or_name)
|
16
|
-
[min(encoding_or_name), max(encoding_or_name)]
|
17
|
-
end
|
18
|
-
end
|