b62 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/b62/b62.c +10 -18
- metadata +2 -2
data/ext/b62/b62.c
CHANGED
@@ -14,33 +14,25 @@ static const char b62_table[] = { "0123456789"
|
|
14
14
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
15
15
|
"abcdefghijklmnopqrstuvwxyz" };
|
16
16
|
|
17
|
-
|
17
|
+
static VALUE encode(VALUE self, VALUE arg)
|
18
18
|
{
|
19
|
-
|
20
|
-
|
19
|
+
u_int64_t input = NUM2ULL(arg);
|
20
|
+
char output[12];
|
21
|
+
unsigned short i = 11;
|
21
22
|
|
22
|
-
|
23
|
+
output[i] = '\0';
|
23
24
|
|
24
25
|
do
|
25
26
|
{
|
26
|
-
i
|
27
|
-
|
28
|
-
|
29
|
-
ptr[i] = b62_table[r];
|
30
|
-
}while(input > 0);
|
31
|
-
|
32
|
-
return i;
|
33
|
-
}
|
27
|
+
output[--i] = b62_table[input % 62];
|
28
|
+
}
|
29
|
+
while((input = input / 62) > 0);
|
34
30
|
|
35
|
-
|
36
|
-
{
|
37
|
-
char output[12];
|
38
|
-
|
39
|
-
return rb_str_new2(&output[encode(NUM2ULL(arg), output)]);
|
31
|
+
return rb_str_new2(&output[i]);
|
40
32
|
}
|
41
33
|
|
42
34
|
void Init_b62(void)
|
43
35
|
{
|
44
36
|
VALUE klass = rb_define_class("B62", rb_cObject);
|
45
|
-
rb_define_singleton_method(klass, "to_b62",
|
37
|
+
rb_define_singleton_method(klass, "to_b62", encode, 1);
|
46
38
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: b62
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! " Adds a to_b62 function to the Integer class that encodes \n any
|
15
15
|
integer between 0 and 18446744073709551615 to base 62.\n The encode function is
|