supplement 2.30 → 2.31.1

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
  SHA256:
3
- metadata.gz: fd387c214f1666040ad8c1d4844543310d0616449c08cf3b69a3f11cdc83e93a
4
- data.tar.gz: 1b5460d3ecf411e6c7cda40510a8649f8ecd9a42ea405d1284f4b3d57148fa9d
3
+ metadata.gz: dff470072491d922eb1edfa3e305fad6323caa366f83379f10065de3c8ce5a84
4
+ data.tar.gz: a69fc76a288c99a345e583029fac4678ec591aaa6edd50cf896e77a498147cef
5
5
  SHA512:
6
- metadata.gz: 513e9ff98266e00ef2ee11f47961cadb834074a7c7d889708032c14515aaf2db28d95a593d25d6904a66d29f030b4cb9e65219152ae88b6cca9b9a532a60c260
7
- data.tar.gz: c8c0be3cff0f29e4d5476f694d78f44105222b58f8e86ac37977567a6b702efe65bc0b9f2d5a0dbf4288761b348231cea62fe6ce90f00c964dcd73fff2d9180a
6
+ metadata.gz: cabaaa436d3f1e3a7bfae57e47c2df42980e8011a1f2a745be79489bbbdc164e8ef7a89c420369a0128e743618303649b396f045351009c5e3b85cca1e60e740
7
+ data.tar.gz: e5de3d55afe67a240d8efbf35198bed3ca114ef143c1e5a91d221b63ee3c5eea367b76548a250010bcc8eca420cc287f0305f612fb075c746ad267fd3a5ca168
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  # BSD-2-clause license, extended by language use conditions
2
2
 
3
- Copyright (C) 2009-2025, Bertram Scharpf <software@bertram-scharpf.de>.
3
+ Copyright (C) 2009-2026, Bertram Scharpf <software@bertram-scharpf.de>.
4
4
  All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # supplement 2.30 -- Useful Ruby enhancements
1
+ # supplement 2.31.1 -- Useful Ruby enhancements
2
2
 
3
3
  Some simple Ruby extensions.
4
4
 
@@ -48,7 +48,7 @@ one of them to be included into the Ruby standard.
48
48
 
49
49
  ## Copyright
50
50
 
51
- * (C) 2009-2025 Bertram Scharpf <software@bertram-scharpf.de>
51
+ * (C) 2009-2026 Bertram Scharpf <software@bertram-scharpf.de>
52
52
  * License: [BSD-2-Clause+](./LICENSE)
53
53
  * Repository: [ruby-supplement](https://github.com/BertramScharpf/ruby-supplement)
54
54
 
data/lib/supplement.c CHANGED
@@ -11,6 +11,7 @@
11
11
  #include <ruby/re.h>
12
12
 
13
13
 
14
+ static long supplement_args_len_default( int, VALUE *);
14
15
  static void supplement_ary_assure_notempty( VALUE);
15
16
  static VALUE supplement_index_blk( VALUE);
16
17
  static VALUE supplement_index_ref( VALUE, VALUE);
@@ -19,6 +20,8 @@ static VALUE supplement_rindex_ref( VALUE, VALUE);
19
20
  static VALUE supplement_do_unumask( VALUE);
20
21
 
21
22
 
23
+ static const char *supplement_ellipse = "...";
24
+
22
25
  static ID id_delete_at = 0;
23
26
  static ID id_cmp = 0;
24
27
  static ID id_eqq = 0;
@@ -395,49 +398,101 @@ rb_str_tail( int argc, VALUE *argv, VALUE str)
395
398
  }
396
399
 
397
400
 
401
+ long
402
+ supplement_args_len_default( int argc, VALUE *argv)
403
+ {
404
+ VALUE n;
405
+ long r;
406
+
407
+ if (rb_scan_args( argc, argv, "01", &n) == 1 && !NIL_P( n))
408
+ r = NUM2LONG( n);
409
+ else
410
+ r = 80;
411
+ return r;
412
+ }
413
+
398
414
  /*
399
415
  * call-seq:
400
416
  * axe( n = 80) -> str
401
417
  *
402
- * Cut off everthing beyond then <code>n</code>th character. Replace the
418
+ * Cut off everthing beyond the <code>n</code>th character. Replace the
403
419
  * last bytes by ellipses.
404
420
  *
405
- * a = "Redistribution and use in source and binary forms, with or without"
406
- * a.axe( 16) #=> "Redistributio..."
421
+ * a = "Now is the time for all good men to come to the aid of their country etc."
422
+ * a.axe( 16) #=> "Now is the ti..."
407
423
  */
