sanscript 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sanscript.rb +5 -7
- data/lib/sanscript/benchmark.rb +10 -10
- data/lib/sanscript/detect.rb +0 -4
- data/lib/sanscript/detect/ruby24.rb +1 -0
- data/lib/sanscript/detect/ruby2x.rb +1 -0
- data/lib/sanscript/detect/rust.rb +16 -0
- data/lib/sanscript/rust.rb +12 -6
- data/lib/sanscript/version.rb +1 -1
- data/src/detect/ruby.rs +1 -0
- data/src/rb.rs +4 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80ce63ec01301d3bafb6e0b5b2e407255c8764e3
|
4
|
+
data.tar.gz: 2da0b081137b3fa9a286e176adb1eea0a329fae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d377ccfbc03e784fa18d80b2e65189eb07c76bc012c57224fb12e01712391b511fd5ecb0fd0933545ab25d8c5480fccc0a08cb9adcdc79cecb94ef3168fdcb3
|
7
|
+
data.tar.gz: f1f2be9cbc4414d7c284322ba0d8525732436f7d0a80880b6dfaf5076f65f991fe38e143d69b9254327ecb983d7658182ff7b72ec1522745be5a6732af75bb61
|
data/lib/sanscript.rb
CHANGED
@@ -10,13 +10,11 @@ require "sanscript/benchmark"
|
|
10
10
|
|
11
11
|
# Sanscript.rb detection/transliteration module for Sanskrit.
|
12
12
|
module Sanscript
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
# :nocov:
|
13
|
+
# Whether Rust extension is available.
|
14
|
+
RUST_AVAILABLE = load_rust!
|
15
|
+
|
16
|
+
# Load rust if available.
|
17
|
+
rust_enable!
|
20
18
|
|
21
19
|
module_function
|
22
20
|
|
data/lib/sanscript/benchmark.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module Sanscript
|
4
|
+
# :nocov:
|
5
|
+
begin
|
6
|
+
require "benchmark/ips"
|
7
|
+
rescue LoadError
|
8
|
+
module ::Benchmark
|
9
|
+
def self.ips(*)
|
10
|
+
raise NotImplementedError, "You must install the `benchmark-ips` gem first."
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
|
-
|
13
|
-
# :nocov:
|
14
|
+
# :nocov:
|
14
15
|
|
15
|
-
module Sanscript
|
16
16
|
# Benchmark/testing module.
|
17
17
|
module Benchmark
|
18
18
|
module_function
|
data/lib/sanscript/detect.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
module Sanscript
|
4
4
|
module Detect
|
5
5
|
# Module implementing `detect_scheme` method using Ruby 2.4's faster Regexp#match? method
|
6
|
+
# (Note: This module will only load if chosen by {Sanscript::Detect}.)
|
6
7
|
module Ruby24
|
7
8
|
# Attempts to detect the encoding scheme of the provided string.
|
8
9
|
# Uses Ruby 2.4's Regexp#match? method for additional speed.
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module Sanscript
|
4
4
|
module Detect
|
5
5
|
# Module implementing `detect_scheme` method using Ruby 2.x-compatible syntax.
|
6
|
+
# (Note: This module will only load if chosen by {Sanscript::Detect}.)
|
6
7
|
module Ruby2x
|
7
8
|
# Attempts to detect the encoding scheme of the provided string.
|
8
9
|
#
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sanscript
|
4
|
+
module Detect
|
5
|
+
# Module stub for implementing `detect_scheme` method using Rust native extension.
|
6
|
+
# (Note: This module will only exist if the native extension is available and {Sanscript.load_rust!} has been run.)
|
7
|
+
module Rust
|
8
|
+
# @!method rust_detect_scheme(text)
|
9
|
+
# Attempts to detect the encoding scheme of the provided string.
|
10
|
+
# Uses Rust native extension for vastly increased performance.
|
11
|
+
#
|
12
|
+
# @param text [String] a string of Sanskrit text
|
13
|
+
# @return [Symbol, nil] the Symbol of the scheme, or nil if no match
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/sanscript/rust.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Sanscript
|
3
|
-
|
4
|
-
require "thermite/fiddle"
|
3
|
+
module_function
|
5
4
|
|
5
|
+
# Attempts to load Rust native extension.
|
6
|
+
# @return [bool] whether the extension loaded.
|
7
|
+
def load_rust!
|
8
|
+
return RUST_AVAILABLE if defined?(RUST_AVAILABLE)
|
9
|
+
require "thermite/fiddle"
|
6
10
|
Thermite::Fiddle.load_module("init_rusty_sanscript",
|
7
11
|
cargo_project_path: GEM_ROOT,
|
8
12
|
ruby_project_path: GEM_ROOT)
|
9
13
|
#:nocov:#
|
10
|
-
|
14
|
+
true
|
11
15
|
rescue Fiddle::DLError
|
12
|
-
|
16
|
+
false
|
13
17
|
#:nocov:#
|
14
18
|
end
|
15
19
|
|
16
|
-
module_function
|
17
|
-
|
18
20
|
# @return [bool] the enabled status of the Rust extension
|
19
21
|
def rust_enabled?
|
20
22
|
@rust_enabled
|
@@ -24,12 +26,16 @@ module Sanscript
|
|
24
26
|
# @return [bool] the enabled status of the Rust extension
|
25
27
|
def rust_enable!
|
26
28
|
if RUST_AVAILABLE
|
29
|
+
# :nocov:
|
27
30
|
Detect.module_eval do
|
28
31
|
class << self
|
29
32
|
alias_method :detect_scheme, :rust_detect_scheme
|
30
33
|
end
|
31
34
|
end
|
32
35
|
@rust_enabled = true
|
36
|
+
else
|
37
|
+
@rust_enabled = false
|
38
|
+
# :nocov:
|
33
39
|
end
|
34
40
|
@rust_enabled
|
35
41
|
end
|
data/lib/sanscript/version.rb
CHANGED
data/src/detect/ruby.rs
CHANGED
data/src/rb.rs
CHANGED
@@ -46,3 +46,7 @@ pub fn define_method(module: &Value, name: &str, method: CallbackPtr, argc: i32)
|
|
46
46
|
let c_strp = str_to_cstrp(name);
|
47
47
|
unsafe { class::rb_define_method(*module, c_strp, method, argc) }
|
48
48
|
}
|
49
|
+
|
50
|
+
pub fn extend_object(object: &Value, module: &Value) {
|
51
|
+
unsafe { class::rb_extend_object(*object, *module) }
|
52
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Bellefleur
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/sanscript/detect.rb
|
191
191
|
- lib/sanscript/detect/ruby24.rb
|
192
192
|
- lib/sanscript/detect/ruby2x.rb
|
193
|
+
- lib/sanscript/detect/rust.rb
|
193
194
|
- lib/sanscript/exceptions.rb
|
194
195
|
- lib/sanscript/rust.rb
|
195
196
|
- lib/sanscript/transliterate.rb
|