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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2036a650644cd3b814d8c74d9a7bc7c4cb647adf51b38a5965b5f0f121144276
4
- data.tar.gz: 4619c1c428626857d1d189cb1a6d64c870cc3a427c1e31ea0fb8f4decb417b88
3
+ metadata.gz: 77b16002a92b4aedc56351a568698fa4032f750b49cbdf1ee4927548a278fe2a
4
+ data.tar.gz: 40b69153c41b6af4182f15769b5dc0eef2b988d4c838d16c3f3a803a6d03cad3
5
5
  SHA512:
6
- metadata.gz: 9fa5d56dbd8bc4372022e3d58b82958bc3561155a8d33c9f9e05ec48f96ef431d1309e4634a11909b31f32609491f8691a3b8ad41f798e7bb584fd5aa3b5c7ac
7
- data.tar.gz: fb58b8aea21cfd8a9ebf24edc693d63397ee7a8f72d175feb8da63a0d0160bb3a4740202e7ce5dd9ba7803d9ad18ebeb38f98e493741d46517c5007f40c8aba9
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
- init_next = 0
167
- while loc = text.index(long, init_next)
168
- # Huristics to check if the surrounding letters are sufficiently distinguished.
169
- if long.length > 3 || ((text[loc - 1, 2] !~ /[a-z][a-z]/) && (text[loc + long.length - 1, 2] !~ /[a-z][a-z]/))
170
- # if true
171
- rpositions << [loc, long.length, 1]
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
- # a workaround to avoid messing-up due to embedding
174
- text[loc, long.length] = one * long.length
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
 
@@ -1,3 +1,3 @@
1
1
  class TextAlignment
2
- VERSION = '0.12.10'
2
+ VERSION = '0.12.11'
3
3
  end
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.10
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-09-30 00:00:00.000000000 Z
11
+ date: 2025-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-dictionary