jsminc 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/jsminc/jsminc.c +92 -88
- data/lib/jsminc/version.rb +1 -1
- metadata +37 -29
data/ext/jsminc/jsminc.c
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
#include "ruby.h"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
typedef struct jsmin_struct {
|
4
|
+
char theA;
|
5
|
+
char theB;
|
6
|
+
char theLookahead;
|
7
|
+
char *in;
|
8
|
+
char *out;
|
9
|
+
} jsmin_struct;
|
9
10
|
|
10
11
|
/* isAlphanum -- return true if the character is a letter, digit, underscore,
|
11
12
|
dollar sign, or non-ASCII character.
|
@@ -26,13 +27,12 @@ isAlphanum(char c)
|
|
26
27
|
*/
|
27
28
|
|
28
29
|
static char
|
29
|
-
get()
|
30
|
+
get(jsmin_struct *s)
|
30
31
|
{
|
31
|
-
char c = theLookahead;
|
32
|
-
theLookahead = '\0';
|
32
|
+
char c = s->theLookahead;
|
33
|
+
s->theLookahead = '\0';
|
33
34
|
if (c == '\0') {
|
34
|
-
c = *
|
35
|
-
current_in++;
|
35
|
+
c = *(s->in)++;
|
36
36
|
}
|
37
37
|
if (c >= ' ' || c == '\n' || c == '\0') {
|
38
38
|
return c;
|
@@ -44,20 +44,20 @@ get()
|
|
44
44
|
}
|
45
45
|
|
46
46
|
static void
|
47
|
-
write_char(const char c)
|
47
|
+
write_char(jsmin_struct *s, const char c)
|
48
48
|
{
|
49
|
-
*
|
50
|
-
|
49
|
+
*(s->out) = c;
|
50
|
+
*(s->out)++;
|
51
51
|
}
|
52
52
|
|
53
53
|
/* peek -- get the next character without getting it.
|
54
54
|
*/
|
55
55
|
|
56
56
|
static char
|
57
|
-
peek()
|
57
|
+
peek(jsmin_struct *s)
|
58
58
|
{
|
59
|
-
theLookahead = get();
|
60
|
-
return theLookahead;
|
59
|
+
s->theLookahead = get(s);
|
60
|
+
return s->theLookahead;
|
61
61
|
}
|
62
62
|
|
63
63
|
|
@@ -66,25 +66,25 @@ peek()
|
|
66
66
|
*/
|
67
67
|
|
68
68
|
static char
|
69
|
-
next()
|
69
|
+
next(jsmin_struct *s)
|
70
70
|
{
|
71
|
-
char c = get();
|
71
|
+
char c = get(s);
|
72
72
|
if (c == '/') {
|
73
|
-
switch (peek()) {
|
73
|
+
switch (peek(s)) {
|
74
74
|
case '/':
|
75
75
|
for (;;) {
|
76
|
-
c = get();
|
76
|
+
c = get(s);
|
77
77
|
if (c <= '\n') {
|
78
78
|
return c;
|
79
79
|
}
|
80
80
|
}
|
81
81
|
case '*':
|
82
|
-
get();
|
82
|
+
get(s);
|
83
83
|
for (;;) {
|
84
|
-
switch (get()) {
|
84
|
+
switch (get(s)) {
|
85
85
|
case '*':
|
86
|
-
if (peek() == '/') {
|
87
|
-
get();
|
86
|
+
if (peek(s) == '/') {
|
87
|
+
get(s);
|
88
88
|
return ' ';
|
89
89
|
}
|
90
90
|
break;
|
@@ -109,67 +109,67 @@ next()
|
|
109
109
|
*/
|
110
110
|
|
111
111
|
static void
|
112
|
-
action(int d)
|
112
|
+
action(jsmin_struct *s, int d)
|
113
113
|
{
|
114
114
|
switch (d) {
|
115
115
|
case 1:
|
116
|
-
write_char(theA);
|
116
|
+
write_char(s, s->theA);
|
117
117
|
case 2:
|
118
|
-
theA = theB;
|
119
|
-
if (theA == '\'' || theA == '"' || theA == '`') {
|
118
|
+
s->theA = s->theB;
|
119
|
+
if (s->theA == '\'' || s->theA == '"' || s->theA == '`') {
|
120
120
|
for (;;) {
|
121
|
-
write_char(theA);
|
122
|
-
theA = get();
|
123
|
-
if (theA == theB) {
|
121
|
+
write_char(s, s->theA);
|
122
|
+
s->theA = get(s);
|
123
|
+
if (s->theA == s->theB) {
|
124
124
|
break;
|
125
125
|
}
|
126
|
-
if (theA == '\\') {
|
127
|
-
write_char(theA);
|
128
|
-
theA = get();
|
126
|
+
if (s->theA == '\\') {
|
127
|
+
write_char(s, s->theA);
|
128
|
+
s->theA = get(s);
|
129
129
|
}
|
130
|
-
if (theA == '\0') {
|
130
|
+
if (s->theA == '\0') {
|
131
131
|
rb_raise(rb_eStandardError, "unterminated string literal");
|
132
132
|
}
|
133
133
|
}
|
134
134
|
}
|
135
135
|
case 3:
|
136
|
-
theB = next();
|
137
|
-
if (theB == '/' && (theA == '(' || theA == ',' || theA == '=' ||
|
138
|
-
theA == ':' || theA == '[' || theA == '!' ||
|
139
|
-
theA == '&' || theA == '|' || theA == '?' ||
|
140
|
-
theA == '{' || theA == '}' || theA == ';' ||
|
141
|
-
theA == '\n')) {
|
142
|
-
write_char(theA);
|
143
|
-
write_char(theB);
|
136
|
+
s->theB = next(s);
|
137
|
+
if (s->theB == '/' && (s->theA == '(' || s->theA == ',' || s->theA == '=' ||
|
138
|
+
s->theA == ':' || s->theA == '[' || s->theA == '!' ||
|
139
|
+
s->theA == '&' || s->theA == '|' || s->theA == '?' ||
|
140
|
+
s->theA == '{' || s->theA == '}' || s->theA == ';' ||
|
141
|
+
s->theA == '\n')) {
|
142
|
+
write_char(s, s->theA);
|
143
|
+
write_char(s, s->theB);
|
144
144
|
for (;;) {
|
145
|
-
theA = get();
|
146
|
-
if (theA == '[') {
|
145
|
+
s->theA = get(s);
|
146
|
+
if (s->theA == '[') {
|
147
147
|
for (;;) {
|
148
|
-
write_char(theA);
|
149
|
-
theA = get();
|
150
|
-
if (theA == ']') {
|
148
|
+
write_char(s, s->theA);
|
149
|
+
s->theA = get(s);
|
150
|
+
if (s->theA == ']') {
|
151
151
|
break;
|
152
152
|
}
|
153
|
-
if (theA == '\\') {
|
154
|
-
write_char(theA);
|
155
|
-
theA = get();
|
153
|
+
if (s->theA == '\\') {
|
154
|
+
write_char(s, s->theA);
|
155
|
+
s->theA = get(s);
|
156
156
|
}
|
157
|
-
if (theA == '\0') {
|
157
|
+
if (s->theA == '\0') {
|
158
158
|
rb_raise(rb_eStandardError, "unterminated set in regex literal");
|
159
159
|
}
|
160
160
|
}
|
161
|
-
} else if (theA == '/') {
|
161
|
+
} else if (s->theA == '/') {
|
162
162
|
break;
|
163
|
-
} else if (theA =='\\') {
|
164
|
-
write_char(theA);
|
165
|
-
theA = get();
|
163
|
+
} else if (s->theA =='\\') {
|
164
|
+
write_char(s, s->theA);
|
165
|
+
s->theA = get(s);
|
166
166
|
}
|
167
|
-
if (theA == '\0') {
|
167
|
+
if (s->theA == '\0') {
|
168
168
|
rb_raise(rb_eStandardError, "unterminated regex literal");
|
169
169
|
}
|
170
|
-
write_char(theA);
|
170
|
+
write_char(s, s->theA);
|
171
171
|
}
|
172
|
-
theB = next();
|
172
|
+
s->theB = next(s);
|
173
173
|
}
|
174
174
|
}
|
175
175
|
}
|
@@ -182,50 +182,52 @@ action(int d)
|
|
182
182
|
*/
|
183
183
|
|
184
184
|
static void
|
185
|
-
jsmin()
|
185
|
+
jsmin(jsmin_struct *s)
|
186
186
|
{
|
187
|
-
theA = '\n';
|
188
|
-
|
189
|
-
|
190
|
-
|
187
|
+
s->theA = '\n';
|
188
|
+
s->theLookahead = '\0';
|
189
|
+
|
190
|
+
action(s, 3);
|
191
|
+
while (s->theA != '\0') {
|
192
|
+
switch (s->theA) {
|
191
193
|
case ' ':
|
192
|
-
if (isAlphanum(theB)) {
|
193
|
-
action(1);
|
194
|
+
if (isAlphanum(s->theB)) {
|
195
|
+
action(s, 1);
|
194
196
|
} else {
|
195
|
-
action(2);
|
197
|
+
action(s, 2);
|
196
198
|
}
|
197
199
|
break;
|
198
200
|
case '\n':
|
199
|
-
switch (theB) {
|
201
|
+
switch (s->theB) {
|
200
202
|
case '{':
|
201
203
|
case '[':
|
202
204
|
case '(':
|
203
205
|
case '+':
|
204
206
|
case '-':
|
205
|
-
action(1);
|
207
|
+
action(s, 1);
|
206
208
|
break;
|
207
209
|
case ' ':
|
208
|
-
action(3);
|
210
|
+
action(s, 3);
|
209
211
|
break;
|
210
212
|
default:
|
211
|
-
if (isAlphanum(theB)) {
|
212
|
-
action(1);
|
213
|
+
if (isAlphanum(s->theB)) {
|
214
|
+
action(s, 1);
|
213
215
|
} else {
|
214
|
-
action(2);
|
216
|
+
action(s, 2);
|
215
217
|
}
|
216
218
|
}
|
217
219
|
break;
|
218
220
|
default:
|
219
|
-
switch (theB) {
|
221
|
+
switch (s->theB) {
|
220
222
|
case ' ':
|
221
|
-
if (isAlphanum(theA)) {
|
222
|
-
action(1);
|
223
|
+
if (isAlphanum(s->theA)) {
|
224
|
+
action(s, 1);
|
223
225
|
break;
|
224
226
|
}
|
225
|
-
action(3);
|
227
|
+
action(s, 3);
|
226
228
|
break;
|
227
229
|
case '\n':
|
228
|
-
switch (theA) {
|
230
|
+
switch (s->theA) {
|
229
231
|
case '}':
|
230
232
|
case ']':
|
231
233
|
case ')':
|
@@ -234,27 +236,29 @@ jsmin()
|
|
234
236
|
case '"':
|
235
237
|
case '\'':
|
236
238
|
case '`':
|
237
|
-
action(1);
|
239
|
+
action(s, 1);
|
238
240
|
break;
|
239
241
|
default:
|
240
|
-
if (isAlphanum(theA)) {
|
241
|
-
action(1);
|
242
|
+
if (isAlphanum(s->theA)) {
|
243
|
+
action(s, 1);
|
242
244
|
} else {
|
243
|
-
action(3);
|
245
|
+
action(s, 3);
|
244
246
|
}
|
245
247
|
}
|
246
248
|
break;
|
247
249
|
default:
|
248
|
-
action(1);
|
250
|
+
action(s, 1);
|
249
251
|
break;
|
250
252
|
}
|
251
253
|
}
|
252
254
|
}
|
253
|
-
write_char('\0');
|
255
|
+
write_char(s, '\0');
|
254
256
|
}
|
255
257
|
|
256
258
|
|
257
259
|
static VALUE minify(VALUE self, VALUE _in_s) {
|
260
|
+
jsmin_struct s;
|
261
|
+
|
258
262
|
char *in_s = StringValueCStr(_in_s);
|
259
263
|
long in_length = strlen(in_s);
|
260
264
|
char out_s[in_length + 1];
|
@@ -263,9 +267,9 @@ static VALUE minify(VALUE self, VALUE _in_s) {
|
|
263
267
|
VALUE prev_encoding = rb_funcall(_in_s, rb_intern("encoding"), 0);
|
264
268
|
#endif
|
265
269
|
|
266
|
-
|
267
|
-
|
268
|
-
jsmin();
|
270
|
+
s.in = in_s;
|
271
|
+
s.out = out_s;
|
272
|
+
jsmin(&s);
|
269
273
|
|
270
274
|
#ifdef RUBY_19
|
271
275
|
return rb_funcall(rb_str_new2(out_s + 1), rb_intern("force_encoding"), 1, prev_encoding);
|
data/lib/jsminc/version.rb
CHANGED
metadata
CHANGED
@@ -1,35 +1,38 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsminc
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 1.1.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Ryan Fitzgerald
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2012-01-25 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: rake-compiler
|
16
|
-
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
19
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version:
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
22
24
|
type: :development
|
23
|
-
|
24
|
-
version_requirements: *70136917393560
|
25
|
+
version_requirements: *id001
|
25
26
|
description: JSMinC is the original C version of JSMin, embedded in Ruby.
|
26
|
-
email:
|
27
|
+
email:
|
27
28
|
- rwfitzge@gmail.com
|
28
29
|
executables: []
|
29
|
-
|
30
|
+
|
31
|
+
extensions:
|
30
32
|
- ext/jsminc/extconf.rb
|
31
33
|
extra_rdoc_files: []
|
32
|
-
|
34
|
+
|
35
|
+
files:
|
33
36
|
- .gitignore
|
34
37
|
- Gemfile
|
35
38
|
- LICENSE
|
@@ -41,26 +44,31 @@ files:
|
|
41
44
|
- lib/jsminc/version.rb
|
42
45
|
homepage: http://rynftz.gr/
|
43
46
|
licenses: []
|
47
|
+
|
44
48
|
post_install_message:
|
45
49
|
rdoc_options: []
|
46
|
-
|
50
|
+
|
51
|
+
require_paths:
|
47
52
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
54
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
60
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version:
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
60
65
|
requirements: []
|
66
|
+
|
61
67
|
rubyforge_project: jsminc
|
62
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.15
|
63
69
|
signing_key:
|
64
70
|
specification_version: 3
|
65
71
|
summary: A fast JavaScript minifier written in C (by Douglas Crockford)
|
66
72
|
test_files: []
|
73
|
+
|
74
|
+
has_rdoc:
|