supplement 2.30 → 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 +77 -18
- 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;
|
|
@@ -395,49 +400,102 @@ rb_str_tail( int argc, VALUE *argv, VALUE str)
|
|
|
395
400
|
}
|
|
396
401
|
|
|
397
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
|
+
|
|
398
425
|
/*
|
|
399
426
|
* call-seq:
|
|
400
427
|
* axe( n = 80) -> str
|
|
401
428
|
*
|
|
402
|
-
* Cut off everthing beyond
|
|
429
|
+
* Cut off everthing beyond the <code>n</code>th character. Replace the
|
|
403
430
|
* last bytes by ellipses.
|
|
404
431
|
*
|
|
405
|
-
* a = "
|
|
406
|
-
* 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..."
|
|
407
434
|
*/
|
|
408
435
|
|
|
409
436
|
VALUE
|
|
410
437
|
rb_str_axe( int argc, VALUE *argv, VALUE str)
|
|
411
438
|
{
|
|
412
|
-
VALUE n;
|
|
413
439
|
VALUE ret;
|
|
414
440
|
long newlen, oldlen;
|
|
415
441
|
|
|
416
|
-
|
|
417
|
-
newlen = NUM2LONG( n);
|
|
418
|
-
else
|
|
419
|
-
newlen = 80;
|
|
442
|
+
newlen = supplement_args_len_default( argc, argv);
|
|
420
443
|
if (newlen < 0)
|
|
421
444
|
return Qnil;
|
|
422
445
|
|
|
423
446
|
oldlen = rb_str_strlen( str);
|
|
424
447
|
if (newlen < oldlen) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
e = rb_str_strlen( ell);
|
|
430
|
-
if (newlen > e) {
|
|
431
|
-
ret = rb_str_substr( str, 0, newlen - e);
|
|
432
|
-
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);
|
|
433
452
|
} else
|
|
434
|
-
ret = rb_str_substr(
|
|
453
|
+
ret = rb_str_substr( supplement_ellipse, 0, newlen);
|
|
435
454
|
} else
|
|
436
455
|
ret = str;
|
|
437
456
|
return ret;
|
|
438
457
|
}
|
|
439
458
|
|
|
440
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
|
+
|
|
441
499
|
/*
|
|
442
500
|
* call-seq:
|
|
443
501
|
* starts_with?( *oth) -> nil or int
|
|
@@ -1185,6 +1243,7 @@ void Init_supplement( void)
|
|
|
1185
1243
|
rb_define_method( rb_cString, "rest", rb_str_rest, -1);
|
|
1186
1244
|
rb_define_method( rb_cString, "tail", rb_str_tail, -1);
|
|
1187
1245
|
rb_define_method( rb_cString, "axe", rb_str_axe, -1);
|
|
1246
|
+
rb_define_method( rb_cString, "axe!", rb_str_axe_bang, -1);
|
|
1188
1247
|
rb_define_method( rb_cString, "starts_with?", rb_str_starts_with_p, -1);
|
|
1189
1248
|
rb_define_method( rb_cString, "ends_with?", rb_str_ends_with_p, -1);
|
|
1190
1249
|
rb_define_method( rb_cSymbol, "starts_with?", rb_sym_starts_with_p, -1);
|
|
@@ -1206,7 +1265,7 @@ void Init_supplement( void)
|
|
|
1206
1265
|
|
|
1207
1266
|
rb_define_method( rb_cHash, "notempty?", rb_hash_notempty_p, 0);
|
|
1208
1267
|
|
|
1209
|
-
rb_undef_method(
|
|
1268
|
+
rb_undef_method( CLASS_OF( rb_cFile), "umask");
|
|
1210
1269
|
rb_define_singleton_method( rb_cFile, "umask", rb_file_s_umask, -1);
|
|
1211
1270
|
|
|
1212
1271
|
rb_define_singleton_method( rb_cDir, "current", rb_dir_s_current, 0);
|
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);
|