text_alignment 0.12.10 → 0.12.11
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/lib/text_alignment/char_mapping.rb +21 -19
- data/lib/text_alignment/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77b16002a92b4aedc56351a568698fa4032f750b49cbdf1ee4927548a278fe2a
|
4
|
+
data.tar.gz: 40b69153c41b6af4182f15769b5dc0eef2b988d4c838d16c3f3a803a6d03cad3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71d13c5a54db05fba9fd32b6eaa1cd7a714a9bef0b69c83dc9fae240e302a7aa7c06591b26749a6d4206bf25ba83ddf1411d37ee74dffd26b93a782a99926983
|
7
|
+
data.tar.gz: fb67eb1ecc933228ede81ecc2690a577853a9a16d12e17e0b5be696dcc661f1aa39399ff877ad567179a0a1d3d3a07134388d87dfd7a72510b56943c87339fdb
|
@@ -151,29 +151,31 @@ class TextAlignment::CharMapping
|
|
151
151
|
|
152
152
|
def enmap_text(_text, char_mapping, no_ws = false)
|
153
153
|
text = _text.dup
|
154
|
-
|
155
|
-
# To perform the single letter mapping replacement
|
156
|
-
char_mapping.each do |one, long|
|
157
|
-
# text.gsub!(one, long) if long.length == 1
|
158
|
-
text.tr!(one, long) if long.length == 1
|
159
|
-
end
|
160
|
-
|
161
|
-
# To get the replacement positions, (position, old_length, new_length), for char mappings
|
162
154
|
rpositions = []
|
163
|
-
char_mapping.each do |one, long|
|
164
|
-
next if long.length == 1
|
165
155
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
156
|
+
# Skip character mapping if text is pure ASCII (performance optimization)
|
157
|
+
unless text.ascii_only?
|
158
|
+
# To perform the single letter mapping replacement
|
159
|
+
char_mapping.each do |one, long|
|
160
|
+
text.gsub!(one, long) if long.length == 1
|
161
|
+
end
|
172
162
|
|
173
|
-
|
174
|
-
|
163
|
+
# To get the replacement positions, (position, old_length, new_length), for char mappings
|
164
|
+
char_mapping.each do |one, long|
|
165
|
+
next if long.length == 1
|
166
|
+
|
167
|
+
init_next = 0
|
168
|
+
while loc = text.index(long, init_next)
|
169
|
+
# Huristics to check if the surrounding letters are sufficiently distinguished.
|
170
|
+
if long.length > 3 || ((text[loc - 1, 2] !~ /[a-z][a-z]/) && (text[loc + long.length - 1, 2] !~ /[a-z][a-z]/))
|
171
|
+
# if true
|
172
|
+
rpositions << [loc, long.length, 1]
|
173
|
+
|
174
|
+
# a workaround to avoid messing-up due to embedding
|
175
|
+
text[loc, long.length] = one * long.length
|
176
|
+
end
|
177
|
+
init_next = loc + long.length
|
175
178
|
end
|
176
|
-
init_next = loc + long.length
|
177
179
|
end
|
178
180
|
end
|
179
181
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_alignment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jin-Dong Kim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-dictionary
|