supplement 2.28 → 2.29
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 +120 -63
- data/lib/supplement.h +4 -2
- 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: 9d98b193bc4d1cc8ede4e690103285660b92acbef10bc2c8c9fbe9774968b55e
|
|
4
|
+
data.tar.gz: ce38aef42ac4a5aceb953eee5090d62b09da647c6badd39eb13fcf6ae75124d7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8a1ca6542111abec4919e6b0fafbc665e88baf3de003ccb696586060b4508f0d8c95c5a85d5b2b2bbab85aad0f2c7132bee0458dd64f799d6825c8f404e6754
|
|
7
|
+
data.tar.gz: 30703341388fdd2895f68879925eef1d4a1e94c22e177470cc7689b5e7a0addd5693bab20969afa8b127e6a137e5794dba323bdf2d1e2824adfe73b813103dc5
|
data/README.md
CHANGED
data/lib/supplement.c
CHANGED
|
@@ -393,10 +393,53 @@ rb_str_tail( int argc, VALUE *argv, VALUE str)
|
|
|
393
393
|
|
|
394
394
|
/*
|
|
395
395
|
* call-seq:
|
|
396
|
-
*
|
|
396
|
+
* axe( n = 80) -> str
|
|
397
397
|
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
398
|
+
* Cut off everthing beyond then <code>n</code>th character. Replace the
|
|
399
|
+
* last bytes by ellipses.
|
|
400
|
+
*
|
|
401
|
+
* a = "Redistribution and use in source and binary forms, with or without"
|
|
402
|
+
* a.axe( 16) #=> "Redistributio..."
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
VALUE
|
|
406
|
+
rb_str_axe( int argc, VALUE *argv, VALUE str)
|
|
407
|
+
{
|
|
408
|
+
VALUE n;
|
|
409
|
+
VALUE ret;
|
|
410
|
+
long newlen, oldlen;
|
|
411
|
+
|
|
412
|
+
if (rb_scan_args( argc, argv, "01", &n) == 1 && !NIL_P( n))
|
|
413
|
+
newlen = NUM2LONG( n);
|
|
414
|
+
else
|
|
415
|
+
newlen = 80;
|
|
416
|
+
if (newlen < 0)
|
|
417
|
+
return Qnil;
|
|
418
|
+
|
|
419
|
+
oldlen = rb_str_strlen( str);
|
|
420
|
+
if (newlen < oldlen) {
|
|
421
|
+
VALUE ell;
|
|
422
|
+
long e;
|
|
423
|
+
|
|
424
|
+
ell = rb_str_new2( "...");
|
|
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);
|
|
429
|
+
} else
|
|
430
|
+
ret = rb_str_substr( str, 0, newlen);
|
|
431
|
+
} else
|
|
432
|
+
ret = str;
|
|
433
|
+
return ret;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
/*
|
|
438
|
+
* call-seq:
|
|
439
|
+
* starts_with?( *oth) -> nil or int
|
|
440
|
+
*
|
|
441
|
+
* Checks whether the head is one of <code>oth</code>. Returns the position
|
|
442
|
+
* where the match ends.
|
|
400
443
|
*
|
|
401
444
|
* "sys-apps".starts_with?( "sys-") #=> 4
|
|
402
445
|
*
|
|
@@ -406,32 +449,39 @@ rb_str_tail( int argc, VALUE *argv, VALUE str)
|
|
|
406
449
|
*/
|
|
407
450
|
|
|
408
451
|
VALUE
|
|
409
|
-
rb_str_starts_with_p( VALUE
|
|
452
|
+
rb_str_starts_with_p( int argc, VALUE *argv, VALUE str)
|
|
410
453
|
{
|
|
411
|
-
|
|
412
|
-
char *s, *o;
|
|
413
|
-
VALUE ost;
|
|
454
|
+
int j;
|
|
414
455
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
456
|
+
for (j = 0; j < argc; j++) {
|
|
457
|
+
long i;
|
|
458
|
+
char *s, *o;
|
|
459
|
+
VALUE ost;
|
|
460
|
+
VALUE oth = argv[ j];
|
|
461
|
+
|
|
462
|
+
ost = rb_string_value( &oth);
|
|
463
|
+
i = RSTRING_LEN( ost);
|
|
464
|
+
if (i > RSTRING_LEN( str))
|
|
423
465
|
return Qnil;
|
|
466
|
+
s = RSTRING_PTR( str);
|
|
467
|
+
o = RSTRING_PTR( ost);
|
|
468
|
+
for (; i; i--, s++, o++) {
|
|
469
|
+
if (*s != *o)
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
if (!i)
|
|
473
|
+
return INT2FIX( rb_str_strlen( ost));
|
|
424
474
|
}
|
|
425
|
-
return
|
|
475
|
+
return Qnil;
|
|
426
476
|
}
|
|
427
477
|
|
|
428
478
|
|
|
429
479
|
/*
|
|
430
480
|
* call-seq:
|
|
431
|
-
* ends_with?( oth) -> nil or int
|
|
481
|
+
* ends_with?( *oth) -> nil or int
|
|
432
482
|
*
|
|
433
|
-
* Checks whether the tail is <code>oth</code>. Returns the position
|
|
434
|
-
* where
|
|
483
|
+
* Checks whether the tail is one of <code>oth</code>. Returns the position
|
|
484
|
+
* where the match starts.
|
|
435
485
|
*
|
|
436
486
|
* "sys-apps".ends_with?( "-apps") #=> 3
|
|
437
487
|
*
|
|
@@ -440,65 +490,70 @@ rb_str_starts_with_p( VALUE str, VALUE oth)
|
|
|
440
490
|
*/
|
|
441
491
|
|
|
442
492
|
VALUE
|
|
443
|
-
rb_str_ends_with_p( VALUE
|
|
493
|
+
rb_str_ends_with_p( int argc, VALUE *argv, VALUE str)
|
|
444
494
|
{
|
|
445
|
-
|
|
446
|
-
char *s, *o;
|
|
447
|
-
VALUE ost;
|
|
495
|
+
int j;
|
|
448
496
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
497
|
+
for (j = 0; j < argc; j++) {
|
|
498
|
+
long i;
|
|
499
|
+
char *s, *o;
|
|
500
|
+
VALUE ost;
|
|
501
|
+
VALUE oth = argv[ j];
|
|
502
|
+
|
|
503
|
+
ost = rb_string_value( &oth);
|
|
504
|
+
i = RSTRING_LEN( ost);
|
|
505
|
+
if (i > RSTRING_LEN( str))
|
|
457
506
|
return Qnil;
|
|
458
|
-
|
|
507
|
+
s = RSTRING_END( str);
|
|
508
|
+
o = RSTRING_END( ost);
|
|
509
|
+
for (; i; i--)
|
|
510
|
+
if (*--s != *--o)
|
|
511
|
+
break;
|
|
512
|
+
if (!i)
|
|
513
|
+
return INT2FIX( rb_str_strlen( str) - rb_str_strlen( ost));
|
|
514
|
+
}
|
|
515
|
+
return Qnil;
|
|
459
516
|
}
|
|
460
517
|
|
|
461
518
|
|
|
462
519
|
/*
|
|
463
520
|
* call-seq:
|
|
464
|
-
*
|
|
521
|
+
* starts_with?( oth) -> nil or int
|
|
465
522
|
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
523
|
+
* Checks whether the head is <code>oth</code>. Returns length of
|
|
524
|
+
* <code>oth</code> when matching.
|
|
468
525
|
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
526
|
+
* :"sys-apps".starts_with?( "sys-") #=> 4
|
|
527
|
+
*
|
|
528
|
+
* Caution! The Ruby 1.9.3 method #start_with? (notice the missing s)
|
|
529
|
+
* just returns +true+ or +false+. Mnemonics: "s" = prepare for
|
|
530
|
+
* <code>#slice</code>.
|
|
471
531
|
*/
|
|
472
532
|
|
|
473
533
|
VALUE
|
|
474
|
-
|
|
534
|
+
rb_sym_starts_with_p( int argc, VALUE *argv, VALUE sym)
|
|
475
535
|
{
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
long newlen, oldlen;
|
|
536
|
+
return rb_str_starts_with_p(argc, argv, rb_sym2str(sym));
|
|
537
|
+
}
|
|
479
538
|
|
|
480
|
-
if (rb_scan_args( argc, argv, "01", &n) == 1 && !NIL_P( n))
|
|
481
|
-
newlen = NUM2LONG( n);
|
|
482
|
-
else
|
|
483
|
-
newlen = 80;
|
|
484
|
-
if (newlen < 0)
|
|
485
|
-
return Qnil;
|
|
486
539
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
540
|
+
/*
|
|
541
|
+
* call-seq:
|
|
542
|
+
* ends_with?( oth) -> nil or int
|
|
543
|
+
*
|
|
544
|
+
* Checks whether the tail is <code>oth</code>. Returns the position
|
|
545
|
+
* where <code>oth</code> starts when matching.
|
|
546
|
+
*
|
|
547
|
+
* :"sys-apps".ends_with?( "-apps") #=> 3
|
|
548
|
+
*
|
|
549
|
+
* Caution! The Ruby 1.9.3 method #start_with? (notice the missing s)
|
|
550
|
+
* just returns +true+ or +false+.
|
|
551
|
+
*/
|
|
491
552
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
rb_str_append( ret, ell);
|
|
497
|
-
} else
|
|
498
|
-
ret = rb_str_substr( str, 0, newlen);
|
|
499
|
-
} else
|
|
500
|
-
ret = str;
|
|
501
|
-
return ret;
|
|
553
|
+
VALUE
|
|
554
|
+
rb_sym_ends_with_p( int argc, VALUE *argv, VALUE sym)
|
|
555
|
+
{
|
|
556
|
+
return rb_str_ends_with_p(argc, argv, rb_sym2str(sym));
|
|
502
557
|
}
|
|
503
558
|
|
|
504
559
|
|
|
@@ -1125,9 +1180,11 @@ void Init_supplement( void)
|
|
|
1125
1180
|
rb_define_method( rb_cString, "head", rb_str_head, -1);
|
|
1126
1181
|
rb_define_method( rb_cString, "rest", rb_str_rest, -1);
|
|
1127
1182
|
rb_define_method( rb_cString, "tail", rb_str_tail, -1);
|
|
1128
|
-
rb_define_method( rb_cString, "starts_with?", rb_str_starts_with_p, 1);
|
|
1129
|
-
rb_define_method( rb_cString, "ends_with?", rb_str_ends_with_p, 1);
|
|
1130
1183
|
rb_define_method( rb_cString, "axe", rb_str_axe, -1);
|
|
1184
|
+
rb_define_method( rb_cString, "starts_with?", rb_str_starts_with_p, -1);
|
|
1185
|
+
rb_define_method( rb_cString, "ends_with?", rb_str_ends_with_p, -1);
|
|
1186
|
+
rb_define_method( rb_cSymbol, "starts_with?", rb_sym_starts_with_p, -1);
|
|
1187
|
+
rb_define_method( rb_cSymbol, "ends_with?", rb_sym_ends_with_p, -1);
|
|
1131
1188
|
|
|
1132
1189
|
rb_define_method( rb_cNumeric, "grammatical", rb_num_grammatical, 2);
|
|
1133
1190
|
rb_define_method( rb_cNumeric, "sqrt", rb_num_sqrt, 0);
|
data/lib/supplement.h
CHANGED
|
@@ -26,9 +26,11 @@ extern VALUE rb_str_cut_bang( VALUE, VALUE);
|
|
|
26
26
|
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
|
-
extern VALUE rb_str_starts_with_p( VALUE, VALUE);
|
|
30
|
-
extern VALUE rb_str_ends_with_p( VALUE, VALUE);
|
|
31
29
|
extern VALUE rb_str_axe( int, VALUE *, VALUE);
|
|
30
|
+
extern VALUE rb_str_starts_with_p( int argc, VALUE *argv, VALUE);
|
|
31
|
+
extern VALUE rb_str_ends_with_p( int argc, VALUE *argv, VALUE);
|
|
32
|
+
extern VALUE rb_sym_starts_with_p( int argc, VALUE *argv, VALUE);
|
|
33
|
+
extern VALUE rb_sym_ends_with_p( int argc, VALUE *argv, VALUE);
|
|
32
34
|
|
|
33
35
|
extern VALUE rb_num_grammatical( VALUE, VALUE, VALUE);
|
|
34
36
|
extern VALUE rb_num_sqrt( VALUE);
|