alt_printf 0.1.1 → 0.1.3

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: 163e28af3e2feea3074475a4c2ca580c052b0cc4230aec9d9f0369d3f3104bc2
4
- data.tar.gz: 3b03df1875de9f25671b3c03886ee47f71ee7b22871234295fbab88ce1304733
3
+ metadata.gz: 35403cb6b05ff5261a51180f48e16840860e28e8e49e6ce7f58fc5bd005a280e
4
+ data.tar.gz: fd7fe644f7d76dadc0780f98f6871fe6b08e31dad97ae5e3ef03877753c88bfd
5
5
  SHA512:
6
- metadata.gz: 2e3f110f3be6ab310efbe8024711442b0d35be448ec569ce9ed2eaeee5af95b87ebe47728524174b3de3eb150cf248cf630633cec2d9f0ee7b484e196cef12de
7
- data.tar.gz: afb0850d89c6b05a2404a1c40721ba7b81ba84782ac1ef68c4a29fb4f7ea3b00566a956632c579e6306e62682d80b40a6698eaaa2dc97a832fc24844d76a0baa
6
+ metadata.gz: b408f3e40e812c8d420bf03749a0fd07136a1a8849af5011a855464602163cf7e2bc3a824c0b7565e410c856b0078d8ee01ccee744f65ca8c68b7d425eaa3a83
7
+ data.tar.gz: ea0811bf28ad00219a1218a3c915248526f1b01707bda152a289ddd6c78aa368a06ae073bbeb90dd1dd31c4301cca1f27cb62eefb643e494d096ded65bb6a12c
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ Rake::ExtensionTask.new('alt_printf') do |ext|
10
10
  ext.config_script = 'extconf_dev.rb'
11
11
  end
12
12
 
13
+ desc 'copy necessary C files from ../src and build the resulting gem'
13
14
  task :build_gem do
14
15
  tmp_dir = "/tmp/alt_printf_#{SecureRandom.hex(8)}"
15
16
  puts "cloning to #{tmp_dir}"
@@ -46,6 +47,7 @@ task :build_gem do
46
47
  FileUtils.rm_rf(tmp_dir)
47
48
  end
48
49
 
50
+ desc 'uses build_gem and pushes the resulting gem'
49
51
  task publish: :build_gem do
50
52
  load File.join(__dir__, 'alt_printf.gemspec')
51
53
 
data/alt_printf.gemspec CHANGED
@@ -8,7 +8,7 @@ AltPrintf::SPEC = Gem::Specification.new do |s|
8
8
  s.summary = 'A powerful printf-like template language'
9
9
  s.authors = ['Stone Tickle']
10
10
  s.email = 'lattis@mochiro.moe'
11
- s.homepage = 'https://github.com/annacrombie/alt_printf/gem'
11
+ s.homepage = 'https://github.com/annacrombie/altprintf/gem'
12
12
  s.license = 'MIT'
13
13
 
14
14
  s.files = Dir['{**/*}']
@@ -96,14 +96,26 @@ struct list_elem *rb_altprintf_make_list(const wchar_t *fmt, VALUE *argv, long *
96
96
  use_hash++;
97
97
  }
98
98
 
99
- len = wcsnrtombs(NULL, &fmt, use_hash, 0, NULL);
99
+ LOG("use_hash: %d\n", use_hash);
100
+ len = wcsnrtombs(NULL, &tmp_str, use_hash, 0, NULL);
101
+
100
102
  cstr = calloc(len + 1, sizeof(char));
101
103
  wcsnrtombs(cstr, &tmp_str, use_hash, len, NULL);
102
- LOG("cstr: '%s'\n", cstr);
104
+
105
+ LOG("symbol | cstr: '%s', len %d\n", cstr, len);
103
106
 
104
107
  symbol = rb_check_symbol_cstr(cstr, len, enc);
105
108
  entry = rb_hash_lookup2(*hash, symbol, Qnil);
106
- free(cstr);
109
+
110
+ if (entry == Qnil) {
111
+ rb_raise(
112
+ rb_eKeyError,
113
+ "no such key :%s",
114
+ cstr
115
+ );
116
+ free(cstr);
117
+ }
118
+
107
119
  use_hash = 1;
108
120
 
109
121
  break;
@@ -116,8 +128,19 @@ struct list_elem *rb_altprintf_make_list(const wchar_t *fmt, VALUE *argv, long *
116
128
  tmp_str = rbstowcs(entry);
117
129
  le_cur = list_elem_ini(tmp_str, String);
118
130
  goto match;
119
- case FS_T_MUL:
120
131
  case FS_T_TERN:
132
+ CHECKARG;
133
+ tmp_int = malloc(sizeof(long int));
134
+ if (entry == Qfalse || entry == Qnil) {
135
+ *tmp_int = 0;
136
+ } else {
137
+ *tmp_int = 1;
138
+ }
139
+ LOG("got bool %ld\n", *tmp_int);
140
+ le_cur = list_elem_ini(tmp_int, Int);
141
+
142
+ goto match;
143
+ case FS_T_MUL:
121
144
  case FS_T_ALIGN:
122
145
  case FS_T_INT:
123
146
  CHECKARG;
@@ -173,6 +196,11 @@ VALUE rb_alt_printf(long passes, size_t argc, VALUE *argv, VALUE self) {
173
196
 
174
197
  rb_scan_args(argc, argv, "1*:", &fmt, &args, &hash);
175
198
 
199
+ if (hash == Qnil && RB_TYPE_P(argv[argc - 1], T_HASH)) {
200
+ hash = argv[argc - 1];
201
+ argc--;
202
+ }
203
+
176
204
  if (passes == 0) return fmt;
177
205
 
178
206
  wfmt = rbstowcs(fmt);
@@ -181,6 +209,9 @@ VALUE rb_alt_printf(long passes, size_t argc, VALUE *argv, VALUE self) {
181
209
  while (passes > 0) {
182
210
  ap = rb_altprintf_make_list(wfmt, &args, &argi, &hash);
183
211
 
212
+ //list_elem_inspect_all(ap);
213
+ LOG("wfmt: %ls\n", wfmt);
214
+
184
215
  formatted = altsprintf(wfmt, ap);
185
216
  LOG("formatted result: '%ls'\n", formatted);
186
217
 
@@ -207,7 +238,13 @@ VALUE rb_alt_printf_single_pass(size_t argc, VALUE *argv, VALUE self) {
207
238
  VALUE rb_alt_printf_multi_pass(size_t argc, VALUE *argv, VALUE self) {
208
239
  long passes;
209
240
 
210
- passes = FIX2LONG(argv[0]);
241
+
242
+ if (RB_TYPE_P(argv[0], T_FIXNUM)) {
243
+ passes = FIX2LONG(argv[0]);
244
+ } else {
245
+ rb_raise(rb_eArgError, "integer expected");
246
+ return Qnil;
247
+ }
211
248
 
212
249
  LOG("passes: %ld\n", passes);
213
250
  return rb_alt_printf(passes, argc - 1, &argv[1], self);
@@ -117,6 +117,9 @@ wchar_t *altsprintf(wchar_t *fmt, struct list_elem *le) {
117
117
  case 1:
118
118
  switch(*fmt) {
119
119
  /* special arguments */
120
+ case FS_A_RBHASHSTART:
121
+ while (fmt < end && *fmt != FS_A_RBHASHEND) fmt++;
122
+ break;
120
123
  case FS_A_STRINGSTART:
121
124
  f.stringarg_start = fmt + 1;
122
125
  lvl = 2;
@@ -191,6 +194,9 @@ wchar_t *altsprintf(wchar_t *fmt, struct list_elem *le) {
191
194
  strbuf_append(sb, FS_START);
192
195
  lvl = 0;
193
196
  break;
197
+ default:
198
+ lvl = 0;
199
+ break;
194
200
  }; break;
195
201
  case 2:
196
202
  if (*fmt == FS_A_STRINGEND) {
File without changes
Binary file
@@ -1,3 +1,3 @@
1
1
  module AltPrintf
2
- VERSION = [0, 1, 1]
2
+ VERSION = [0, 1, 3]
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alt_printf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stone Tickle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-07 00:00:00.000000000 Z
11
+ date: 2019-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -52,6 +52,7 @@ files:
52
52
  - ext/alt_printf/alt_printf.c
53
53
  - ext/alt_printf/altprintf.c
54
54
  - ext/alt_printf/altprintf.h
55
+ - ext/alt_printf/extconf.h
55
56
  - ext/alt_printf/extconf.rb
56
57
  - ext/alt_printf/extconf_dev.rb
57
58
  - ext/alt_printf/list.c
@@ -63,7 +64,7 @@ files:
63
64
  - lib/alt_printf.rb
64
65
  - lib/alt_printf/alt_printf.so
65
66
  - lib/alt_printf/version.rb
66
- homepage: https://github.com/annacrombie/alt_printf/gem
67
+ homepage: https://github.com/annacrombie/altprintf/gem
67
68
  licenses:
68
69
  - MIT
69
70
  metadata: {}