ox 2.14.14 → 2.14.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/ext/ox/attr.h +33 -39
- data/ext/ox/base64.c +48 -42
- data/ext/ox/base64.h +4 -4
- data/ext/ox/buf.h +80 -86
- data/ext/ox/builder.c +378 -423
- data/ext/ox/cache.c +2 -2
- data/ext/ox/cache8.c +37 -40
- data/ext/ox/cache8.h +7 -7
- data/ext/ox/dump.c +838 -867
- data/ext/ox/err.c +16 -13
- data/ext/ox/err.h +11 -12
- data/ext/ox/extconf.rb +5 -5
- data/ext/ox/gen_load.c +135 -137
- data/ext/ox/hash_load.c +130 -148
- data/ext/ox/helper.h +32 -39
- data/ext/ox/intern.c +1 -2
- data/ext/ox/obj_load.c +590 -644
- data/ext/ox/ox.c +2 -2
- data/ext/ox/ox.h +5 -5
- data/ext/ox/parse.c +836 -874
- data/ext/ox/sax.c +38 -23
- data/ext/ox/sax.h +2 -2
- data/ext/ox/sax_as.c +78 -94
- data/ext/ox/sax_buf.c +85 -94
- data/ext/ox/sax_buf.h +101 -120
- data/ext/ox/sax_hint.c +175 -184
- data/ext/ox/sax_hint.h +19 -19
- data/ext/ox/sax_stack.h +59 -45
- data/ext/ox/slotcache.c +2 -2
- data/ext/ox/slotcache.h +4 -4
- data/ext/ox/special.c +320 -327
- data/ext/ox/special.h +2 -2
- data/ext/ox/type.h +19 -19
- data/lib/ox/bag.rb +13 -9
- data/lib/ox/cdata.rb +0 -2
- data/lib/ox/comment.rb +0 -2
- data/lib/ox/doctype.rb +0 -2
- data/lib/ox/document.rb +3 -5
- data/lib/ox/element.rb +41 -26
- data/lib/ox/error.rb +0 -3
- data/lib/ox/hasattrs.rb +7 -8
- data/lib/ox/instruct.rb +4 -6
- data/lib/ox/node.rb +3 -4
- data/lib/ox/raw.rb +0 -2
- data/lib/ox/sax.rb +20 -36
- data/lib/ox/version.rb +1 -2
- data/lib/ox/xmlrpc_adapter.rb +4 -6
- data/lib/ox.rb +15 -16
- metadata +6 -5
data/ext/ox/sax_buf.c
CHANGED
@@ -3,96 +3,94 @@
|
|
3
3
|
* All rights reserved.
|
4
4
|
*/
|
5
5
|
|
6
|
-
#include <stdlib.h>
|
7
6
|
#include <errno.h>
|
8
7
|
#include <stdio.h>
|
8
|
+
#include <stdlib.h>
|
9
9
|
#include <strings.h>
|
10
10
|
#include <sys/types.h>
|
11
11
|
#if HAVE_SYS_UIO_H
|
12
12
|
#include <sys/uio.h>
|
13
13
|
#endif
|
14
|
-
#include <unistd.h>
|
15
14
|
#include <time.h>
|
15
|
+
#include <unistd.h>
|
16
16
|
|
17
|
-
#include "ruby.h"
|
18
17
|
#include "ox.h"
|
18
|
+
#include "ruby.h"
|
19
19
|
#include "sax.h"
|
20
20
|
|
21
|
-
#define BUF_PAD
|
21
|
+
#define BUF_PAD 4
|
22
22
|
|
23
|
-
static VALUE
|
24
|
-
static VALUE
|
25
|
-
static VALUE
|
26
|
-
static int
|
27
|
-
static int
|
28
|
-
static int
|
29
|
-
static int
|
23
|
+
static VALUE rescue_cb(VALUE rdr, VALUE err);
|
24
|
+
static VALUE io_cb(VALUE rdr);
|
25
|
+
static VALUE partial_io_cb(VALUE rdr);
|
26
|
+
static int read_from_io(Buf buf);
|
27
|
+
static int read_from_fd(Buf buf);
|
28
|
+
static int read_from_io_partial(Buf buf);
|
29
|
+
static int read_from_str(Buf buf);
|
30
30
|
|
31
|
-
void
|
32
|
-
|
33
|
-
|
34
|
-
VALUE rfd;
|
31
|
+
void ox_sax_buf_init(Buf buf, VALUE io) {
|
32
|
+
volatile VALUE io_class = rb_obj_class(io);
|
33
|
+
VALUE rfd;
|
35
34
|
|
36
35
|
if (rb_cString == io_class) {
|
37
|
-
|
38
|
-
|
36
|
+
buf->read_func = read_from_str;
|
37
|
+
buf->in.str = StringValuePtr(io);
|
39
38
|
} else if (ox_stringio_class == io_class && 0 == FIX2INT(rb_funcall2(io, ox_pos_id, 0, 0))) {
|
40
|
-
|
39
|
+
volatile VALUE s = rb_funcall2(io, ox_string_id, 0, 0);
|
41
40
|
|
42
|
-
|
43
|
-
|
41
|
+
buf->read_func = read_from_str;
|
42
|
+
buf->in.str = StringValuePtr(s);
|
44
43
|
} else if (rb_cFile == io_class && Qnil != (rfd = rb_funcall(io, ox_fileno_id, 0))) {
|
45
|
-
|
46
|
-
|
44
|
+
buf->read_func = read_from_fd;
|
45
|
+
buf->in.fd = FIX2INT(rfd);
|
47
46
|
} else if (rb_respond_to(io, ox_readpartial_id)) {
|
48
|
-
|
49
|
-
|
47
|
+
buf->read_func = read_from_io_partial;
|
48
|
+
buf->in.io = io;
|
50
49
|
} else if (rb_respond_to(io, ox_read_id)) {
|
51
|
-
|
52
|
-
|
50
|
+
buf->read_func = read_from_io;
|
51
|
+
buf->in.io = io;
|
53
52
|
} else {
|
54
53
|
rb_raise(ox_arg_error_class, "sax_parser io argument must respond to readpartial() or read().\n");
|
55
54
|
}
|
56
|
-
buf->head
|
57
|
-
*buf->head
|
58
|
-
buf->end
|
59
|
-
buf->tail
|
55
|
+
buf->head = buf->base;
|
56
|
+
*buf->head = '\0';
|
57
|
+
buf->end = buf->head + sizeof(buf->base) - BUF_PAD;
|
58
|
+
buf->tail = buf->head;
|
60
59
|
buf->read_end = buf->head;
|
61
|
-
buf->pro
|
62
|
-
buf->str
|
63
|
-
buf->pos
|
64
|
-
buf->line
|
65
|
-
buf->col
|
66
|
-
buf->pro_pos
|
60
|
+
buf->pro = 0;
|
61
|
+
buf->str = 0;
|
62
|
+
buf->pos = 0;
|
63
|
+
buf->line = 1;
|
64
|
+
buf->col = 0;
|
65
|
+
buf->pro_pos = 1;
|
67
66
|
buf->pro_line = 1;
|
68
|
-
buf->pro_col
|
69
|
-
buf->dr
|
67
|
+
buf->pro_col = 0;
|
68
|
+
buf->dr = 0;
|
70
69
|
}
|
71
70
|
|
72
|
-
int
|
73
|
-
|
74
|
-
|
75
|
-
size_t shift = 0;
|
71
|
+
int ox_sax_buf_read(Buf buf) {
|
72
|
+
int err;
|
73
|
+
size_t shift = 0;
|
76
74
|
|
77
75
|
// if there is not much room to read into, shift or realloc a larger buffer.
|
78
76
|
if (buf->head < buf->tail && 4096 > buf->end - buf->tail) {
|
79
77
|
if (0 == buf->pro) {
|
80
78
|
shift = buf->tail - buf->head;
|
81
79
|
} else {
|
82
|
-
shift = buf->pro - buf->head - 1;
|
80
|
+
shift = buf->pro - buf->head - 1; // leave one character so we cab backup one
|
83
81
|
}
|
84
|
-
if (0 >= shift) {
|
85
|
-
char
|
86
|
-
size_t
|
82
|
+
if (0 >= shift) { /* no space left so allocate more */
|
83
|
+
char *old = buf->head;
|
84
|
+
size_t size = buf->end - buf->head + BUF_PAD;
|
87
85
|
|
88
86
|
if (buf->head == buf->base) {
|
89
87
|
buf->head = ALLOC_N(char, size * 2);
|
90
88
|
memcpy(buf->head, old, size);
|
91
89
|
} else {
|
92
|
-
|
90
|
+
REALLOC_N(buf->head, char, size * 2);
|
93
91
|
}
|
94
|
-
buf->end
|
95
|
-
buf->tail
|
92
|
+
buf->end = buf->head + size * 2 - BUF_PAD;
|
93
|
+
buf->tail = buf->head + (buf->tail - old);
|
96
94
|
buf->read_end = buf->head + (buf->read_end - old);
|
97
95
|
if (0 != buf->pro) {
|
98
96
|
buf->pro = buf->head + (buf->pro - old);
|
@@ -112,77 +110,71 @@ ox_sax_buf_read(Buf buf) {
|
|
112
110
|
}
|
113
111
|
}
|
114
112
|
}
|
115
|
-
err
|
113
|
+
err = buf->read_func(buf);
|
116
114
|
*buf->read_end = '\0';
|
117
115
|
|
118
116
|
return err;
|
119
117
|
}
|
120
118
|
|
121
|
-
static VALUE
|
122
|
-
|
123
|
-
VALUE err_class = rb_obj_class(err);
|
119
|
+
static VALUE rescue_cb(VALUE rbuf, VALUE err) {
|
120
|
+
VALUE err_class = rb_obj_class(err);
|
124
121
|
|
125
122
|
if (err_class != rb_eTypeError && err_class != rb_eEOFError) {
|
126
|
-
|
123
|
+
Buf buf = (Buf)rbuf;
|
127
124
|
|
128
|
-
//ox_sax_drive_cleanup(buf->dr); called after exiting protect
|
125
|
+
// ox_sax_drive_cleanup(buf->dr); called after exiting protect
|
129
126
|
rb_raise(err, "at line %ld, column %ld\n", (long)buf->line, (long)buf->col);
|
130
127
|
}
|
131
128
|
return Qfalse;
|
132
129
|
}
|
133
130
|
|
134
|
-
static VALUE
|
135
|
-
|
136
|
-
|
137
|
-
VALUE
|
138
|
-
|
139
|
-
|
140
|
-
size_t cnt;
|
131
|
+
static VALUE partial_io_cb(VALUE rbuf) {
|
132
|
+
Buf buf = (Buf)rbuf;
|
133
|
+
VALUE args[1];
|
134
|
+
VALUE rstr;
|
135
|
+
char *str;
|
136
|
+
size_t cnt;
|
141
137
|
|
142
138
|
args[0] = ULONG2NUM(buf->end - buf->tail);
|
143
|
-
rstr
|
144
|
-
str
|
145
|
-
cnt
|
146
|
-
//printf("*** read partial %lu bytes, str: '%s'\n", cnt, str);
|
139
|
+
rstr = rb_funcall2(buf->in.io, ox_readpartial_id, 1, args);
|
140
|
+
str = StringValuePtr(rstr);
|
141
|
+
cnt = strlen(str);
|
142
|
+
// printf("*** read partial %lu bytes, str: '%s'\n", cnt, str);
|
147
143
|
strcpy(buf->tail, str);
|
148
144
|
buf->read_end = buf->tail + cnt;
|
149
145
|
|
150
146
|
return Qtrue;
|
151
147
|
}
|
152
148
|
|
153
|
-
static VALUE
|
154
|
-
|
155
|
-
|
156
|
-
VALUE
|
157
|
-
|
158
|
-
|
159
|
-
size_t cnt;
|
149
|
+
static VALUE io_cb(VALUE rbuf) {
|
150
|
+
Buf buf = (Buf)rbuf;
|
151
|
+
VALUE args[1];
|
152
|
+
VALUE rstr;
|
153
|
+
char *str;
|
154
|
+
size_t cnt;
|
160
155
|
|
161
156
|
args[0] = ULONG2NUM(buf->end - buf->tail);
|
162
|
-
rstr
|
163
|
-
str
|
164
|
-
cnt
|
165
|
-
//printf("*** read %lu bytes, str: '%s'\n", cnt, str);
|
157
|
+
rstr = rb_funcall2(buf->in.io, ox_read_id, 1, args);
|
158
|
+
str = StringValuePtr(rstr);
|
159
|
+
cnt = strlen(str);
|
160
|
+
// printf("*** read %lu bytes, str: '%s'\n", cnt, str);
|
166
161
|
strcpy(buf->tail, str);
|
167
162
|
buf->read_end = buf->tail + cnt;
|
168
163
|
|
169
164
|
return Qtrue;
|
170
165
|
}
|
171
166
|
|
172
|
-
static int
|
173
|
-
read_from_io_partial(Buf buf) {
|
167
|
+
static int read_from_io_partial(Buf buf) {
|
174
168
|
return (Qfalse == rb_rescue(partial_io_cb, (VALUE)buf, rescue_cb, (VALUE)buf));
|
175
169
|
}
|
176
170
|
|
177
|
-
static int
|
178
|
-
read_from_io(Buf buf) {
|
171
|
+
static int read_from_io(Buf buf) {
|
179
172
|
return (Qfalse == rb_rescue(io_cb, (VALUE)buf, rescue_cb, (VALUE)buf));
|
180
173
|
}
|
181
174
|
|
182
|
-
static int
|
183
|
-
|
184
|
-
|
185
|
-
size_t max = buf->end - buf->tail;
|
175
|
+
static int read_from_fd(Buf buf) {
|
176
|
+
ssize_t cnt;
|
177
|
+
size_t max = buf->end - buf->tail;
|
186
178
|
|
187
179
|
cnt = read(buf->in.fd, buf->tail, max);
|
188
180
|
if (cnt < 0) {
|
@@ -194,22 +186,21 @@ read_from_fd(Buf buf) {
|
|
194
186
|
return 0;
|
195
187
|
}
|
196
188
|
|
197
|
-
static int
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
size_t cnt;
|
189
|
+
static int read_from_str(Buf buf) {
|
190
|
+
size_t max = buf->end - buf->tail - 1;
|
191
|
+
char *s;
|
192
|
+
size_t cnt;
|
202
193
|
|
203
194
|
if ('\0' == *buf->in.str) {
|
204
|
-
|
195
|
+
return -1;
|
205
196
|
}
|
206
197
|
cnt = strlen(buf->in.str) + 1;
|
207
198
|
if (max < cnt) {
|
208
|
-
|
199
|
+
cnt = max;
|
209
200
|
}
|
210
201
|
strncpy(buf->tail, buf->in.str, cnt);
|
211
|
-
s
|
212
|
-
*s
|
202
|
+
s = buf->tail + cnt - 1;
|
203
|
+
*s = '\0';
|
213
204
|
cnt = s - buf->tail;
|
214
205
|
buf->in.str += cnt;
|
215
206
|
buf->read_end = buf->tail + cnt;
|
data/ext/ox/sax_buf.h
CHANGED
@@ -9,44 +9,45 @@
|
|
9
9
|
#include <stdio.h>
|
10
10
|
|
11
11
|
typedef struct _buf {
|
12
|
-
char
|
13
|
-
char
|
14
|
-
char
|
15
|
-
char
|
16
|
-
char
|
17
|
-
char
|
18
|
-
char
|
19
|
-
off_t
|
20
|
-
off_t
|
21
|
-
off_t
|
22
|
-
off_t
|
23
|
-
off_t
|
24
|
-
off_t
|
25
|
-
int
|
12
|
+
char base[0x00001000];
|
13
|
+
char *head;
|
14
|
+
char *end;
|
15
|
+
char *tail;
|
16
|
+
char *read_end; /* one past last character read */
|
17
|
+
char *pro; /* protection start, buffer can not slide past this point */
|
18
|
+
char *str; /* start of current string being read */
|
19
|
+
off_t pos;
|
20
|
+
off_t line;
|
21
|
+
off_t col;
|
22
|
+
off_t pro_pos;
|
23
|
+
off_t pro_line;
|
24
|
+
off_t pro_col;
|
25
|
+
int (*read_func)(struct _buf *buf);
|
26
26
|
union {
|
27
|
-
int
|
28
|
-
VALUE
|
29
|
-
|
27
|
+
int fd;
|
28
|
+
VALUE io;
|
29
|
+
const char *str;
|
30
30
|
} in;
|
31
|
-
struct _saxDrive
|
31
|
+
struct _saxDrive *dr;
|
32
32
|
} *Buf;
|
33
33
|
|
34
34
|
typedef struct _checkPt {
|
35
|
-
off_t
|
36
|
-
off_t
|
37
|
-
off_t
|
38
|
-
off_t
|
39
|
-
char
|
35
|
+
off_t pro_dif;
|
36
|
+
off_t pos;
|
37
|
+
off_t line;
|
38
|
+
off_t col;
|
39
|
+
char c;
|
40
40
|
} *CheckPt;
|
41
41
|
|
42
|
-
#define CHECK_PT_INIT
|
42
|
+
#define CHECK_PT_INIT \
|
43
|
+
{ -1, 0, 0, 0, '\0' }
|
43
44
|
|
44
|
-
extern void
|
45
|
-
extern int
|
45
|
+
extern void ox_sax_buf_init(Buf buf, VALUE io);
|
46
|
+
extern int ox_sax_buf_read(Buf buf);
|
46
47
|
|
47
|
-
static inline char
|
48
|
-
|
49
|
-
//
|
48
|
+
static inline char buf_get(Buf buf) {
|
49
|
+
// printf("*** drive get from '%s' from start: %ld buf: %p from read_end: %ld\n", buf->tail, buf->tail -
|
50
|
+
// buf->head, buf->head, buf->read_end - buf->tail);
|
50
51
|
if (buf->read_end <= buf->tail) {
|
51
52
|
if (0 != ox_sax_buf_read(buf)) {
|
52
53
|
return '\0';
|
@@ -56,59 +57,53 @@ buf_get(Buf buf) {
|
|
56
57
|
buf->line++;
|
57
58
|
buf->col = 0;
|
58
59
|
} else {
|
59
|
-
|
60
|
+
buf->col++;
|
60
61
|
}
|
61
62
|
buf->pos++;
|
62
63
|
|
63
64
|
return *buf->tail++;
|
64
65
|
}
|
65
66
|
|
66
|
-
static inline void
|
67
|
-
buf_backup(Buf buf) {
|
67
|
+
static inline void buf_backup(Buf buf) {
|
68
68
|
buf->tail--;
|
69
69
|
buf->col--;
|
70
70
|
buf->pos--;
|
71
71
|
if (0 >= buf->col) {
|
72
|
-
|
73
|
-
|
72
|
+
buf->line--;
|
73
|
+
// allow col to be negative since we never backup twice in a row
|
74
74
|
}
|
75
75
|
}
|
76
76
|
|
77
|
-
static inline void
|
78
|
-
|
79
|
-
buf->
|
80
|
-
buf->
|
81
|
-
buf->pro_pos = buf->pos;
|
77
|
+
static inline void buf_protect(Buf buf) {
|
78
|
+
buf->pro = buf->tail;
|
79
|
+
buf->str = buf->tail; // can't have str before pro
|
80
|
+
buf->pro_pos = buf->pos;
|
82
81
|
buf->pro_line = buf->line;
|
83
|
-
buf->pro_col
|
82
|
+
buf->pro_col = buf->col;
|
84
83
|
}
|
85
84
|
|
86
|
-
static inline void
|
87
|
-
buf_reset(Buf buf) {
|
85
|
+
static inline void buf_reset(Buf buf) {
|
88
86
|
buf->tail = buf->pro;
|
89
|
-
buf->pos
|
87
|
+
buf->pos = buf->pro_pos;
|
90
88
|
buf->line = buf->pro_line;
|
91
|
-
buf->col
|
89
|
+
buf->col = buf->pro_col;
|
92
90
|
}
|
93
91
|
|
94
92
|
/* Starts by reading a character so it is safe to use with an empty or
|
95
93
|
* compacted buffer.
|
96
94
|
*/
|
97
|
-
static inline char
|
98
|
-
|
99
|
-
char c;
|
95
|
+
static inline char buf_next_non_white(Buf buf) {
|
96
|
+
char c;
|
100
97
|
|
101
98
|
while ('\0' != (c = buf_get(buf))) {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
return c;
|
111
|
-
}
|
99
|
+
switch (c) {
|
100
|
+
case ' ':
|
101
|
+
case '\t':
|
102
|
+
case '\f':
|
103
|
+
case '\n':
|
104
|
+
case '\r': break;
|
105
|
+
default: return c;
|
106
|
+
}
|
112
107
|
}
|
113
108
|
return '\0';
|
114
109
|
}
|
@@ -116,107 +111,93 @@ buf_next_non_white(Buf buf) {
|
|
116
111
|
/* Starts by reading a character so it is safe to use with an empty or
|
117
112
|
* compacted buffer.
|
118
113
|
*/
|
119
|
-
static inline char
|
120
|
-
|
121
|
-
char c;
|
114
|
+
static inline char buf_next_white(Buf buf) {
|
115
|
+
char c;
|
122
116
|
|
123
117
|
while ('\0' != (c = buf_get(buf))) {
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
break;
|
134
|
-
}
|
118
|
+
switch (c) {
|
119
|
+
case ' ':
|
120
|
+
case '\t':
|
121
|
+
case '\f':
|
122
|
+
case '\n':
|
123
|
+
case '\r':
|
124
|
+
case '\0': return c;
|
125
|
+
default: break;
|
126
|
+
}
|
135
127
|
}
|
136
128
|
return '\0';
|
137
129
|
}
|
138
130
|
|
139
|
-
static inline void
|
140
|
-
buf_cleanup(Buf buf) {
|
131
|
+
static inline void buf_cleanup(Buf buf) {
|
141
132
|
if (buf->base != buf->head && 0 != buf->head) {
|
142
133
|
xfree(buf->head);
|
143
|
-
|
134
|
+
buf->head = 0;
|
144
135
|
}
|
145
136
|
}
|
146
137
|
|
147
|
-
static inline int
|
148
|
-
|
149
|
-
switch(c) {
|
138
|
+
static inline int is_white(char c) {
|
139
|
+
switch (c) {
|
150
140
|
case ' ':
|
151
141
|
case '\t':
|
152
142
|
case '\f':
|
153
143
|
case '\n':
|
154
|
-
case '\r':
|
155
|
-
|
156
|
-
default:
|
157
|
-
break;
|
144
|
+
case '\r': return 1;
|
145
|
+
default: break;
|
158
146
|
}
|
159
147
|
return 0;
|
160
148
|
}
|
161
149
|
|
162
|
-
static inline void
|
163
|
-
buf_checkpoint(Buf buf, CheckPt cp) {
|
150
|
+
static inline void buf_checkpoint(Buf buf, CheckPt cp) {
|
164
151
|
cp->pro_dif = (int)(buf->tail - buf->pro);
|
165
|
-
cp->pos
|
166
|
-
cp->line
|
167
|
-
cp->col
|
168
|
-
cp->c
|
152
|
+
cp->pos = buf->pos;
|
153
|
+
cp->line = buf->line;
|
154
|
+
cp->col = buf->col;
|
155
|
+
cp->c = *(buf->tail - 1);
|
169
156
|
}
|
170
157
|
|
171
|
-
static inline int
|
172
|
-
buf_checkset(CheckPt cp) {
|
158
|
+
static inline int buf_checkset(CheckPt cp) {
|
173
159
|
return (0 <= cp->pro_dif);
|
174
160
|
}
|
175
161
|
|
176
|
-
static inline char
|
177
|
-
buf_checkback(Buf buf, CheckPt cp) {
|
162
|
+
static inline char buf_checkback(Buf buf, CheckPt cp) {
|
178
163
|
buf->tail = buf->pro + cp->pro_dif;
|
179
|
-
buf->pos
|
164
|
+
buf->pos = cp->pos;
|
180
165
|
buf->line = cp->line;
|
181
|
-
buf->col
|
166
|
+
buf->col = cp->col;
|
182
167
|
return cp->c;
|
183
168
|
}
|
184
169
|
|
185
|
-
static inline void
|
186
|
-
|
187
|
-
char
|
188
|
-
char *back = str;
|
170
|
+
static inline void buf_collapse_return(char *str) {
|
171
|
+
char *s = str;
|
172
|
+
char *back = str;
|
189
173
|
|
190
174
|
for (; '\0' != *s; s++) {
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
175
|
+
if (back != str && '\n' == *s && '\r' == *(back - 1)) {
|
176
|
+
*(back - 1) = '\n';
|
177
|
+
} else {
|
178
|
+
*back++ = *s;
|
179
|
+
}
|
196
180
|
}
|
197
181
|
*back = '\0';
|
198
182
|
}
|
199
183
|
|
200
|
-
static inline void
|
201
|
-
|
202
|
-
char
|
203
|
-
char *back = str;
|
184
|
+
static inline void buf_collapse_white(char *str) {
|
185
|
+
char *s = str;
|
186
|
+
char *back = str;
|
204
187
|
|
205
188
|
for (; '\0' != *s; s++) {
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
break;
|
219
|
-
}
|
189
|
+
switch (*s) {
|
190
|
+
case ' ':
|
191
|
+
case '\t':
|
192
|
+
case '\f':
|
193
|
+
case '\n':
|
194
|
+
case '\r':
|
195
|
+
if (back == str || ' ' != *(back - 1)) {
|
196
|
+
*back++ = ' ';
|
197
|
+
}
|
198
|
+
break;
|
199
|
+
default: *back++ = *s; break;
|
200
|
+
}
|
220
201
|
}
|
221
202
|
*back = '\0';
|
222
203
|
}
|