gstring 2.0.0 → 3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e9da314e0abc57b70a58a172be26423fe6b4b1a
4
- data.tar.gz: 0eabf0124b7374e799d3d276c8b0e5241f48c8ca
3
+ metadata.gz: ced11932da70666e5f25d7becccc40f3898e28f3
4
+ data.tar.gz: a5c4f7ed36e54aefbb0b84453ffc17bc64727e4d
5
5
  SHA512:
6
- metadata.gz: 728c13f93ae7a071a02e47e14d7943a685b2ab36fc0ba336c62082272d381adeaa75cb4ff2bafe99806fb10ad16b6956773e68ac217ca5f08ef5cf088c15d41a
7
- data.tar.gz: 976b6ef79f3e6fd6a6bda88cf8add2896d6efd671caa36eb4fc17e49f59aa659e6264a80181b4f7a7a0ba3e98bc4e851ec506a7fdaf97723e7c7bde31be0ed01
6
+ metadata.gz: d6bddc4f25b2b37408cec2a975adb7a9a70f7789dd46d9b1994b171fe6644f9efdeb8d6c6d03ec5328a77b68d3e2af1515f55834f7e2b17f10e07ce167977c06
7
+ data.tar.gz: 53a85b0370b2cc4c5d7fd946a303477c4c9485fcb5b5498d531db1e3b48123523bcb7a27ba7e207b58ec9ce0fbf74231bf45195eb9c71f37be6c375cd8e598d0
@@ -23,7 +23,7 @@ Most are from 20 years of multiple language string extensions that were used in
23
23
  spec.require_paths = ["lib"]
24
24
  spec.required_ruby_version = '>= 1.9.1'
25
25
 
26
- spec.add_runtime_dependency 'setfu', '>= 1.2.1'
26
+ spec.add_runtime_dependency 'setfu', '>= 2.0.0'
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.3"
29
29
  spec.add_development_dependency "rake", ">= 10.1.0"
@@ -28,15 +28,15 @@ class String
28
28
  SI_UNIT_PREFIXES = {1=>'da', 2=>'h', 3=>'k', 6=>'M', 9=>'G', 12=>'T', 15=>'P', 18=>'E', 21=>'Z', 24=>'Y', 27=>'kY', 30=>'MY', 33=>'GY', 36=>'TY', 39=>'PY', 42=>'EY', 45=>'ZY', 48=>'YY',
29
29
  -1=>'d',-2=>'c', -3=>'m', -6=>'µ',-9=>'n',-12=>'p',-15=>'f',-18=>'a',-21=>'z',-24=>'y',-27=>'my',-30=>'µy', -33=>'ny', -36=>'py', -39=>'fy', -42=>'ay', -45=>'zy', -48=>'yy'}
30
30
  RGX_FLOAT = /\A[\+\-]?(0|[1-9]\d*)(([eE][\+\-]?\d+)|(\.\d+((e)?[\+\-]?\d+)?))/
31
- STD_ESCAPE_SET_RUBY = [0..31,'"',"'","\\","\;","\#"].to_set
31
+ STD_ESCAPE_SET_RUBY = [0..31,'"',"'","\\","\;","\#"].to_bset
32
32
  STD_ESCAPE_HASH = {7=>"\\a", 8=>"\\b", 12=>"\\f", 10=>"\\n", 13=>"\\r", 9=>"\\t", 11=>"\\v"}
33
- SET_PARSE_CHARS = Set.new.add_parse_chars!
33
+ SET_PARSE_CHARS = BitSet.new.add_parse_chars!
34
34
  SET_SPLIT_CHARS = SET_PARSE_CHARS | "_#`\""
