soundx 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06e4808727b131b50f1d37e805eb4660e3d0291437588ed2f77bc221691ba57b
4
- data.tar.gz: e030973ecc248204ac6f7b6c4f09c73bd38fe69cf9b2bd4c8a94e34aa00ecd47
3
+ metadata.gz: 70da174fdeb5829dc7ad150b4d3f55ffdc10234e2f3b766fbe0a5b958855fa9f
4
+ data.tar.gz: 69fd9ec26626d65efd54ef0ced2112bf1818ea8ce9557c68253e1299abc5b5da
5
5
  SHA512:
6
- metadata.gz: c61cc1f4bfcf617bc34fc2562c703a6e2475756a5b53767ca8b8c3878f67d4c6a89e3c41819444345fe16e853ce398ae4dae0eadbbdef1817bad5999dea844f8
7
- data.tar.gz: 7a04204d898953dd287b54331bce9d13862d5930519526857344b2fe6eda345842d084feac90a9a02d32441a1a95c257f8cf311e81fb498081939b0cebdc1a47
6
+ metadata.gz: 4045704be2c535c5cf56324e156300217a820e9aa52518c96ff8865906d2c9bb191bb7cb98044842382d96752d871b2acd46cea9c4a91d8b207222d423e3bf78
7
+ data.tar.gz: 616866e481e640814594105e59407d200e782ffeabfbde84fd4895189cac7dd3c270f691914bd436d6adf5828674c7747ba2b491dd13c960f52df387ddf35331
data/ext/soundx/soundx.c CHANGED
@@ -20,7 +20,7 @@ r => 6
20
20
  Pre-computed mapping of a-z to the above
21
21
  table.
22
22
  */
23
- static const char mapping[128] = {
23
+ static const unsigned char mapping[128] = {
24
24
  0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
25
25
  0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
26
26
  0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE,
@@ -46,14 +46,15 @@ static VALUE
46
46
  rb_soundx(int argc, VALUE* argv, VALUE self)
47
47
  {
48
48
  VALUE input;
49
- const unsigned char* src;
49
+ unsigned char* src;
50
50
  int written = 0;
51
51
  size_t srclen;
52
- char *dest = malloc(5);
53
52
 
54
- if (!dest) {
55
- rb_raise(rb_eNoMemError, "malloc failed");
56
- }
53
+ /*
54
+ Destination is padded with up to 3 trailing zeros
55
+ for short names.
56
+ */
57
+ char dest[5] = {'0', '0', '0', '0', '\0'};
57
58
 
58
59
  rb_scan_args(argc, argv, "1", &input);
59
60
 
@@ -62,7 +63,7 @@ rb_soundx(int argc, VALUE* argv, VALUE self)
62
63
  }
63
64
 
64
65
  srclen = RSTRING_LEN(input);
65
- src = (const unsigned char*) StringValueCStr(input);
66
+ src = (unsigned char *) StringValueCStr(input);
66
67
 
67
68
  dest[0] = toupper(src[0]);
68
69
 
@@ -76,15 +77,14 @@ rb_soundx(int argc, VALUE* argv, VALUE self)
76
77
  }
77
78
 
78
79
  if (src[i] > 128) {
79
- free(dest);
80
80
  rb_raise(rb_eArgError, "non-ASCII character found");
81
81
  break;
82
82
  }
83
83
 
84
84
  unsigned char current = tolower(src[i]);
85
85
 
86
- char match = mapping[ current ];
87
- if (0xFE == (int) match) {
86
+ unsigned char match = mapping[ current ];
87
+ if (0xFE == match) {
88
88
  continue;
89
89
  }
90
90
 
@@ -104,18 +104,7 @@ rb_soundx(int argc, VALUE* argv, VALUE self)
104
104
  written++;
105
105
  }
106
106
 
107
- // Pad at most three '0' characters
108
- // to handle really short names
109
- if (written < 3) {
110
- for( int i = (3-written); i > 0; i--) {
111
- dest[written+i] = '0';
112
- }
113
- }
114
-
115
- dest[4] = '\0';
116
-
117
107
  VALUE rbString = rb_str_new_cstr(dest);
118
- free(dest);
119
108
 
120
109
  return rbString;
121
110
  }
@@ -1,3 +1,3 @@
1
1
  module SoundX
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soundx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Cook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-07 00:00:00.000000000 Z
11
+ date: 2019-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler