unbrace 0.5.0 → 0.5.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -1
  3. data/ext/unbrace/unbrace.c +13 -21
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c5f1b2af0a18d498126a5aaec25c2a8310f5f5e527102162d32ddd4b2cce49d
4
- data.tar.gz: 98eed7afd2b05a27ef189d12429e5942e4c9e849dd3692b4c2238b09a520d65d
3
+ metadata.gz: 453a5bdee6a73cb142972d065fa6d2a0f04084452b7ed098c5cad1839f937055
4
+ data.tar.gz: f473892efa7c70ddf5a8bca3e09b79c9bfdbdf388d1587cb0292839af91074cd
5
5
  SHA512:
6
- metadata.gz: d93760f4f5a65918966282cfa755dbe6f5c9ddfc76d9fa2b78b828f4bd6df0585de4ad0ced9bdfbd43b420f6331c49078d8da345f8d1e2bef011bbcd064a6f13
7
- data.tar.gz: 3ac1a167f444665e8f59e0697593bcaa5758b2acaf1d98f811f9ed5284df04072ec0870c1433012c24ac6020a2cc48333fd3eb2e45a7b52e631158f3facdd523
6
+ metadata.gz: b682f2eb9b0d68deb5e6432b23d4ec22f1bb25f35d9b168b5821c3c0cfa9ba539ca08c4755c1ef3f5477f1dbf73e86380d1d0f195e87253bd9438ab1bc2f7640
7
+ data.tar.gz: 9d62693f1d05ccdd6f9ff980f57122ba1d160c9a623e1317750b7d2172d828dfef4b3c8af6b92340c0d4896a16cde256013025482d9bff613ce9041751446a2c
data/README.md CHANGED
@@ -8,7 +8,7 @@ Just call ```String#unbrace``` for any string containing embeded braces to expan
8
8
 
9
9
  ## Example
10
10
 
11
- ```ruby
11
+ ```shell
12
12
  irb> puts "lawyer_{name,{work,home}_email_{active,inactive},state}".unbrace
13
13
  lawyer_name
14
14
  lawyer_work_email_active
@@ -16,6 +16,22 @@ lawyer_work_email_inactive
16
16
  lawyer_home_email_active
17
17
  lawyer_home_email_inactive
18
18
  lawyer_state
19
+
20
+ irb> puts "~/{Downloads,Pictures}/*.{jpg,gif,png}".unbrace
21
+ ~/Downloads/*.jpg
22
+ ~/Downloads/*.gif
23
+ ~/Downloads/*.png
24
+ ~/Pictures/*.jpg
25
+ ~/Pictures/*.gif
26
+ ~/Pictures/*.png
27
+
28
+ irb> puts "It{{em,alic}iz,erat}e{d,}, please.".unbrace
29
+ Itemized, please.
30
+ Itemize, please.
31
+ Italicized, please.
32
+ Italicize, please.
33
+ Iterated, please.
34
+ Iterate, please.
19
35
  ```
20
36
 
21
37
  ## Test
@@ -1,8 +1,8 @@
1
1
  // ============================================================================
2
2
  // Summary: unbrace.c - Offers String#unbrace, which expands braces in strings.
3
- // Version: 0.5.0
3
+ // Version: 0.5.1
4
4
  // Author: Steve Shreeve (steve.shreeve@gmail.com)
5
- // Date: December 16, 2023
5
+ // Date: December 17, 2023
6
6
  // Legal: Same license as Ruby (see http://www.ruby-lang.org/en/LICENSE.txt)
7
7
  // Note: This file is derived from "dir.c" in the Ruby source code.
8
8
  // ============================================================================
@@ -10,59 +10,51 @@
10
10
  #include "ruby/ruby.h"
11
11
  // FIXME: Encoding requires(?) others, such as #include "ruby/encoding.h"
12
12
 
13
- static int
13
+ static void
14
14
  brace_expand(const char *str, VALUE ary) // FIXME: Add ",rb_encoding *enc)" here?
15
15
  {
16
16
  const char *p = str;
17
17
  const char *pend = p + strlen(p);
18
18
  const char *s = p;
19
19
  const char *lbrace = 0, *rbrace = 0;
20
- int nest = 0, status = 0;
20
+ int nest = 0;
21
21
 
22
22
  while (*p) {
23
- if (*p == '{' && nest++ == 0) {
24
- lbrace = p;
25
- }
23
+ if (*p == '\\' && !*++p) break;
24
+ if (*p == '{' && nest++ == 0) lbrace = p;
26
25
  if (*p == '}' && lbrace && --nest == 0) {
27
26
  rbrace = p;
28
27
  break;
29
28
  }
30
- if (*p == '\\' && !*++p) {
31
- break;
32
- }
33
29
  p++; // FIXME: For encoding, use Inc(p, pend, enc) here?
34
30
  }
35
31
 
36
32
  if (lbrace && rbrace) {
33
+ long size = lbrace - s;
37
34
  size_t len = strlen(s) + 1;
38
35
  char *buf = (char *) malloc(len); // FIXME: Use ALLOC_N(...) here?
39
- long shift;
36
+ if (!buf) return;
40
37
 
41
- if (!buf) return -1;
42
- memcpy(buf, s, lbrace - s);
43
- shift = (lbrace - s);
38
+ memcpy(buf, s, size);
44
39
  p = lbrace;
45
40
  while (p < rbrace) {
46
41
  const char *t = ++p;
47
42
  nest = 0;
48
43
  while (p < rbrace && !(*p == ',' && nest == 0)) {
44
+ if (*p == '\\' && (++p == rbrace)) break;
49
45
  if (*p == '{') nest++;
50
46
  if (*p == '}') nest--;
51
- if (*p == '\\' && (++p == rbrace)) break;
52
47
  p++; // FIXME: For encoding, use Inc(p, pend, enc) here?
53
48
  }
54
- memcpy(buf + shift, t, p - t);
55
- strlcpy(buf + shift + (p - t), rbrace + 1, len - (shift + (p - t)));
56
- status = brace_expand(buf, ary);
49
+ memcpy(buf + size, t, p - t);
50
+ strlcpy(buf + size + (p - t), rbrace + 1, len - (size + (p - t)));
51
+ brace_expand(buf, ary);
57
52
  }
58
53
  free(buf); // FIXME: Use GLOB_FREE(buf) here?
59
54
  }
60
55
  else if (!lbrace && !rbrace) {
61
56
  rb_ary_push(ary, rb_str_new_cstr(str));
62
- status = 1;
63
57
  }
64
-
65
- return status;
66
58
  }
67
59
 
68
60
  static VALUE
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unbrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.4.22
88
+ rubygems_version: 3.5.1
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: A Ruby gem that expands braces in strings