sin_fast_blank 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/java/sin_fast_blank/SinFastBlankLibrary.java +115 -0
- data/lib/sin_fast_blank/sin_fast_blank.jar +0 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eeb9b11b9d94d52aa750db25c24b6f03aff5683df7de915585b45659aaa36532
|
4
|
+
data.tar.gz: 19303166df58b7b7cb15b97593c214acd802fa170fa99334921d5a054d0406e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06eaa63aaa21b76d7deca1ed55cb1aad6a04c0bf5923159d6e7e235e563c1b2a772a57136541da2e7acc71fb213e0e78b78d56076785016f79b6f971ca46ecb5
|
7
|
+
data.tar.gz: 1283ffc9c079f99d1814e091dc0b42b36eaf5930a86d1aafbc34cfcc6d09f040150374378921596e72f682f1effe50d69664139bff8fc6b943e48c79943ddc99
|
@@ -0,0 +1,115 @@
|
|
1
|
+
package sin_fast_blank;
|
2
|
+
|
3
|
+
import org.jcodings.Encoding;
|
4
|
+
import org.jruby.Ruby;
|
5
|
+
import org.jruby.RubyString;
|
6
|
+
import org.jruby.anno.JRubyMethod;
|
7
|
+
import org.jruby.runtime.ThreadContext;
|
8
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
9
|
+
import org.jruby.runtime.load.Library;
|
10
|
+
import org.jruby.util.ByteList;
|
11
|
+
import org.jruby.util.StringSupport;
|
12
|
+
import org.jruby.util.io.EncodingUtils;
|
13
|
+
|
14
|
+
public class SinFastBlankLibrary implements Library {
|
15
|
+
public void load(Ruby runtime, boolean wrap) {
|
16
|
+
runtime.getString().defineAnnotatedMethods(SinFastBlankLibrary.class);
|
17
|
+
}
|
18
|
+
|
19
|
+
@JRubyMethod(name = "blank_as?")
|
20
|
+
public static IRubyObject blank_as_p(ThreadContext context, IRubyObject self) {
|
21
|
+
RubyString str = (RubyString) self;
|
22
|
+
if (str.size() == 0) return context.tru;
|
23
|
+
|
24
|
+
Ruby runtime = context.runtime;
|
25
|
+
ByteList sByteList = str.getByteList();
|
26
|
+
byte[] sBytes = sByteList.unsafeBytes();
|
27
|
+
int s = sByteList.begin();
|
28
|
+
int e = s + sByteList.realSize();
|
29
|
+
int[] len = {0};
|
30
|
+
Encoding enc = str.getEncoding();
|
31
|
+
|
32
|
+
while (s < e) {
|
33
|
+
int codepoint = EncodingUtils.encCodepointLength(runtime, sBytes, s, e, len, enc);
|
34
|
+
|
35
|
+
switch (codepoint) {
|
36
|
+
case 9:
|
37
|
+
case 0xa:
|
38
|
+
case 0xb:
|
39
|
+
case 0xc:
|
40
|
+
case 0xd:
|
41
|
+
case 0x20:
|
42
|
+
case 0x85:
|
43
|
+
case 0xa0:
|
44
|
+
case 0x1680:
|
45
|
+
case 0x2000:
|
46
|
+
case 0x2001:
|
47
|
+
case 0x2002:
|
48
|
+
case 0x2003:
|
49
|
+
case 0x2004:
|
50
|
+
case 0x2005:
|
51
|
+
case 0x2006:
|
52
|
+
case 0x2007:
|
53
|
+
case 0x2008:
|
54
|
+
case 0x2009:
|
55
|
+
case 0x200a:
|
56
|
+
case 0x2028:
|
57
|
+
case 0x2029:
|
58
|
+
case 0x202f:
|
59
|
+
case 0x205f:
|
60
|
+
case 0x3000:
|
61
|
+
break;
|
62
|
+
default:
|
63
|
+
return context.fals;
|
64
|
+
}
|
65
|
+
|
66
|
+
s += len[0];
|
67
|
+
}
|
68
|
+
|
69
|
+
return context.tru;
|
70
|
+
}
|
71
|
+
|
72
|
+
@JRubyMethod(name = "blank?")
|
73
|
+
public static IRubyObject blank_p(ThreadContext context, IRubyObject self) {
|
74
|
+
RubyString str = (RubyString) self;
|
75
|
+
if (str.size() == 0) return context.tru;
|
76
|
+
|
77
|
+
ByteList sByteList = str.getByteList();
|
78
|
+
byte[] sBytes = sByteList.unsafeBytes();
|
79
|
+
int s = sByteList.begin();
|
80
|
+
int e = s + sByteList.realSize();
|
81
|
+
|
82
|
+
// Move to slower path if the string contains non 7-bit ASCII.
|
83
|
+
if (str.getCodeRange() != StringSupport.CR_7BIT) return blankSlow(context, sBytes, s, e, str.getEncoding());
|
84
|
+
|
85
|
+
for (int i = s; i < e; i++) {
|
86
|
+
if (!isSpace(sBytes[i])) return context.fals;
|
87
|
+
}
|
88
|
+
|
89
|
+
return context.tru;
|
90
|
+
}
|
91
|
+
|
92
|
+
private static IRubyObject blankSlow(ThreadContext context, byte[] bytes, int s, int e, Encoding enc) {
|
93
|
+
Ruby runtime = context.runtime;
|
94
|
+
int[] len = {0};
|
95
|
+
|
96
|
+
while (s < e) {
|
97
|
+
int codepoint = EncodingUtils.encCodepointLength(runtime, bytes, s, e, len, enc);
|
98
|
+
if (!isSpaceCodepoint(codepoint) && codepoint != 0) return context.fals;
|
99
|
+
|
100
|
+
s += len[0];
|
101
|
+
}
|
102
|
+
|
103
|
+
return context.tru;
|
104
|
+
}
|
105
|
+
|
106
|
+
// MRI: rb_isspace
|
107
|
+
private static boolean isSpaceCodepoint(int codepoint) {
|
108
|
+
long c = codepoint & 0xFFFFFFFF;
|
109
|
+
return c == ' ' || ('\t' <= c && c <= '\r');
|
110
|
+
}
|
111
|
+
|
112
|
+
private static boolean isSpace(byte c) {
|
113
|
+
return c == ' ' || ('\t' <= c && c <= '\r') || c == '\0';
|
114
|
+
}
|
115
|
+
}
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sin_fast_blank
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Masahiro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
Ruby extension library for fast blank string checking.
|
15
|
+
Forked from FastBlank.
|
16
|
+
email:
|
17
|
+
- watanabe@cadenza-tech.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ext/java/sin_fast_blank/SinFastBlankLibrary.java
|
23
|
+
- lib/sin_fast_blank/sin_fast_blank.jar
|
24
|
+
homepage: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.0.0
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata:
|
28
|
+
homepage_uri: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.0.0
|
29
|
+
source_code_uri: https://github.com/cadenza-tech/sin_fast_blank/tree/v2.0.0
|
30
|
+
changelog_uri: https://github.com/cadenza-tech/sin_fast_blank/blob/v2.0.0/CHANGELOG.md
|
31
|
+
bug_tracker_uri: https://github.com/cadenza-tech/sin_fast_blank/issues
|
32
|
+
documentation_uri: https://rubydoc.info/gems/sin_fast_blank/2.0.0
|
33
|
+
funding_uri: https://patreon.com/CadenzaTech
|
34
|
+
rubygems_mfa_required: 'true'
|
35
|
+
required_jruby_version: ">= 9.3.0.0"
|
36
|
+
required_truffleruby_version: ">= 22.0.0"
|
37
|
+
required_truffleruby+graalvm_version: ">= 22.0.0"
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.3.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.2.33
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Ruby extension library for fast blank string checking.
|
57
|
+
test_files: []
|