unbrace 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/ext/unbrace/unbrace.c +13 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 453a5bdee6a73cb142972d065fa6d2a0f04084452b7ed098c5cad1839f937055
|
4
|
+
data.tar.gz: f473892efa7c70ddf5a8bca3e09b79c9bfdbdf388d1587cb0292839af91074cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
```
|
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
|
data/ext/unbrace/unbrace.c
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
// ============================================================================
|
2
2
|
// Summary: unbrace.c - Offers String#unbrace, which expands braces in strings.
|
3
|
-
// Version: 0.5.
|
3
|
+
// Version: 0.5.1
|
4
4
|
// Author: Steve Shreeve (steve.shreeve@gmail.com)
|
5
|
-
// Date: December
|
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
|
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
|
20
|
+
int nest = 0;
|
21
21
|
|
22
22
|
while (*p) {
|
23
|
-
if (*p == '
|
24
|
-
|
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
|
-
|
36
|
+
if (!buf) return;
|
40
37
|
|
41
|
-
|
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 +
|
55
|
-
strlcpy(buf +
|
56
|
-
|
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.
|
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.
|
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
|