altprintf 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/altprintf/altprintf/altprintf.h +1 -1
- data/ext/altprintf/ext.c +43 -3
- data/lib/altprintf/version.rb +1 -1
- 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: 134617d2a0afa2d1fcbcc02b7e83421b625ed740e80a02869d73fd9c32f9bff9
|
4
|
+
data.tar.gz: 2ff6cc05cd95897746fbdbad9a8d1c7c98ec9ad3430ce6dfcb58de5eea4508ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c6fbb933675cdf58684849b252a61da79241bb86c9da851bc01f9abfeac3e7fa1cfc0211753fd6d0701c68085091c739853a1972d7f3f527ea4a6e89293df3c
|
7
|
+
data.tar.gz: 2542ed5e8d4417a9858c11b9fab94e61c2582827ee0976c261bc87e3ea8450a4eae9d3fa1e45d2ec955de0067717e88e9739d4e2fe5f8d09e857c4d2005d941e
|
data/ext/altprintf/ext.c
CHANGED
@@ -14,8 +14,6 @@
|
|
14
14
|
#include <altprintf/altprintf.h>
|
15
15
|
#include <altprintf/log.h>
|
16
16
|
|
17
|
-
#define MODNAME "Altprintf"
|
18
|
-
|
19
17
|
rb_encoding *enc;
|
20
18
|
|
21
19
|
char *rbstocs(VALUE *rbstr)
|
@@ -209,11 +207,44 @@ VALUE rb_altprintf(long passes, size_t argc, VALUE *argv, VALUE self)
|
|
209
207
|
return final;
|
210
208
|
}
|
211
209
|
|
210
|
+
/*
|
211
|
+
* call-seq:
|
212
|
+
* fmt(format_string [, arguments...]) -> String
|
213
|
+
*
|
214
|
+
* Formats a `format_string` with `arguments`. `format_string` may be any
|
215
|
+
* vaild altprintf format string .
|
216
|
+
* Additionally, a hash may be specified as the last argument, or as keyword
|
217
|
+
* arguments and the values of the hash may be directly accessed in the format
|
218
|
+
* string using < and >.
|
219
|
+
*
|
220
|
+
* For example:
|
221
|
+
* fmt("hello %<name>", name: "John") #=> "hello John"
|
222
|
+
*
|
223
|
+
* Note that the keys within <> are always assumed to be symbols, so the
|
224
|
+
* following would not work
|
225
|
+
* fmt("hello %<name>", { "name" => "John" }) #=> "hello John"
|
226
|
+
*/
|
212
227
|
VALUE rb_altprintf_single_pass(size_t argc, VALUE *argv, VALUE self)
|
213
228
|
{
|
214
229
|
return rb_altprintf(1, argc, argv, self);
|
215
230
|
}
|
216
231
|
|
232
|
+
|
233
|
+
|
234
|
+
/*
|
235
|
+
* call-seq:
|
236
|
+
* fmtm(passes, format_string [, arguments...]) -> String
|
237
|
+
*
|
238
|
+
* Same as #fmt, but takes an additional argument, passes, which specifies the
|
239
|
+
* number of passes to go over the format string.
|
240
|
+
*
|
241
|
+
* For example:
|
242
|
+
* fmtm(0, "%%%%%%%%") #=> "%%%%%%%%"
|
243
|
+
* fmtm(1, "%%%%%%%%") #=> "%%%%"
|
244
|
+
* fmtm(2, "%%%%%%%%") #=> "%%"
|
245
|
+
* fmtm(3, "%%%%%%%%") #=> "%"
|
246
|
+
* fmtm(4, "%%%%%%%%") #=> ""
|
247
|
+
*/
|
217
248
|
VALUE rb_altprintf_multi_pass(size_t argc, VALUE *argv, VALUE self)
|
218
249
|
{
|
219
250
|
long passes;
|
@@ -233,10 +264,19 @@ void Init_altprintf()
|
|
233
264
|
size_t len;
|
234
265
|
|
235
266
|
enc = rb_enc_find("UTF-8");
|
236
|
-
|
267
|
+
|
268
|
+
/*
|
269
|
+
* The base module for *Altprintf*. For documentation on the syntax of
|
270
|
+
* the format string, see https://github.com/annacrombie/altprintf
|
271
|
+
*/
|
272
|
+
mod = rb_define_module("Altprintf");
|
237
273
|
|
238
274
|
len = strlen(ALTPRINTF_VERSION);
|
239
275
|
ver = rb_external_str_new_with_enc(ALTPRINTF_VERSION, len, enc);
|
276
|
+
|
277
|
+
/*
|
278
|
+
* The version of libaltprintf that this extension was compiled against.
|
279
|
+
*/
|
240
280
|
rb_define_const(mod, "LIB_VERSION", ver);
|
241
281
|
|
242
282
|
rb_define_module_function(mod, "fmt", rb_altprintf_single_pass, -1);
|
data/lib/altprintf/version.rb
CHANGED