-294
-295
-296
-297
-298
-299
-300
+275
+276
+277
+278
+279
+280
+281
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 294
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 275
def ljust(idx, padstr = ' ')
raise ArgumentError, 'zero width padding' if padstr == ''
@@ -8433,15 +8715,15 @@
-45
-46
-47
-48
-49
-50
+26
+27
+28
+29
+30
+31
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 45
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 26
def lstrip
a = 0
@@ -8502,14 +8784,14 @@
-97
-98
-99
-100
-101
+78
+79
+80
+81
+82
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 97
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 78
def lstrip!
raise FrozenError, "can't modify frozen String" if frozen?
@@ -8548,6 +8830,7 @@
+253
254
255
256
@@ -8558,14 +8841,13 @@
261
262
263
-264
-265
+264
|
- # File 'mrblib/string.rb', line 254
+ # File 'mrblib/string.rb', line 253
def match(re, &block)
- if re.respond_to? :to_str
+ if String === re
if Object.const_defined?(:Regexp)
r = Regexp.new(re)
r.match(self, &block)
@@ -8596,14 +8878,14 @@
-244
-245
-246
-247
-248
+830
+831
+832
+833
+834
|
- # File 'mrbgems/mruby-string-ext/src/string.c', line 244
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 830
static mrb_value
mrb_str_oct(mrb_state *mrb, mrb_value self)
@@ -8630,16 +8912,16 @@
-518
-519
-520
-521
-522
-523
-524
+1050
+1051
+1052
+1053
+1054
+1055
+1056
|
- # File 'mrbgems/mruby-string-ext/src/string.c', line 518
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 1050
static mrb_value
mrb_str_ord(mrb_state* mrb, mrb_value str)
@@ -8693,19 +8975,19 @@
-163
-164
-165
-166
-167
-168
-169
-170
-171
-172
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 163
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 144
def partition(sep)
raise TypeError, "type mismatch: #{sep.class} given" unless sep.is_a? String
@@ -8756,13 +9038,13 @@
-364
-365
-366
-367
+345
+346
+347
+348
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 364
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 345
def prepend(arg)
self[0, 0] = arg
@@ -8828,17 +9110,17 @@
-1614
-1615
-1616
-1617
-1618
-1619
-1620
-1621
+1602
+1603
+1604
+1605
+1606
+1607
+1608
+1609
|
- # File 'src/string.c', line 1614
+ # File 'src/string.c', line 1602
static mrb_value
mrb_str_replace(mrb_state *mrb, mrb_value str)
@@ -8909,16 +9191,16 @@
-1795
-1796
-1797
-1798
-1799
-1800
-1801
+1771
+1772
+1773
+1774
+1775
+1776
+1777
|
- # File 'src/string.c', line 1795
+ # File 'src/string.c', line 1771
static mrb_value
mrb_str_reverse(mrb_state *mrb, mrb_value str)
@@ -8986,6 +9268,30 @@
+1709
+1710
+1711
+1712
+1713
+1714
+1715
+1716
+1717
+1718
+1719
+1720
+1721
+1722
+1723
+1724
+1725
+1726
+1727
+1728
+1729
+1730
+1731
+1732
1733
1734
1735
@@ -9012,34 +9318,10 @@
1756
1757
1758
-1759
-1760
-1761
-1762
-1763
-1764
-1765
-1766
-1767
-1768
-1769
-1770
-1771
-1772
-1773
-1774
-1775
-1776
-1777
-1778
-1779
-1780
-1781
-1782
-1783
+1759
|
- # File 'src/string.c', line 1733
+ # File 'src/string.c', line 1709
static mrb_value
mrb_str_reverse_bang(mrb_state *mrb, mrb_value str)
@@ -9238,6 +9520,30 @@
+1798
+1799
+1800
+1801
+1802
+1803
+1804
+1805
+1806
+1807
+1808
+1809
+1810
+1811
+1812
+1813
+1814
+1815
+1816
+1817
+1818
+1819
+1820
+1821
1822
1823
1824
@@ -9266,34 +9572,10 @@
1847
1848
1849
-1850
-1851
-1852
-1853
-1854
-1855
-1856
-1857
-1858
-1859
-1860
-1861
-1862
-1863
-1864
-1865
-1866
-1867
-1868
-1869
-1870
-1871
-1872
-1873
-1874
- |
-
- # File 'src/string.c', line 1822
+1850
+ |
+
+ # File 'src/string.c', line 1798
static mrb_value
mrb_str_rindex(mrb_state *mrb, mrb_value str)
@@ -9403,16 +9685,16 @@
-313
-314
-315
-316
-317
-318
-319
+294
+295
+296
+297
+298
+299
+300
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 313
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 294
def rjust(idx, padstr = ' ')
raise ArgumentError, 'zero width padding' if padstr == ''
@@ -9466,19 +9748,19 @@
-174
-175
-176
-177
-178
-179
-180
-181
-182
-183
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 174
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 155
def rpartition(sep)
raise TypeError, "type mismatch: #{sep.class} given" unless sep.is_a? String
@@ -9529,15 +9811,15 @@
-62
-63
-64
-65
-66
-67
+43
+44
+45
+46
+47
+48
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 62
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 43
def rstrip
a = 0
@@ -9582,7 +9864,7 @@
- (RuntimeError)
+ (FrozenError)
@@ -9598,17 +9880,17 @@
-114
-115
-116
-117
-118
+95
+96
+97
+98
+99
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 114
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 95
def rstrip!
- raise RuntimeError, "can't modify frozen String" if frozen?
+ raise FrozenError, "can't modify frozen String" if frozen?
s = self.rstrip
(s == self) ? nil : self.replace(s)
end
@@ -9785,15 +10067,15 @@
-799
-800
-801
-802
-803
-804
+794
+795
+796
+797
+798
+799
|
- # File 'src/string.c', line 799
+ # File 'src/string.c', line 794
static mrb_value
mrb_str_size(mrb_state *mrb, mrb_value self)
@@ -10191,6 +10473,16 @@
+1120
+1121
+1122
+1123
+1124
+1125
+1126
+1127
+1128
+1129
1130
1131
1132
@@ -10199,20 +10491,10 @@
1135
1136
1137
-1138
-1139
-1140
-1141
-1142
-1143
-1144
-1145
-1146
-1147
-1148
+1138
|
- # File 'src/string.c', line 1130
+ # File 'src/string.c', line 1120
static mrb_value
mrb_str_aref_m(mrb_state *mrb, mrb_value str)
@@ -10291,6 +10573,25 @@
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
201
202
203
@@ -10326,29 +10627,10 @@
233
234
235
-236
-237
-238
-239
-240
-241
-242
-243
-244
-245
-246
-247
-248
-249
-250
-251
-252
-253
-254
-255
+236
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 201
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 182
def slice!(arg1, arg2=nil)
raise FrozenError, "can't modify frozen String" if frozen?
@@ -10496,6 +10778,30 @@
+1893
+1894
+1895
+1896
+1897
+1898
+1899
+1900
+1901
+1902
+1903
+1904
+1905
+1906
+1907
+1908
+1909
+1910
+1911
+1912
+1913
+1914
+1915
+1916
1917
1918
1919
@@ -10586,34 +10892,10 @@
2004
2005
2006
-2007
-2008
-2009
-2010
-2011
-2012
-2013
-2014
-2015
-2016
-2017
-2018
-2019
-2020
-2021
-2022
-2023
-2024
-2025
-2026
-2027
-2028
-2029
-2030
-2031
- |
-
- # File 'src/string.c', line 1917
+2007
+ |
+
+ # File 'src/string.c', line 1893
static mrb_value
mrb_str_split_m(mrb_state *mrb, mrb_value str)
@@ -10736,9 +11018,9 @@
-
+
- #start_with?([prefixes]) ⇒ Boolean
+ #squeeze([other_str]) ⇒ String
@@ -10746,14 +11028,15 @@
- Returns true if +str+ starts with one of the +prefixes+ given.
+ Builds a set of characters from the other_str
+parameter(s) using the procedure described for String#count. Returns a
+new string where runs of the same character that occur in this set are
+replaced by a single character. If no arguments are given, all runs of
+identical characters are replaced by a single character.
- “hello”.start_with?(“hell”) #=> true
-
- # returns true if one of the prefixes matches.
- “hello”.start_with?(“heaven”, “hell”) #=> true
- “hello”.start_with?(“heaven”, “paradise”) #=> false
- “h”.start_with?(“heaven”, “hell”) #=> false
+ “yellow moon”.squeeze #=> “yelow mon”
+ “ now is the”.squeeze(“ “) #=> “ now is the”
+ “putters shoot balls”.squeeze(“m-z”) #=> “puters shot balls”
@@ -10775,7 +11058,7 @@
- (Boolean)
+ (String)
@@ -10787,6 +11070,166 @@
+
+
+
+
+
+
+
+
+
+702
+703
+704
+705
+706
+707
+708
+709
+710
+711
+712
+ |
+
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 702
+
+static mrb_value
+mrb_str_squeeze(mrb_state *mrb, mrb_value str)
+{
+ mrb_value pat = mrb_nil_value();
+ mrb_value dup;
+
+ mrb_get_args(mrb, "|S", &pat);
+ dup = mrb_str_dup(mrb, str);
+ str_squeeze(mrb, dup, pat);
+ return dup;
+}
+ |
+
+
+
+
+
+
+
+ #squeeze!([other_str]) ⇒ String?
+
+
+
+
+
+
+
+ Squeezes str in place, returning either str, or nil if no
+changes were made.
+
+
+
+
+
+
+
+
+
+
+
+
+721
+722
+723
+724
+725
+726
+727
+728
+729
+730
+731
+ |
+
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 721
+
+static mrb_value
+mrb_str_squeeze_bang(mrb_state *mrb, mrb_value str)
+{
+ mrb_value pat = mrb_nil_value();
+
+ mrb_get_args(mrb, "|S", &pat);
+ if (str_squeeze(mrb, str, pat)) {
+ return str;
+ }
+ return mrb_nil_value();
+}
+ |
+
+
+
+
+
+
+
+ #start_with?([prefixes]) ⇒ Boolean
+
+
+
+
+
+
+
+ Returns true if +str+ starts with one of the +prefixes+ given.
+
+ “hello”.start_with?(“hell”) #=> true
+
+ # returns true if one of the prefixes matches.
+ “hello”.start_with?(“heaven”, “hell”) #=> true
+ “hello”.start_with?(“heaven”, “paradise”) #=> false
+ “h”.start_with?(“heaven”, “hell”) #=> false
+
+
+
+
+
@@ -10845,7 +11293,7 @@
for (i = 0; i < argc; i++) {
size_t len_l, len_r;
int ai = mrb_gc_arena_save(mrb);
- sub = mrb_string_type(mrb, argv[i]);
+ sub = mrb_ensure_string_type(mrb, argv[i]);
mrb_gc_arena_restore(mrb, ai);
len_l = RSTRING_LEN(self);
len_r = RSTRING_LEN(sub);
@@ -10895,16 +11343,16 @@
-78
-79
-80
-81
-82
-83
-84
+59
+60
+61
+62
+63
+64
+65
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 78
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 59
def strip
a = 0
@@ -10962,14 +11410,14 @@
-127
-128
-129
-130
-131
+108
+109
+110
+111
+112
|
- # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 127
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 108
def strip!
raise FrozenError, "can't modify frozen String" if frozen?
@@ -11050,12 +11498,12 @@
end
pattern, replace = *args
- pattern = pattern.to_str
+ pattern.__to_str
if args.length == 2 && block
block = nil
end
unless block
- replace = replace.to_str
+ replace.__to_str
end
result = []
this = dup
@@ -11134,7 +11582,7 @@
def sub!(*args, &block)
raise FrozenError, "can't modify frozen String" if frozen?
str = self.sub(*args, &block)
- return nil if str == self
+ return nil unless self.index(args[0])
self.replace(str)
end
|
@@ -11157,18 +11605,18 @@
-451
-452
-453
-454
-455
-456
-457
-458
-459
+983
+984
+985
+986
+987
+988
+989
+990
+991
- # File 'mrbgems/mruby-string-ext/src/string.c', line 451
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 983
static mrb_value
mrb_str_succ(mrb_state *mrb, mrb_value self)
@@ -11241,86 +11689,86 @@
-373
-374
-375
-376
-377
-378
-379
-380
-381
-382
-383
-384
-385
-386
-387
-388
-389
-390
-391
-392
-393
-394
-395
-396
-397
-398
-399
-400
-401
-402
-403
-404
-405
-406
-407
-408
-409
-410
-411
-412
-413
-414
-415
-416
-417
-418
-419
-420
-421
-422
-423
-424
-425
-426
-427
-428
-429
-430
-431
-432
-433
-434
-435
-436
-437
-438
-439
-440
-441
-442
-443
-444
-445
-446
-447
-448
-449
+905
+906
+907
+908
+909
+910
+911
+912
+913
+914
+915
+916
+917
+918
+919
+920
+921
+922
+923
+924
+925
+926
+927
+928
+929
+930
+931
+932
+933
+934
+935
+936
+937
+938
+939
+940
+941
+942
+943
+944
+945
+946
+947
+948
+949
+950
+951
+952
+953
+954
+955
+956
+957
+958
+959
+960
+961
+962
+963
+964
+965
+966
+967
+968
+969
+970
+971
+972
+973
+974
+975
+976
+977
+978
+979
+980
+981
|
- # File 'mrbgems/mruby-string-ext/src/string.c', line 373
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 905
static mrb_value
mrb_str_succ_bang(mrb_state *mrb, mrb_value self)
@@ -11666,14 +12114,14 @@
-2365
-2366
-2367
-2368
-2369
+2344
+2345
+2346
+2347
+2348
|
- # File 'src/string.c', line 2365
+ # File 'src/string.c', line 2344
static mrb_value
mrb_str_to_f(mrb_state *mrb, mrb_value self)
@@ -11753,20 +12201,20 @@
-2254
-2255
-2256
-2257
-2258
-2259
-2260
-2261
-2262
-2263
-2264
+2233
+2234
+2235
+2236
+2237
+2238
+2239
+2240
+2241
+2242
+2243
|
- # File 'src/string.c', line 2254
+ # File 'src/string.c', line 2233
static mrb_value
mrb_str_to_i(mrb_state *mrb, mrb_value self)
@@ -11787,11 +12235,7 @@
|
- # File 'src/string.c', line 2380
+ # File 'src/string.c', line 2358
static mrb_value
mrb_str_to_s(mrb_state *mrb, mrb_value self)
@@ -11910,11 +12314,7 @@
|
- # File 'src/string.c', line 2380
+ # File 'src/string.c', line 2358
static mrb_value
mrb_str_to_s(mrb_state *mrb, mrb_value self)
@@ -12073,14 +12433,14 @@
-1664
-1665
-1666
-1667
-1668
+1652
+1653
+1654
+1655
+1656
|
- # File 'src/string.c', line 1664
+ # File 'src/string.c', line 1652
MRB_API mrb_value
mrb_str_intern(mrb_state *mrb, mrb_value self)
@@ -12093,9 +12453,9 @@
-
+
- #upcase ⇒ String
+ #tr(from_str, to_str) ⇒ String
@@ -12103,11 +12463,37 @@
- Returns a copy of str with all lowercase letters replaced with their
-uppercase counterparts. The operation is locale insensitive—only
-characters ‘a’ to ‘z’ are affected.
+ Returns a copy of str with the characters in from_str replaced by the
+corresponding characters in to_str. If to_str is shorter than from_str,
+it is padded with its last character in order to maintain the
+correspondence.
- “hEllO”.upcase #=> “HELLO”
+ “hello”.tr(‘el’, ‘ip’) #=> “hippo”
+ “hello”.tr(‘aeiou’, ‘’) #=> “hll”
+ “hello”.tr(‘aeiou’, ‘AA’) #=> “hAll*”
+
+ Both strings may use the c1-c2 notation to denote ranges of characters,
+and from_str may start with a ^, which denotes all characters except
+those listed.
+
+ “hello”.tr(‘a-y’, ‘b-z’) #=> “ifmmp”
+ “hello”.tr(‘^aeiou’, ‘’) #=> “e**o”
+
+ The backslash character \ can be used to escape ^ or - and is otherwise
+ignored unless it appears at the end of a range or the end of the
+from_str or to_str:
+
+ “hello^world”.tr(“\^aeiou”, “”) #=> “hll*wrld”
+ “hello-world”.tr(“a\-eo”, “”) #=> “hll*wrld”
+
+ “hello\r\nworld”.tr(“\r”, “”) #=> “hello\nworld”
+ “hello\r\nworld”.tr(“\r”, “”) #=> “hello\r\nwold”
+ “hello\r\nworld”.tr(“\\r”, “”) #=> “hello\nworld”
+
+ “X[’\b’]”.tr(“X\”, “”) #=> “[‘b’]”
+ “X[’\b’]”.tr(“X-\]”, “”) #=> “‘b’”
+
+ Note: conversion is effective only in ASCII region.
@@ -12150,27 +12536,31 @@
-2430
-2431
-2432
-2433
-2434
-2435
-2436
-2437
-2438
+566
+567
+568
+569
+570
+571
+572
+573
+574
+575
+576
|
- # File 'src/string.c', line 2430
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 566
static mrb_value
-mrb_str_upcase(mrb_state *mrb, mrb_value self)
+mrb_str_tr(mrb_state *mrb, mrb_value str)
{
- mrb_value str;
+ mrb_value dup;
+ mrb_value p1, p2;
- str = mrb_str_dup(mrb, self);
- mrb_str_upcase_bang(mrb, str);
- return str;
+ mrb_get_args(mrb, "SS", &p1, &p2);
+ dup = mrb_str_dup(mrb, str);
+ str_tr(mrb, dup, p1, p2, FALSE);
+ return dup;
}
|
@@ -12178,9 +12568,9 @@
-
+
- #upcase! ⇒ String?
+ #tr!(from_str, to_str) ⇒ String?
@@ -12188,8 +12578,8 @@
- Upcases the contents of str, returning nil if no changes
-were made.
+ Translates str in place, using the same rules as String#tr.
+Returns str, or nil if no changes were made.
@@ -12232,50 +12622,30 @@
-2397
-2398
-2399
-2400
-2401
-2402
-2403
-2404
-2405
-2406
-2407
-2408
-2409
-2410
-2411
-2412
-2413
-2414
-2415
-2416
-2417
+585
+586
+587
+588
+589
+590
+591
+592
+593
+594
+595
- # File 'src/string.c', line 2397
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 585
static mrb_value
-mrb_str_upcase_bang(mrb_state *mrb, mrb_value str)
+mrb_str_tr_bang(mrb_state *mrb, mrb_value str)
{
- struct RString *s = mrb_str_ptr(str);
- char *p, *pend;
- mrb_bool modify = FALSE;
+ mrb_value p1, p2;
- mrb_str_modify(mrb, s);
- p = RSTRING_PTR(str);
- pend = RSTRING_END(str);
- while (p < pend) {
- if (ISLOWER(*p)) {
- *p = TOUPPER(*p);
- modify = TRUE;
- }
- p++;
+ mrb_get_args(mrb, "SS", &p1, &p2);
+ if (str_tr(mrb, str, p1, p2, FALSE)) {
+ return str;
}
-
- if (modify) return str;
return mrb_nil_value();
}
|
@@ -12284,13 +12654,9 @@
-
+
-
- #upto(other_str, exclusive = false) {|s| ... } ⇒ String
-
- #upto(other_str, exclusive = false) ⇒ Object
-
+ #tr_s(from_str, to_str) ⇒ String
@@ -12298,44 +12664,19 @@
- Iterates through successive values, starting at str and
-ending at other_str inclusive, passing each value in turn to
-the block. The String#succ method is used to generate
-each value. If optional second argument exclusive is omitted or is false,
-the last value will be included; otherwise it will be excluded.
+ Processes a copy of str as described under String#tr, then removes
+duplicate characters in regions that were affected by the translation.
- If no block is given, an enumerator is returned instead.
-
- “a8”.upto(“b6”) {|s| print s, ‘ ‘ }
- for s in “a8”..”b6”
- print s, ‘ ‘
- end
-
- produces:
-
- a8 a9 b0 b1 b2 b3 b4 b5 b6
- a8 a9 b0 b1 b2 b3 b4 b5 b6
-
- If str and other_str contains only ascii numeric characters,
-both are recognized as decimal numbers. In addition, the width of
-string (e.g. leading zeros) is handled appropriately.
-
- “9”.upto(“11”).to_a #=> [“9”, “10”, “11”]
- “25”.upto(“5”).to_a #=> []
- “07”.upto(“11”).to_a #=> [“07”, “08”, “09”, “10”, “11”]
+ “hello”.tr_s(‘l’, ‘r’) #=> “hero”
+ “hello”.tr_s(‘el’, ‘’) #=> “ho”
+ “hello”.tr_s(‘el’, ‘hx’) #=> “hhxo”
+
+
+
+
+
+ #tr_s!(from_str, to_str) ⇒ String?
+
- if (c > e || (excl && c == e)) return beg;
- for (;;) {
- mrb_yield(mrb, block, mrb_str_new(mrb, &c, 1));
- mrb_gc_arena_restore(mrb, ai);
- if (!excl && c == e) break;
- c++;
- if (excl && c == e) break;
- }
- return beg;
- }
- /* both edges are all digits */
- if (ISDIGIT(RSTRING_PTR(beg)[0]) && ISDIGIT(RSTRING_PTR(end)[0]) &&
- all_digits_p(RSTRING_PTR(beg), RSTRING_LEN(beg)) &&
- all_digits_p(RSTRING_PTR(end), RSTRING_LEN(end))) {
- mrb_int min_width = RSTRING_LEN(beg);
- mrb_int bi = mrb_int(mrb, mrb_str_to_inum(mrb, beg, 10, FALSE));
- mrb_int ei = mrb_int(mrb, mrb_str_to_inum(mrb, end, 10, FALSE));
- int ai = mrb_gc_arena_save(mrb);
+
- while (bi <= ei) {
- mrb_value ns, str;
+
+
+
+ Performs String#tr_s processing on str in place, returning
+str, or nil if no changes were made.
- if (excl && bi == ei) break;
- ns = mrb_format(mrb, "%S", mrb_fixnum_value(bi));
- if (min_width > RSTRING_LEN(ns)) {
- str = mrb_str_new(mrb, NULL, min_width);
- memset(RSTRING_PTR(str), '0', min_width-RSTRING_LEN(ns));
- memcpy(RSTRING_PTR(str)+min_width-RSTRING_LEN(ns),
- RSTRING_PTR(ns), RSTRING_LEN(ns));
- }
- else {
- str = ns;
- }
- mrb_yield(mrb, block, str);
- mrb_gc_arena_restore(mrb, ai);
- bi++;
- }
- return beg;
- }
- /* normal case */
- n = mrb_int(mrb, mrb_funcall(mrb, beg, "<=>", 1, end));
- if (n > 0 || (excl && n == 0)) return beg;
+
+
+
+
+
+
+
+
+
+
+627
+628
+629
+630
+631
+632
+633
+634
+635
+636
+637
+ |
+
+ # File 'mrbgems/mruby-string-ext/src/string.c', line 627
+
+static mrb_value
+mrb_str_tr_s_bang(mrb_state *mrb, mrb_value str)
+{
+ mrb_value p1, p2;
+
+ mrb_get_args(mrb, "SS", &p1, &p2);
+ if (str_tr(mrb, str, p1, p2, TRUE)) {
+ return str;
+ }
+ return mrb_nil_value();
}
|
+
+
+
+
+
+ #upcase ⇒ String
+
+
+
+
+
+
+
+ Returns a copy of str with all lowercase letters replaced with their
+uppercase counterparts. The operation is locale insensitive—only
+characters ‘a’ to ‘z’ are affected.
+
+ “hEllO”.upcase #=> “HELLO”
+
+
+
+
+
+
+
+
+
+
+
+
+2408
+2409
+2410
+2411
+2412
+2413
+2414
+2415
+2416
+ |
+
+ # File 'src/string.c', line 2408
+
+static mrb_value
+mrb_str_upcase(mrb_state *mrb, mrb_value self)
+{
+ mrb_value str;
+
+ str = mrb_str_dup(mrb, self);
+ mrb_str_upcase_bang(mrb, str);
+ return str;
+}
+ |
+
+
+
+
+
+
+
+ #upcase! ⇒ String?
+
+
+
+
+
+
+
+ Upcases the contents of str, returning nil if no changes
+were made.
+
+
+
+
+
+
+
+
+
+
+
+
+2375
+2376
+2377
+2378
+2379
+2380
+2381
+2382
+2383
+2384
+2385
+2386
+2387
+2388
+2389
+2390
+2391
+2392
+2393
+2394
+2395
+ |
+
+ # File 'src/string.c', line 2375
+
+static mrb_value
+mrb_str_upcase_bang(mrb_state *mrb, mrb_value str)
+{
+ struct RString *s = mrb_str_ptr(str);
+ char *p, *pend;
+ mrb_bool modify = FALSE;
+
+ mrb_str_modify(mrb, s);
+ p = RSTRING_PTR(str);
+ pend = RSTRING_END(str);
+ while (p < pend) {
+ if (ISLOWER(*p)) {
+ *p = TOUPPER(*p);
+ modify = TRUE;
+ }
+ p++;
+ }
+
+ if (modify) return str;
+ return mrb_nil_value();
+}
+ |
+
+
+
+
+
+
+
+ #upto(max, exclusive = false, &block) ⇒ Object
+
+
+
+
+
+
+
+ call-seq:
+ str.upto(other_str, exclusive=false) {|s| block } -> str
+ str.upto(other_str, exclusive=false) -> an_enumerator
+
+ Iterates through successive values, starting at str and
+ ending at other_str inclusive, passing each value in turn to
+ the block. The String#succ method is used to generate
+ each value. If optional second argument exclusive is omitted or is false,
+ the last value will be included; otherwise it will be excluded.
+
+ If no block is given, an enumerator is returned instead.
+
+ "a8".upto("b6") {|s| print s, ' ' }
+for s in "a8".."b6"
+ print s, ' '
+end
+
+
+ produces:
+
+ a8 a9 b0 b1 b2 b3 b4 b5 b6
+a8 a9 b0 b1 b2 b3 b4 b5 b6
+
+
+ If str and other_str contains only ascii numeric characters,
+ both are recognized as decimal numbers. In addition, the width of
+ string (e.g. leading zeros) is handled appropriately.
+
+ "9".upto("11").to_a #=> ["9", "10", "11"]
+"25".upto("5").to_a #=> []
+"07".upto("11").to_a #=> ["07", "08", "09", "10", "11"]
+
+
+
+
+
+
+
+
+
+
+
+
+
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+ |
+
+ # File 'mrbgems/mruby-string-ext/mrblib/string.rb', line 401
+
+def upto(max, exclusive=false, &block)
+ return to_enum(:upto, max, exclusive) unless block
+ raise TypeError, "no implicit conversion of #{max.class} into String" unless max.kind_of? String
+
+ len = self.length
+ maxlen = max.length
+ # single character
+ if len == 1 and maxlen == 1
+ c = self.ord
+ e = max.ord
+ while c <= e
+ break if exclusive and c == e
+ yield c.chr
+ c += 1
+ end
+ return self
+ end
+ # both edges are all digits
+ bi = self.to_i(10)
+ ei = max.to_i(10)
+ len = self.length
+ if (bi > 0 or bi == "0"*len) and (ei > 0 or ei == "0"*maxlen)
+ while bi <= ei
+ break if exclusive and bi == ei
+ s = bi.to_s
+ s = s.rjust(len, "0") if s.length < len
+ yield s
+ bi += 1
+ end
+ return self
+ end
+ bs = self
+ while true
+ n = (bs <=> max)
+ break if n > 0
+ break if exclusive and n == 0
+ yield bs
+ break if n == 0
+ bs = bs.succ
+ end
+ self
+end
+ |
+
+
@@ -12576,9 +13189,9 @@
diff --git a/docs/api/Struct.html b/docs/api/Struct.html
index 2b4b611..ba3d0e5 100644
--- a/docs/api/Struct.html
+++ b/docs/api/Struct.html
@@ -6,7 +6,7 @@
Class: Struct
- — Documentation by YARD 0.9.12
+ — Documentation by YARD 0.9.19
@@ -209,6 +209,29 @@
+
+
+
+
+
+
+ #dig(idx, *args) ⇒ Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+ call-seq: hsh.dig(key,…) -> object.
+
+
@@ -571,7 +594,6 @@
-354
355
356
357
@@ -579,10 +601,11 @@
359
360
361
-362
+362
+363
|
- # File 'mrbgems/mruby-struct/src/struct.c', line 354
+ # File 'mrbgems/mruby-struct/src/struct.c', line 355
static mrb_value
mrb_struct_initialize(mrb_state *mrb, mrb_value self)
@@ -669,7 +692,6 @@
-558
559
560
561
@@ -696,10 +718,11 @@
582
583
584
-585
+585
+586
|
- # File 'mrbgems/mruby-struct/src/struct.c', line 558
+ # File 'mrbgems/mruby-struct/src/struct.c', line 559
static mrb_value
mrb_struct_equal(mrb_state *mrb, mrb_value s)
@@ -843,7 +866,6 @@
-439
440
441
442
@@ -861,10 +883,11 @@
454
455
456
-457
+457
+458
|
- # File 'mrbgems/mruby-struct/src/struct.c', line 439
+ # File 'mrbgems/mruby-struct/src/struct.c', line 440
static mrb_value
mrb_struct_aref(mrb_state *mrb, mrb_value s)
@@ -1001,7 +1024,6 @@
-503
504
505
506
@@ -1036,10 +1058,11 @@
535
536
537
-538
+538
+539
|
- # File 'mrbgems/mruby-struct/src/struct.c', line 503
+ # File 'mrbgems/mruby-struct/src/struct.c', line 504
static mrb_value
mrb_struct_aset(mrb_state *mrb, mrb_value s)
@@ -1130,6 +1153,63 @@
|
+