35
- SET_UPPERS = Set.uppercase_chars
36
- SET_LOWERS = Set.lowercase_chars
37
- SET_CHARS = Set.letter_chars
38
- SET_INT_CHARS = Set.digit_chars
39
- GS_SENTENCE_TERM = '?!.'.to_set
35
+ SET_UPPERS = BitSet.uppercase_chars
36
+ SET_LOWERS = BitSet.lowercase_chars
37
+ SET_CHARS = BitSet.letter_chars
38
+ SET_INT_CHARS = BitSet.digit_chars
39
+ GS_SENTENCE_TERM = '?!.'.to_bset
40
40
  GS_TITLE_EXCEPTIONS =
41
41
  {
42
42
  "a" =>true,
@@ -169,21 +169,21 @@ class String
169
169
  end
170
170
 
171
171
  def upcase?
172
- set = self.to_set
172
+ set = self.to_bset
173
173
  return false if String::SET_LOWERS ** set # may not have any lower
174
174
  return nil unless String::SET_UPPERS ** set # must have at least one upper
175
175
  return true
176
176
  end
177
177
 
178
178
  def downcase?
179
- set = self.to_set
179
+ set = self.to_bset
180
180
  return false if String::SET_UPPERS ** set # may not have any lower
181
181
  return nil unless String::SET_LOWERS ** set # must have at least one lower
182
182
  return true
183
183
  end
184
184
 
185
185
  def mixedcase?
186
- set = self.to_set
186
+ set = self.to_bset
187
187
  return nil unless set ** (String::SET_LOWERS | String::SET_UPPERS) # must have a letter
188
188
  return (set ** String::SET_LOWERS) && (set ** String::SET_UPPERS)
189
189
  end
@@ -239,6 +239,12 @@ class String
239
239
  return ary
240
240
  end
241
241
 
242
+ def find_near(pos, obj=String::SET_SPLIT_CHARS, *flags)
243
+ p_r = self.index(obj, pos, *flags)
244
+ p_l = self.rindex(obj, pos, *flags)
245
+ return [p_l,p_r]
246
+ end
247
+
242
248
  def find_nth(obj, nth, *modes)
243
249
  return nil if 0==nth
244
250
  if nth > 0
@@ -266,10 +272,10 @@ class String
266
272
  def cryptogram(dat=nil) # nil==> encode, string==>test for match
267
273
  if (dat.nil?)
268
274
  rtn = dup
269
- set = Set.lowercase_chars
275
+ set = BitSet.lowercase_chars
270
276
  off_limits = []
271
277
  skey = nil
272
- ary = (self.downcase.to_set & String::SET_LOWERS).to_a(false).shuffle
278
+ ary = (self.downcase.to_bset & String::SET_LOWERS).to_a(false).shuffle
273
279
  loop do
274
280
  break if ary.empty?
275
281
  skey = ary.pop
@@ -285,8 +291,8 @@ class String
285
291
  return rtn
286
292
  elsif (dat.class==String)
287
293
  return false if self.length != dat.length
288
- s1 = self.downcase.to_set & Set.lowercase_chars
289
- s2 = dat.downcase.to_set & Set.lowercase_chars
294
+ s1 = self.downcase.to_bset & BitSet.lowercase_chars
295
+ s2 = dat.downcase.to_bset & BitSet.lowercase_chars
290
296
  return false if s1.count != s2.count
291
297
  ary1 = self.downcase.find_all(s1)
292
298
  ary2 = dat.downcase.find_all(s2)
@@ -389,7 +395,7 @@ class String
389
395
  end
390
396
 
391
397
  def duplicates?
392
- set = self.to_set
398
+ set = self.to_bset
393
399
  return false if set.count == length
394
400
  return true
395
401
  end
@@ -405,10 +411,10 @@ class String
405
411
  # generator does not need an instance
406
412
  def self.random_password(chars=8, special="_-#!~@$%^*+=?:")
407
413
  raise "password must be at least 8 characters" if chars < 8
408
- low = Set.lowercase_chars
409
- high = Set.uppercase_chars
410
- digits = Set.digit_chars
411
- special = special.to_set rescue Set.new
414
+ low = BitSet.lowercase_chars
415
+ high = BitSet.uppercase_chars
416
+ digits = BitSet.digit_chars
417
+ special = special.to_bset rescue BitSet.new
412
418
  all = low | high | digits | special
413
419
  a,b = low.rand(2,:array_chars)
414
420
  c,d = high.rand(2, :array_chars)
@@ -500,10 +506,10 @@ class String
500
506
  filler.extract! str.length # remove and discard
501
507
  end
502
508
  end
503
- remove! "\000".to_set
509
+ remove! "\000".to_bset
504
510
  return rtn
505
511
  else # convert to set
506
- ary = (prm.to_set & (0..(self.length-1))).to_a #ignore everything out of range
512
+ ary = (prm.to_bset & (0..(self.length-1))).to_a #ignore everything out of range
507
513
  fill=fill_hole.dup
508
514
  rtn = ""
509
515
  oft = 0
@@ -673,7 +679,7 @@ class String
673
679
  meth = options.include?(:no_strip) ? :ignore_me : :strip
674
680
  rtn=""
675
681
  @found = nil
676
- if(search_key.class==Set)
682
+ if(search_key.class==BitSet)
677
683
  #skip over first char
678
684
  idx = options.include?(:no_skip) ? 0 : 1
679
685
  sk = options.include?(:ignore) ? search_key.add_opposing_case : search_key
@@ -746,7 +752,7 @@ class String
746
752
  return parse(search_key[best],options)
747
753
  end
748
754
  else # we are passed something that should have been converted to a set
749
- return parse([search_key].to_set,options)
755
+ return parse([search_key].to_bset,options)
750
756
  end
751
757
  end
752
758
 
@@ -784,7 +790,7 @@ class String
784
790
  end
785
791
 
786
792
  # call this for unrecognized options
787
- return old_string_index_method_4gstring(search,from) unless search.class == Set
793
+ return old_string_index_method_4gstring(search,from) unless search.class == BitSet
788
794
  if options.include? :ignore
789
795
  return self.downcase.index(search.add_opposing_case,from)
790
796
  end
@@ -822,7 +828,7 @@ class String
822
828
  end
823
829
 
824
830
  # call this for unrecognized options
825
- return old_string_rindex_method_4gstring(search,from) unless search.class == Set
831
+ return old_string_rindex_method_4gstring(search,from) unless search.class == BitSet
826
832
  if options.include? :ignore
827
833
  return self.downcase.rindex(search.add_opposing_case,from)
828
834
  end
@@ -935,7 +941,7 @@ class String
935
941
 
936
942
  def extract_leading_set!(set)
937
943
  rtn = ""
938
- set = set.to_set
944
+ set = set.to_bset
939
945
  while set.include? first do
940
946
  rtn += first!
941
947
  end
@@ -944,7 +950,7 @@ class String
944
950
 
945
951
  def extract_trailing_set!(set)
946
952
  rtn = ""
947
- set = set.to_set
953
+ set = set.to_bset
948
954
  while set.include? last do
949
955
  rtn += last!
950
956
  end
@@ -956,7 +962,7 @@ class String
956
962
  if (set.nil? || set.empty?)
957
963
  set = ' '
958
964
  end
959
- set = set.to_set
965
+ set = set.to_bset
960
966
  prefx = str.extract_leading_set!(set)
961
967
  pstfx = str.extract_trailing_set!(set)
962
968
  dat = []
@@ -1058,7 +1064,7 @@ class String
1058
1064
  # add more as needed later ...
1059
1065
  fa.push :ignore if flags.include? :ignore
1060
1066
  fass = fa + [:no_strip] + [:no_skip]
1061
- cls = [cls] if (Set==cls.class) # push everything into an array even regx
1067
+ cls = [cls] if (BitSet==cls.class) # push everything into an array even regx
1062
1068
  cls = [cls] if (Regexp==cls.class)
1063
1069
  flst = (flags.include? :first) ? {} : nil
1064
1070
 
@@ -1188,7 +1194,7 @@ class String
1188
1194
  def extract_num!
1189
1195
  dat = parse(String::RGX_FLOAT, :no_skip)
1190
1196
  if parsed.nil? # no number found
1191
- num = dat.extract_leading_set!(Set.digit_chars)
1197
+ num = dat.extract_leading_set!(BitSet.digit_chars)
1192
1198
  replace dat
1193
1199
  return 0 if num.empty?
1194
1200
  return num.to_i
@@ -1197,7 +1203,64 @@ class String
1197
1203
  end
1198
1204
  end
1199
1205
 
1200
- SET_VERTICLE = "\n\v".to_set
1206
+ def wrap_to(len, *flags)
1207
+ if (self.length < len)
1208
+ if flags.include? :array
1209
+ return [self.dup]
1210
+ else
1211
+ return self.dup
1212
+ end
1213
+ end
1214
+ ary = []
1215
+ str = self.dup
1216
+ if flags.include? :approximate
1217
+ loop do
1218
+ tar = str.find_near(len)
1219
+ # now for the nasty end points and edge cases
1220
+ if tar.first.nil?
1221
+ if tar.last.nil?
1222
+ ary.push str.extract! len
1223
+ else
1224
+ ary.push str.extract! tar.last + 1
1225
+ end
1226
+ else
1227
+ if tar.last.nil?
1228
+ ary.push str.extract! tar.first + 1
1229
+ else # find closest fit
1230
+ if (len - tar.first) <= (tar.last - len)
1231
+ ary.push str.extract! tar.first + 1
1232
+ else
1233
+ ary.push str.extract! tar.last + 1
1234
+ end
1235
+ end
1236
+ end
1237
+ break if str.length <= len
1238
+ end # loop
1239
+ else
1240
+ loop do
1241
+ tar = str.rindex(String::SET_SPLIT_CHARS, len)
1242
+ if (tar.nil?)
1243
+ ary.push str.extract! len
1244
+ else
1245
+ ary.push str.extract! tar+1
1246
+ end
1247
+ break if str.length <= len
1248
+ end #loop
1249
+ end #if
1250
+ ary.push str
1251
+ ary.length.times { |ii| ary[ii].rstrip! }
1252
+ return ary if flags.include? :array
1253
+ if flags.include? :html
1254
+ str = ary.join '<br />'
1255
+ else
1256
+ str = ary.join "\n"
1257
+ end
1258
+ return str
1259
+ end
1260
+
1261
+
1262
+
1263
+ SET_VERTICLE = "\n\v".to_bset
1201
1264
 
1202
1265
  def limit_to(size, *flags)
1203
1266
  size = length + size + 1 if size < 0
@@ -1248,7 +1311,7 @@ class String
1248
1311
  end
1249
1312
  rnd = Random.new
1250
1313
  rtn = ""
1251
- str = prms.include?(:set) ? self.to_set.to_s : self.dup
1314
+ str = prms.include?(:set) ? self.to_bset.to_s : self.dup
1252
1315
  cnt.times do
1253
1316
  break if str.empty?
1254
1317
  ch = str[rnd.rand(str.length)]
@@ -1271,7 +1334,7 @@ class String
1271
1334
  ch = self[rnd.rand(self.length)]
1272
1335
  rtn += ch
1273
1336
  if prms.include? :set
1274
- remove! ch.to_set
1337
+ remove! ch.to_bset
1275
1338
  else
1276
1339
  self[self.find(ch)] = ""
1277
1340
  end
@@ -1,3 +1,3 @@
1
1
  module Gstring
2
- VERSION = "2.0.0"
2
+ VERSION = "3.0.0"
3
3
  end
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: 2.0.0
4
+ version: 3.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-27 00:00:00.000000000 Z
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: setfu
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.1
19
+ version: 2.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.1
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement