gstring 1.0.0 → 2.0.0
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/gstring.rb +121 -54
- data/lib/gstring/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e9da314e0abc57b70a58a172be26423fe6b4b1a
|
4
|
+
data.tar.gz: 0eabf0124b7374e799d3d276c8b0e5241f48c8ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 728c13f93ae7a071a02e47e14d7943a685b2ab36fc0ba336c62082272d381adeaa75cb4ff2bafe99806fb10ad16b6956773e68ac217ca5f08ef5cf088c15d41a
|
7
|
+
data.tar.gz: 976b6ef79f3e6fd6a6bda88cf8add2896d6efd671caa36eb4fc17e49f59aa659e6264a80181b4f7a7a0ba3e98bc4e851ec506a7fdaf97723e7c7bde31be0ed01
|
data/lib/gstring.rb
CHANGED
@@ -129,6 +129,44 @@ class String
|
|
129
129
|
rtn = "\\u" + num.to_s(16).padto(8,'0',:left)
|
130
130
|
end
|
131
131
|
end
|
132
|
+
|
133
|
+
SET_SUP_CHARS = (SET_CHARS | SET_INT_CHARS | "+-=()βγδεθινΦφχ") - "qCFQSXYZC"
|
134
|
+
SET_SUB_CHARS = "aeijoruvx" | SET_INT_CHARS | "βγρφχ()+-="
|
135
|
+
|
136
|
+
@@gs_sup_hash = {'β'=>'ᵝ', 'γ'=>'ᵞ', 'δ'=>'ᵟ', 'ε'=>'ᵋ', 'θ'=>'ᶿ', 'ι'=>'ᶥ', 'ν'=>'ᶹ', 'Φ'=>'ᶲ', 'φ'=>'ᵠ', 'χ'=>'ᵡ',
|
137
|
+
'1'=>'¹','2'=>'²','3'=>'³','0'=>'⁰','-'=>'⁻','+'=>'⁺', '='=>'⁼', '('=>'⁽', ')'=>'⁾',
|
138
|
+
'A'=>'ᴬ','B'=>'ᴮ','D'=>'ᴰ','E'=>'ᴱ','G'=>'ᴳ','H'=>'ᴴ','I'=>'ᴵ','J'=>'ᴶ','K'=>'ᴷ',
|
139
|
+
'L'=>'ᴸ','M'=>'ᴹ','N'=>'ᴺ','O'=>'ᴼ','P'=>'ᴾ','R'=>'ᴿ','T'=>'ᵀ','U'=>'ᵁ','V'=>'ⱽ','W'=>'ᵂ',
|
140
|
+
'a'=>'ᵃ','b'=>'ᵇ','c'=>'ᶜ','d'=>'ᵈ','e'=>'ᵉ','f'=>'ᶠ','g'=>'ᵍ','h'=>'ʰ',
|
141
|
+
'i'=>'ⁱ','j'=>'ʲ','k'=>'ᵏ','l'=>'ˡ','m'=>'ᵐ','n'=>'ⁿ','o'=>'ᵒ','p'=>'ᵖ','r'=>'ʳ',
|
142
|
+
's'=>'ˢ','t'=>'ᵗ','u'=>'ᵘ','v'=>'ᵛ','w'=>'ʷ','x'=>'ˣ','y'=>'ʸ','z'=>'ᶻ'}
|
143
|
+
|
144
|
+
@@gs_sub_hash = {'a'=>'ₐ', 'e'=>'ₑ','i'=>'ᵢ','j'=>'ⱼ','o'=>'ₒ','r'=>'ᵣ','u'=>'ᵤ','v'=>'ᵥ',
|
145
|
+
'x'=>'ₓ','β'=>'ᵦ','γ'=>'ᵧ','ρ'=>'ᵨ','φ'=>'ᵩ','χ'=>'ᵪ','='=>'₌','('=>'₍',')'=>'₎','+'=>'₊','-'=>'₋'}
|
146
|
+
(4..9).each do |i|
|
147
|
+
@@gs_sup_hash[(48+i).chr] = (0x2070+i).chr(Encoding::UTF_8)
|
148
|
+
end
|
149
|
+
(0..9).each do |i|
|
150
|
+
@@gs_sub_hash[(48+i).chr] = (0x2080+i).chr(Encoding::UTF_8)
|
151
|
+
end
|
152
|
+
|
153
|
+
def to_superscript(html=false)
|
154
|
+
return '<sup>' + self + '</sup>' if html
|
155
|
+
rtn = ""
|
156
|
+
each_char do |ch|
|
157
|
+
rtn += String::SET_SUP_CHARS.include?(ch) ? @@gs_sup_hash[ch] : ch
|
158
|
+
end
|
159
|
+
return rtn
|
160
|
+
end
|
161
|
+
|
162
|
+
def to_subscript(html=false)
|
163
|
+
return '<sub>' + self + '</sub>' if html
|
164
|
+
rtn = ""
|
165
|
+
each_char do |ch|
|
166
|
+
rtn += String::SET_SUB_CHARS.include?(ch) ? @@gs_sub_hash[ch] : ch
|
167
|
+
end
|
168
|
+
return rtn
|
169
|
+
end
|
132
170
|
|
133
171
|
def upcase?
|
134
172
|
set = self.to_set
|
@@ -193,7 +231,7 @@ class String
|
|
193
231
|
pos = 0
|
194
232
|
ary = []
|
195
233
|
loop do
|
196
|
-
pos = self.index(obj, pos, modes)
|
234
|
+
pos = self.index(obj, pos, *modes)
|
197
235
|
break if pos.nil?
|
198
236
|
ary.push pos
|
199
237
|
pos +=1
|
@@ -201,6 +239,30 @@ class String
|
|
201
239
|
return ary
|
202
240
|
end
|
203
241
|
|
242
|
+
def find_nth(obj, nth, *modes)
|
243
|
+
return nil if 0==nth
|
244
|
+
if nth > 0
|
245
|
+
pos = 0
|
246
|
+
loop do
|
247
|
+
nth -= 1
|
248
|
+
pos = self.index(obj, pos, *modes)
|
249
|
+
return nil if pos.nil?
|
250
|
+
return pos if nth.zero?
|
251
|
+
pos += 1
|
252
|
+
end
|
253
|
+
else
|
254
|
+
nth = -nth
|
255
|
+
pos = length
|
256
|
+
loop do
|
257
|
+
nth -= 1
|
258
|
+
pos = self.rindex(obj, pos, *modes)
|
259
|
+
return nil if pos.nil?
|
260
|
+
return pos if nth.zero?
|
261
|
+
pos -= 1
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
204
266
|
def cryptogram(dat=nil) # nil==> encode, string==>test for match
|
205
267
|
if (dat.nil?)
|
206
268
|
rtn = dup
|
@@ -361,20 +423,27 @@ class String
|
|
361
423
|
pswd.shuffle!
|
362
424
|
return pswd.join ''
|
363
425
|
end
|
364
|
-
|
365
|
-
def remove(prm)
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
426
|
+
|
427
|
+
def remove!(obj, *prm) # remove all characters
|
428
|
+
flags = prm.dup
|
429
|
+
flags |= [:no_skip, :no_strip]
|
430
|
+
rtn = ""
|
431
|
+
str = ""
|
432
|
+
loop do
|
433
|
+
str += parse(obj,flags)
|
434
|
+
break if parsed.nil?
|
435
|
+
rtn += parsed
|
370
436
|
end
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
def remove!(prm) # remove all characters
|
375
|
-
replace remove(prm)
|
437
|
+
str += self
|
438
|
+
replace str
|
439
|
+
return rtn
|
376
440
|
end
|
377
441
|
|
442
|
+
def remove(obj, *prm) # remove all characters
|
443
|
+
str = dup
|
444
|
+
str.remove!(obj, *prm)
|
445
|
+
return str
|
446
|
+
end
|
378
447
|
|
379
448
|
def extract!(prm=1, fill_hole="")
|
380
449
|
return "" if empty?
|
@@ -431,7 +500,7 @@ class String
|
|
431
500
|
filler.extract! str.length # remove and discard
|
432
501
|
end
|
433
502
|
end
|
434
|
-
remove! "\000"
|
503
|
+
remove! "\000".to_set
|
435
504
|
return rtn
|
436
505
|
else # convert to set
|
437
506
|
ary = (prm.to_set & (0..(self.length-1))).to_a #ignore everything out of range
|
@@ -844,12 +913,16 @@ class String
|
|
844
913
|
return dup.inc!(val)
|
845
914
|
end
|
846
915
|
|
847
|
-
def append
|
848
|
-
|
916
|
+
def append(*prms)
|
917
|
+
rtn = ""
|
918
|
+
prms.each do |item|
|
919
|
+
rtn += item.to_s
|
920
|
+
end
|
921
|
+
self + rtn
|
849
922
|
end
|
850
923
|
|
851
|
-
def append(
|
852
|
-
self
|
924
|
+
def append!(*prms)
|
925
|
+
replace self.append(*prms)
|
853
926
|
end
|
854
927
|
|
855
928
|
def zap! # simple alias
|
@@ -1124,10 +1197,21 @@ class String
|
|
1124
1197
|
end
|
1125
1198
|
end
|
1126
1199
|
|
1200
|
+
SET_VERTICLE = "\n\v".to_set
|
1201
|
+
|
1127
1202
|
def limit_to(size, *flags)
|
1203
|
+
size = length + size + 1 if size < 0
|
1204
|
+
if flags.first.kind_of? Integer
|
1205
|
+
flags=flags.dup
|
1206
|
+
cnt=flags.reverse!.pop
|
1207
|
+
pos = find_nth(SET_VERTICLE,cnt,*flags)
|
1208
|
+
if pos && (pos < size)
|
1209
|
+
size = pos + 1
|
1210
|
+
end
|
1211
|
+
end
|
1128
1212
|
return self if length <= size
|
1129
1213
|
if flags.include? :no_break
|
1130
|
-
pos = self.rfind(SET_SPLIT_CHARS)
|
1214
|
+
pos = self.rfind(SET_SPLIT_CHARS,size-1)
|
1131
1215
|
return self[0..(size-2)] + '…' if pos.nil?
|
1132
1216
|
return self[0..(pos-1)] + '…'
|
1133
1217
|
else
|
@@ -1135,6 +1219,10 @@ class String
|
|
1135
1219
|
end
|
1136
1220
|
end
|
1137
1221
|
|
1222
|
+
def limit_to!(size, *flags)
|
1223
|
+
replace limit_to(size, *flags)
|
1224
|
+
end
|
1225
|
+
|
1138
1226
|
def to_eng(pa=6, unit=nil)
|
1139
1227
|
return self.to_f.to_eng(pa, unit)
|
1140
1228
|
end
|
@@ -1183,7 +1271,7 @@ class String
|
|
1183
1271
|
ch = self[rnd.rand(self.length)]
|
1184
1272
|
rtn += ch
|
1185
1273
|
if prms.include? :set
|
1186
|
-
remove! ch
|
1274
|
+
remove! ch.to_set
|
1187
1275
|
else
|
1188
1276
|
self[self.find(ch)] = ""
|
1189
1277
|
end
|
@@ -1191,40 +1279,6 @@ class String
|
|
1191
1279
|
return rtn
|
1192
1280
|
end
|
1193
1281
|
|
1194
|
-
=begin
|
1195
|
-
def rand(cnt=1, unique=true)
|
1196
|
-
return "" if empty?
|
1197
|
-
return "" if cnt < 1
|
1198
|
-
return self if length==1
|
1199
|
-
cnt = cnt >= length ? length : cnt
|
1200
|
-
if unique
|
1201
|
-
sh = shuffle
|
1202
|
-
return sh[0..(cnt-1)]
|
1203
|
-
else
|
1204
|
-
rr = Random.new
|
1205
|
-
rtn = ""
|
1206
|
-
cnt.times do
|
1207
|
-
rtn += self[rr.rand(length)]
|
1208
|
-
end
|
1209
|
-
return rtn
|
1210
|
-
end
|
1211
|
-
end
|
1212
|
-
|
1213
|
-
def rand!(cnt=1)
|
1214
|
-
return "" if empty?
|
1215
|
-
return "" if cnt < 1
|
1216
|
-
return first! if length==1
|
1217
|
-
cnt = cnt >= length ? length : cnt
|
1218
|
-
if length==cnt
|
1219
|
-
rtn = shuffle
|
1220
|
-
zap!
|
1221
|
-
return rtn
|
1222
|
-
end
|
1223
|
-
ary = (0..(length-1)).to_a.shuffle
|
1224
|
-
return extract! ary[0..(cnt-1)] # return is not randomized ... why ???
|
1225
|
-
end
|
1226
|
-
=end
|
1227
|
-
|
1228
1282
|
# default char for blank? or new mode
|
1229
1283
|
def access_mode(md=:stop, dflt=' ') # :swing :stick :default :rotate
|
1230
1284
|
@gs_access_mode = md
|
@@ -1332,7 +1386,11 @@ class String
|
|
1332
1386
|
raise "unsupported access mode"
|
1333
1387
|
end
|
1334
1388
|
end
|
1335
|
-
end
|
1389
|
+
end
|
1390
|
+
|
1391
|
+
def uchr
|
1392
|
+
first
|
1393
|
+
end
|
1336
1394
|
|
1337
1395
|
end # String
|
1338
1396
|
|
@@ -1348,6 +1406,15 @@ class Integer
|
|
1348
1406
|
def to_eng(pa=6, unit=nil)
|
1349
1407
|
return self.to_f.to_eng(pa, unit)
|
1350
1408
|
end
|
1409
|
+
def uchr
|
1410
|
+
chr(Encoding::UTF_8)
|
1411
|
+
end
|
1412
|
+
def to_superscript(html=false)
|
1413
|
+
to_s.to_superscript(html)
|
1414
|
+
end
|
1415
|
+
def to_subscript(html=false)
|
1416
|
+
to_s.to_subscript(html)
|
1417
|
+
end
|
1351
1418
|
end
|
1352
1419
|
|
1353
1420
|
class Float
|
data/lib/gstring/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gstring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Colvin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: setfu
|