supplement 2.29 → 2.31
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/README.md +1 -1
- data/lib/supplement.c +88 -22
- data/lib/supplement.h +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ecb9754ff9168f112f5cc9535bdd6fa1dd1877cb7eb4738757a32854a56c325
|
|
4
|
+
data.tar.gz: 983d0b6c6c91258fd74eb0e6fe31f16124654e730d750a09105fe66873086915
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 31724b42dca923848441e648d91757c58bb212a63d91a3613fbedb760b6894f64d432bfb30de89f95fbba93002b9e316283efab175ef747e162ca174ac25e3c4
|
|
7
|
+
data.tar.gz: 5f9e2ff5d368ea29e22bc2218c22b2261b582a8d81724ae5fb48f841fd1c6d77d3367950a68372a74fd8287a8b51b08ba0c7e7635d5bed296619362103f2f5bb
|
data/README.md
CHANGED
data/lib/supplement.c
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
#include <ruby/re.h>
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
static long supplement_args_len_default( int, VALUE *);
|
|
15
|
+
static void supplement_make_ellipse( void);
|
|
14
16
|
static void supplement_ary_assure_notempty( VALUE);
|
|
15
17
|
static VALUE supplement_index_blk( VALUE);
|
|
16
18
|
static VALUE supplement_index_ref( VALUE, VALUE);
|
|
@@ -19,6 +21,9 @@ static VALUE supplement_rindex_ref( VALUE, VALUE);
|
|
|
19
21
|
static VALUE supplement_do_unumask( VALUE);
|
|
20
22
|
|
|
21
23
|
|
|
24
|
+
static VALUE supplement_ellipse = Qnil;
|
|
25
|
+
static long supplement_len_ell = 0;
|
|
26
|
+
|
|
22
27
|
static ID id_delete_at = 0;
|
|
23
28
|
static ID id_cmp = 0;
|
|
24
29
|
static ID id_eqq = 0;
|
|
@@ -111,8 +116,10 @@ rb_krn_tap_bang( VALUE obj)
|
|
|
111
116
|
* call-seq:
|
|
112
117
|
* with { |x| ... } -> obj
|
|
113
118
|
*
|
|
119
|
+
* Warning. This method will be removed. Use +Kernel#then+ instead.
|
|
120
|
+
*
|
|
114
121
|
* Yields +x+ to the block.
|
|
115
|
-
*
|
|
122
|
+
* The difference to +tap+ is that the block's result will be returned.
|
|
116
123
|
*
|
|
117
124
|
* Use this to narrow your namespace.
|
|
118
125
|
*
|
|
@@ -121,6 +128,8 @@ rb_krn_tap_bang( VALUE obj)
|
|
|
121
128
|
VALUE
|
|
122
129
|
rb_krn_with( VALUE obj)
|
|
123
130
|
{
|
|
131
|
+
rb_category_warning(RB_WARN_CATEGORY_DEPRECATED,
|
|
132
|
+
"Kernel#with will be removed from the supplement gem. Use Kernel#then instead.");
|
|
124
133
|
return rb_yield( obj);
|
|
125
134
|
}
|
|
126
135
|
|
|
@@ -391,49 +400,102 @@ rb_str_tail( int argc, VALUE *argv, VALUE str)
|
|
|
391
400
|
}
|
|
392
401
|
|
|
393
402
|
|
|
403
|
+
long
|
|
404
|
+
supplement_args_len_default( int argc, VALUE *argv)
|
|
405
|
+
{
|
|
406
|
+
VALUE n;
|
|
407
|
+
long r;
|
|
408
|
+
|
|
409
|
+
if (rb_scan_args( argc, argv, "01", &n) == 1 && !NIL_P( n))
|
|
410
|
+
r = NUM2LONG( n);
|
|
411
|
+
else
|
|
412
|
+
r = 80;
|
|
413
|
+
return r;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
void
|
|
417
|
+
supplement_make_ellipse( void)
|
|
418
|
+
{
|
|
419
|
+
if (!NIL_P( supplement_ellipse))
|
|
420
|
+
return;
|
|
421
|
+
supplement_ellipse = rb_str_new2( "...");
|
|
422
|
+
supplement_len_ell = rb_str_strlen( supplement_ellipse);
|
|
423
|
+
}
|
|
424
|
+
|
|
394
425
|
/*
|
|
395
426
|
* call-seq:
|
|
396
427
|
* axe( n = 80) -> str
|
|
397
428
|
*
|
|
398
|
-
* Cut off everthing beyond
|
|
429
|
+
* Cut off everthing beyond the <code>n</code>th character. Replace the
|
|
399
430
|
* last bytes by ellipses.
|
|
400
431
|
*
|
|
401
|
-
* a = "
|
|
402
|
-
* a.axe( 16) #=> "
|
|
432
|
+
* a = "Now is the time for all good men to come to the aid of their country etc."
|
|
433
|
+
* a.axe( 16) #=> "Now is the ti..."
|
|
403
434
|
*/
|
|
404
435
|
|
|
405
436
|
VALUE
|
|
406
437
|
rb_str_axe( int argc, VALUE *argv, VALUE str)
|
|
407
438
|
{
|
|
408
|
-
VALUE n;
|
|
409
439
|
VALUE ret;
|
|
410
440
|
long newlen, oldlen;
|
|
411
441
|
|
|
412
|
-
|
|
413
|
-
newlen = NUM2LONG( n);
|
|
414
|
-
else
|
|
415
|
-
newlen = 80;
|
|
442
|
+
newlen = supplement_args_len_default( argc, argv);
|
|
416
443
|
if (newlen < 0)
|
|
417
444
|
return Qnil;
|
|
418
445
|
|
|
419
446
|
oldlen = rb_str_strlen( str);
|
|
420
447
|
if (newlen < oldlen) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
e = rb_str_strlen( ell);
|
|
426
|
-
if (newlen > e) {
|
|
427
|
-
ret = rb_str_substr( str, 0, newlen - e);
|
|
428
|
-
rb_str_append( ret, ell);
|
|
448
|
+
supplement_make_ellipse();
|
|
449
|
+
if (newlen >= supplement_len_ell) {
|
|
450
|
+
ret = rb_str_substr( str, 0, newlen - supplement_len_ell);
|
|
451
|
+
rb_str_append( ret, supplement_ellipse);
|
|
429
452
|
} else
|
|
430
|
-
ret = rb_str_substr(
|
|
453
|
+
ret = rb_str_substr( supplement_ellipse, 0, newlen);
|
|
431
454
|
} else
|
|
432
455
|
ret = str;
|
|
433
456
|
return ret;
|
|
434
457
|
}
|
|
435
458
|
|
|
436
459
|
|
|
460
|
+
/*
|
|
461
|
+
* call-seq:
|
|
462
|
+
* axe!( n = 80) -> str
|
|
463
|
+
*
|
|
464
|
+
* Cut off everthing beyond the <code>n</code>th character. Replace the
|
|
465
|
+
* last bytes by ellipses.
|
|
466
|
+
*
|
|
467
|
+
* a = "Now is the time for all good men to come to the aid of their country etc."
|
|
468
|
+
* a.axe!( 16) #=> "Now is the ti..."
|
|
469
|
+
* a #=> "Now is the ti..."
|
|
470
|
+
*
|
|
471
|
+
* If nothing was removed, <code>nil</code> is returned.
|
|
472
|
+
*/
|
|
473
|
+
|
|
474
|
+
VALUE
|
|
475
|
+
rb_str_axe_bang( int argc, VALUE *argv, VALUE str)
|
|
476
|
+
{
|
|
477
|
+
long newlen, oldlen;
|
|
478
|
+
|
|
479
|
+
newlen = supplement_args_len_default( argc, argv);
|
|
480
|
+
if (newlen < 0)
|
|
481
|
+
return Qnil;
|
|
482
|
+
|
|
483
|
+
rb_str_modify( str);
|
|
484
|
+
|
|
485
|
+
oldlen = rb_str_strlen( str);
|
|
486
|
+
if (newlen < oldlen) {
|
|
487
|
+
long re;
|
|
488
|
+
|
|
489
|
+
rb_str_update( str, newlen, oldlen - newlen, rb_str_new( NULL, 0));
|
|
490
|
+
supplement_make_ellipse();
|
|
491
|
+
re = newlen < supplement_len_ell ? newlen : supplement_len_ell;
|
|
492
|
+
rb_str_update( str, newlen - re, re, rb_str_substr( supplement_ellipse, 0, re));
|
|
493
|
+
return str;
|
|
494
|
+
} else
|
|
495
|
+
return Qnil;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
|
|
437
499
|
/*
|
|
438
500
|
* call-seq:
|
|
439
501
|
* starts_with?( *oth) -> nil or int
|
|
@@ -443,7 +505,7 @@ rb_str_axe( int argc, VALUE *argv, VALUE str)
|
|
|
443
505
|
*
|
|
444
506
|
* "sys-apps".starts_with?( "sys-") #=> 4
|
|
445
507
|
*
|
|
446
|
-
* Caution! The Ruby 1.9.3 method #start_with? (
|
|
508
|
+
* Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
|
|
447
509
|
* just returns +true+ or +false+. Mnemonics: "s" = prepare for
|
|
448
510
|
* <code>#slice</code>.
|
|
449
511
|
*/
|
|
@@ -485,7 +547,7 @@ rb_str_starts_with_p( int argc, VALUE *argv, VALUE str)
|
|
|
485
547
|
*
|
|
486
548
|
* "sys-apps".ends_with?( "-apps") #=> 3
|
|
487
549
|
*
|
|
488
|
-
* Caution! The Ruby 1.9.3 method #start_with? (
|
|
550
|
+
* Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
|
|
489
551
|
* just returns +true+ or +false+.
|
|
490
552
|
*/
|
|
491
553
|
|
|
@@ -525,7 +587,7 @@ rb_str_ends_with_p( int argc, VALUE *argv, VALUE str)
|
|
|
525
587
|
*
|
|
526
588
|
* :"sys-apps".starts_with?( "sys-") #=> 4
|
|
527
589
|
*
|
|
528
|
-
* Caution! The Ruby 1.9.3 method #start_with? (
|
|
590
|
+
* Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
|
|
529
591
|
* just returns +true+ or +false+. Mnemonics: "s" = prepare for
|
|
530
592
|
* <code>#slice</code>.
|
|
531
593
|
*/
|
|
@@ -546,7 +608,7 @@ rb_sym_starts_with_p( int argc, VALUE *argv, VALUE sym)
|
|
|
546
608
|
*
|
|
547
609
|
* :"sys-apps".ends_with?( "-apps") #=> 3
|
|
548
610
|
*
|
|
549
|
-
* Caution! The Ruby 1.9.3 method #start_with? (
|
|
611
|
+
* Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
|
|
550
612
|
* just returns +true+ or +false+.
|
|
551
613
|
*/
|
|
552
614
|
|
|
@@ -1181,6 +1243,7 @@ void Init_supplement( void)
|
|
|
1181
1243
|
rb_define_method( rb_cString, "rest", rb_str_rest, -1);
|
|
1182
1244
|
rb_define_method( rb_cString, "tail", rb_str_tail, -1);
|
|
1183
1245
|
rb_define_method( rb_cString, "axe", rb_str_axe, -1);
|
|
1246
|
+
rb_define_method( rb_cString, "axe!", rb_str_axe_bang, -1);
|
|
1184
1247
|
rb_define_method( rb_cString, "starts_with?", rb_str_starts_with_p, -1);
|
|
1185
1248
|
rb_define_method( rb_cString, "ends_with?", rb_str_ends_with_p, -1);
|
|
1186
1249
|
rb_define_method( rb_cSymbol, "starts_with?", rb_sym_starts_with_p, -1);
|
|
@@ -1202,12 +1265,15 @@ void Init_supplement( void)
|
|
|
1202
1265
|
|
|
1203
1266
|
rb_define_method( rb_cHash, "notempty?", rb_hash_notempty_p, 0);
|
|
1204
1267
|
|
|
1268
|
+
rb_undef_method( CLASS_OF( rb_cFile), "umask");
|
|
1205
1269
|
rb_define_singleton_method( rb_cFile, "umask", rb_file_s_umask, -1);
|
|
1206
1270
|
|
|
1207
1271
|
rb_define_singleton_method( rb_cDir, "current", rb_dir_s_current, 0);
|
|
1208
1272
|
rb_define_singleton_method( rb_cDir, "mkdir!", rb_dir_s_mkdir_bang, -1);
|
|
1209
1273
|
rb_define_alias( rb_cDir, "entries!", "children");
|
|
1210
1274
|
|
|
1275
|
+
rb_undef_method( rb_cMatch, "begin");
|
|
1276
|
+
rb_undef_method( rb_cMatch, "end");
|
|
1211
1277
|
rb_define_method( rb_cMatch, "begin", rb_match_begin, -1);
|
|
1212
1278
|
rb_define_method( rb_cMatch, "end", rb_match_end, -1);
|
|
1213
1279
|
|
data/lib/supplement.h
CHANGED
|
@@ -27,6 +27,7 @@ extern VALUE rb_str_head( int, VALUE *, VALUE);
|
|
|
27
27
|
extern VALUE rb_str_rest( int, VALUE *, VALUE);
|
|
28
28
|
extern VALUE rb_str_tail( int, VALUE *, VALUE);
|
|
29
29
|
extern VALUE rb_str_axe( int, VALUE *, VALUE);
|
|
30
|
+
extern VALUE rb_str_axe_bang( int, VALUE *, VALUE);
|
|
30
31
|
extern VALUE rb_str_starts_with_p( int argc, VALUE *argv, VALUE);
|
|
31
32
|
extern VALUE rb_str_ends_with_p( int argc, VALUE *argv, VALUE);
|
|
32
33
|
extern VALUE rb_sym_starts_with_p( int argc, VALUE *argv, VALUE);
|