408
424
 
409
425
  VALUE
410
426
  rb_str_axe( int argc, VALUE *argv, VALUE str)
411
427
  {
412
- VALUE n;
413
428
  VALUE ret;
414
429
  long newlen, oldlen;
415
430
 
416
- if (rb_scan_args( argc, argv, "01", &n) == 1 && !NIL_P( n))
417
- newlen = NUM2LONG( n);
418
- else
419
- newlen = 80;
431
+ newlen = supplement_args_len_default( argc, argv);
420
432
  if (newlen < 0)
421
433
  return Qnil;
422
434
 
435
+
423
436
  oldlen = rb_str_strlen( str);
424
437
  if (newlen < oldlen) {
425
438
  VALUE ell;
426
- long e;
439
+ long le;
427
440
 
428
- ell = rb_str_new2( "...");
429
- e = rb_str_strlen( ell);
430
- if (newlen > e) {
431
- ret = rb_str_substr( str, 0, newlen - e);
441
+ ell = rb_str_new2( supplement_ellipse);
442
+ le = rb_str_strlen( ell);
443
+ if (newlen >= le) {
444
+ ret = rb_str_substr( str, 0, newlen - le);
432
445
  rb_str_append( ret, ell);
433
446
  } else
434
- ret = rb_str_substr( str, 0, newlen);
447
+ ret = rb_str_substr( ell, 0, newlen);
435
448
  } else
436
449
  ret = str;
437
450
  return ret;
438
451
  }
439
452
 
440
453
 
454
+ /*
455
+ * call-seq:
456
+ * axe!( n = 80) -> str
457
+ *
458
+ * Cut off everthing beyond the <code>n</code>th character. Replace the
459
+ * last bytes by ellipses.
460
+ *
461
+ * a = "Now is the time for all good men to come to the aid of their country etc."
462
+ * a.axe!( 16) #=> "Now is the ti..."
463
+ * a #=> "Now is the ti..."
464
+ *
465
+ * If nothing was removed, <code>nil</code> is returned.
466
+ */
467
+
468
+ VALUE
469
+ rb_str_axe_bang( int argc, VALUE *argv, VALUE str)
470
+ {
471
+ long newlen, oldlen;
472
+
473
+ newlen = supplement_args_len_default( argc, argv);
474
+ if (newlen < 0)
475
+ return Qnil;
476
+
477
+ rb_str_modify( str);
478
+
479
+ oldlen = rb_str_strlen( str);
480
+ if (newlen < oldlen) {
481
+ VALUE ell;
482
+ long le;
483
+ long re;
484
+
485
+ rb_str_update( str, newlen, oldlen - newlen, rb_str_new( NULL, 0));
486
+ ell = rb_str_new2( supplement_ellipse);
487
+ le = rb_str_strlen( ell);
488
+ re = newlen < le ? newlen : le;
489
+ rb_str_update( str, newlen - re, re, rb_str_substr( ell, 0, re));
490
+ return str;
491
+ } else
492
+ return Qnil;
493
+ }
494
+
495
+
441
496
  /*
442
497
  * call-seq:
443
498
  * starts_with?( *oth) -> nil or int
@@ -1185,6 +1240,7 @@ void Init_supplement( void)
1185
1240
  rb_define_method( rb_cString, "rest", rb_str_rest, -1);
1186
1241
  rb_define_method( rb_cString, "tail", rb_str_tail, -1);
1187
1242
  rb_define_method( rb_cString, "axe", rb_str_axe, -1);
1243
+ rb_define_method( rb_cString, "axe!", rb_str_axe_bang, -1);
1188
1244
  rb_define_method( rb_cString, "starts_with?", rb_str_starts_with_p, -1);
1189
1245
  rb_define_method( rb_cString, "ends_with?", rb_str_ends_with_p, -1);
1190
1246
  rb_define_method( rb_cSymbol, "starts_with?", rb_sym_starts_with_p, -1);
@@ -1206,7 +1262,7 @@ void Init_supplement( void)
1206
1262
 
1207
1263
  rb_define_method( rb_cHash, "notempty?", rb_hash_notempty_p, 0);
1208
1264
 
1209
- rb_undef_method( rb_singleton_class( rb_cFile), "umask");
1265
+ rb_undef_method( CLASS_OF( rb_cFile), "umask");
1210
1266
  rb_define_singleton_method( rb_cFile, "umask", rb_file_s_umask, -1);
1211
1267
 
1212
1268
  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);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supplement
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.30'
4
+ version: 2.31.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf