compact_enc_det 0.3.0 → 0.5.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: bef63e0da461545062b0ead5c255b5fee0446f0443b72378a06ae8a66b4f317d
4
- data.tar.gz: 747de82200ca394670e00a4b8ff7b13e4447f92f3e3a78959fdd2067d51a3928
3
+ metadata.gz: b279e2ff76dcfe77ac5fa5a5b1b4460558f4623e4cad9cb5443f2b72d1bcc15c
4
+ data.tar.gz: 1bbbd0b13a4c2bd197d52b5a889f05d406f1b77a2a0f4bbe5f48adc977baef9e
5
5
  SHA512:
6
- metadata.gz: c07116dce4e14f7063f46df843421ee54f4ec85732fdaf6ab184765b214bb1baada1c3a8ccb5efabcf18c7c3e366cca50462f24d7f52e0dd6bbfd5f258c45bcf
7
- data.tar.gz: dabdeaebfd479321168e07e6b76674dffe92d07063cc31a0929a005464256d55a0105c31c146fdf5acf5779d80d7ab6b186b7fc65eb3b450c97e8a311cfdc105
6
+ metadata.gz: f8218d5eb64fbe44933a274d793972088fe7a6239862d8f733067d31968d724c720ea265dac9913b902012958a5987ef4f754b452384044025c8ebc25333bce9
7
+ data.tar.gz: fa4956674eb82b53e206a00f99568108e780512040e4e035420681e1d46610038645a32d8fba5143429e5e46f8f7fd2891e65b8ef7768647333b23cf21363608
data/README.md CHANGED
@@ -32,7 +32,7 @@ which is a thin wrapper around `CompactEncDet::DetectEncoding` and `MimeEncoding
32
32
 
33
33
  > ```ruby
34
34
  > file = File.read("unknown-encoding.txt")
35
- > result = CompactEncDet.detect_encoding(file, file.bytesize)
35
+ > result = CompactEncDet.detect_encoding(file)
36
36
  > result.encoding
37
37
  > # => #<Encoding:Windows-1250>
38
38
  > result.bytes_consumed
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env sh
2
2
  #
3
3
  # Copyright 2016 Google Inc.
4
4
  #
@@ -34,8 +34,8 @@ void Init_detect_encoding_result(VALUE rb_mCompactEncDet)
34
34
  // for the CompactEncDet::DetectEncoding C++ function
35
35
  static VALUE detect_encoding(int argc, VALUE *argv, VALUE self)
36
36
  {
37
- VALUE ruby_text,
38
- ruby_text_length,
37
+ VALUE text,
38
+ text_length,
39
39
  url_hint,
40
40
  http_charset_hint,
41
41
  meta_charset_hint,
@@ -45,9 +45,9 @@ static VALUE detect_encoding(int argc, VALUE *argv, VALUE self)
45
45
  ignore_7bit_mail_encodings;
46
46
 
47
47
  // Parse the Ruby arguments
48
- rb_scan_args(argc, argv, "27",
49
- &ruby_text,
50
- &ruby_text_length,
48
+ rb_scan_args(argc, argv, "17",
49
+ &text,
50
+ &text_length,
51
51
  &url_hint,
52
52
  &http_charset_hint,
53
53
  &meta_charset_hint,
@@ -56,9 +56,9 @@ static VALUE detect_encoding(int argc, VALUE *argv, VALUE self)
56
56
  &corpus_type,
57
57
  &ignore_7bit_mail_encodings);
58
58
 
59
- // Convert the Ruby values to C types
60
- const char *text = StringValueCStr(ruby_text);
61
- const int text_length = NUM2INT(ruby_text_length);
59
+ // Convert the Ruby arguments to C++ types
60
+ const char* c_text = StringValueCStr(text);
61
+ const int c_text_length = NIL_P(text_length) ? strlen(c_text) : NUM2INT(text_length);
62
62
 
63
63
  // Declare the output variables
64
64
  int bytes_consumed;
@@ -66,7 +66,8 @@ static VALUE detect_encoding(int argc, VALUE *argv, VALUE self)
66
66
 
67
67
  // Detect the encoding using CompactEncDet::DetectEncoding
68
68
  Encoding encoding = CompactEncDet::DetectEncoding(
69
- text, text_length,
69
+ c_text,
70
+ c_text_length,
70
71
  NIL_P(url_hint) ? nullptr : StringValueCStr(url_hint),
71
72
  NIL_P(http_charset_hint) ? nullptr : StringValueCStr(http_charset_hint),
72
73
  NIL_P(meta_charset_hint) ? nullptr : StringValueCStr(meta_charset_hint),
@@ -76,11 +77,11 @@ static VALUE detect_encoding(int argc, VALUE *argv, VALUE self)
76
77
  NIL_P(ignore_7bit_mail_encodings) ? false : RTEST(ignore_7bit_mail_encodings),
77
78
  &bytes_consumed,
78
79
  &is_reliable);
79
-
80
+
80
81
  // Convert the encoding enum to string using MimeEncodingName
81
82
  const char* encoding_mime_name = MimeEncodingName(encoding);
82
83
  VALUE rb_encoding_mime_name = rb_str_new_cstr(encoding_mime_name);
83
-
84
+
84
85
  // Find the Ruby Encoding class
85
86
  VALUE rb_encoding = rb_funcall(rb_cEncoding, rb_intern("find"), 1, rb_encoding_mime_name);
86
87
 
@@ -1,3 +1,3 @@
1
1
  module CompactEncDet
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compact_enc_det
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cloudaper