commonmarker 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of commonmarker might be problematic. Click here for more details.

Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/ext/commonmarker/cmark/CMakeLists.txt +10 -4
  3. data/ext/commonmarker/cmark/Makefile +5 -5
  4. data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
  5. data/ext/commonmarker/cmark/api_test/main.c +16 -0
  6. data/ext/commonmarker/cmark/build/CMakeCache.txt +3 -4
  7. data/ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CMakeSystem.cmake +4 -4
  8. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +12 -12
  9. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +97 -142
  10. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +0 -1
  11. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +1 -1
  12. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
  13. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +1 -1
  14. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +23 -23
  15. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +2 -2
  16. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
  17. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
  18. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/buffer.c.o +0 -0
  19. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
  20. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
  21. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_u.c.o +0 -0
  22. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
  23. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
  24. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
  25. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/references.c.o +0 -0
  26. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/render.c.o +0 -0
  27. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
  28. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/utf8.c.o +0 -0
  29. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
  30. data/ext/commonmarker/cmark/build/src/cmake_install.cmake +3 -3
  31. data/ext/commonmarker/cmark/build/src/cmark_version.h +2 -2
  32. data/ext/commonmarker/cmark/build/src/config.h +6 -6
  33. data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
  34. data/ext/commonmarker/cmark/build/src/libcmark.pc +1 -1
  35. data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +4 -4
  36. data/ext/commonmarker/cmark/changelog.txt +46 -0
  37. data/ext/commonmarker/cmark/man/man3/cmark.3 +21 -20
  38. data/ext/commonmarker/cmark/src/CMakeLists.txt +4 -6
  39. data/ext/commonmarker/cmark/src/bench.h +8 -8
  40. data/ext/commonmarker/cmark/src/blocks.c +917 -947
  41. data/ext/commonmarker/cmark/src/buffer.c +213 -288
  42. data/ext/commonmarker/cmark/src/buffer.h +19 -21
  43. data/ext/commonmarker/cmark/src/chunk.h +78 -82
  44. data/ext/commonmarker/cmark/src/cmark.c +9 -17
  45. data/ext/commonmarker/cmark/src/cmark.h +113 -157
  46. data/ext/commonmarker/cmark/src/cmark_ctype.c +24 -35
  47. data/ext/commonmarker/cmark/src/commonmark.c +390 -425
  48. data/ext/commonmarker/cmark/src/config.h.in +6 -6
  49. data/ext/commonmarker/cmark/src/houdini.h +21 -15
  50. data/ext/commonmarker/cmark/src/houdini_href_e.c +50 -57
  51. data/ext/commonmarker/cmark/src/houdini_html_e.c +36 -51
  52. data/ext/commonmarker/cmark/src/houdini_html_u.c +119 -124
  53. data/ext/commonmarker/cmark/src/html.c +289 -307
  54. data/ext/commonmarker/cmark/src/inlines.c +976 -1030
  55. data/ext/commonmarker/cmark/src/inlines.h +4 -2
  56. data/ext/commonmarker/cmark/src/iterator.c +96 -126
  57. data/ext/commonmarker/cmark/src/iterator.h +5 -5
  58. data/ext/commonmarker/cmark/src/latex.c +379 -401
  59. data/ext/commonmarker/cmark/src/main.c +168 -175
  60. data/ext/commonmarker/cmark/src/man.c +212 -226
  61. data/ext/commonmarker/cmark/src/node.c +746 -839
  62. data/ext/commonmarker/cmark/src/node.h +47 -48
  63. data/ext/commonmarker/cmark/src/parser.h +14 -14
  64. data/ext/commonmarker/cmark/src/references.c +101 -111
  65. data/ext/commonmarker/cmark/src/references.h +10 -8
  66. data/ext/commonmarker/cmark/src/render.c +144 -167
  67. data/ext/commonmarker/cmark/src/render.h +22 -41
  68. data/ext/commonmarker/cmark/src/scanners.c +27695 -20903
  69. data/ext/commonmarker/cmark/src/scanners.h +2 -1
  70. data/ext/commonmarker/cmark/src/scanners.re +1 -1
  71. data/ext/commonmarker/cmark/src/utf8.c +276 -419
  72. data/ext/commonmarker/cmark/src/utf8.h +6 -6
  73. data/ext/commonmarker/cmark/src/xml.c +129 -144
  74. data/ext/commonmarker/cmark/test/CMakeLists.txt +4 -4
  75. data/ext/commonmarker/cmark/test/smart_punct.txt +8 -0
  76. data/ext/commonmarker/cmark/test/spec.txt +109 -47
  77. data/lib/commonmarker/version.rb +1 -1
  78. metadata +2 -2
@@ -16,371 +16,296 @@
16
16
  unsigned char cmark_strbuf__initbuf[1];
17
17
 
18
18
  #ifndef MIN
19
- #define MIN(x,y) ((x<y) ? x : y)
19
+ #define MIN(x, y) ((x < y) ? x : y)
20
20
  #endif
21
21
 
22
- void cmark_strbuf_init(cmark_strbuf *buf, bufsize_t initial_size)
23
- {
24
- buf->asize = 0;
25
- buf->size = 0;
26
- buf->ptr = cmark_strbuf__initbuf;
22
+ void cmark_strbuf_init(cmark_strbuf *buf, bufsize_t initial_size) {
23
+ buf->asize = 0;
24
+ buf->size = 0;
25
+ buf->ptr = cmark_strbuf__initbuf;
27
26
 
28
- if (initial_size > 0)
29
- cmark_strbuf_grow(buf, initial_size);
27
+ if (initial_size > 0)
28
+ cmark_strbuf_grow(buf, initial_size);
30
29
  }
31
30
 
32
- void cmark_strbuf_overflow_err()
33
- {
34
- fprintf(stderr, "String buffer overflow");
35
- abort();
31
+ void cmark_strbuf_overflow_err() {
32
+ fprintf(stderr, "String buffer overflow");
33
+ abort();
36
34
  }
37
35
 
38
- static inline void
39
- S_strbuf_grow_by(cmark_strbuf *buf, size_t add)
40
- {
41
- size_t target_size = (size_t)buf->size + add;
36
+ static inline void S_strbuf_grow_by(cmark_strbuf *buf, size_t add) {
37
+ size_t target_size = (size_t)buf->size + add;
42
38
 
43
- if (target_size < add /* Integer overflow. */
44
- || target_size > BUFSIZE_MAX /* Truncation overflow. */
45
- ) {
46
- cmark_strbuf_overflow_err();
47
- return; /* unreachable */
48
- }
39
+ if (target_size < add /* Integer overflow. */
40
+ || target_size > BUFSIZE_MAX /* Truncation overflow. */
41
+ ) {
42
+ cmark_strbuf_overflow_err();
43
+ return; /* unreachable */
44
+ }
49
45
 
50
- if ((bufsize_t)target_size >= buf->asize)
51
- cmark_strbuf_grow(buf, (bufsize_t)target_size);
46
+ if ((bufsize_t)target_size >= buf->asize)
47
+ cmark_strbuf_grow(buf, (bufsize_t)target_size);
52
48
  }
53
49
 
54
- void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size)
55
- {
56
- unsigned char *new_ptr;
57
-
58
- if (target_size < buf->asize)
59
- return;
60
-
61
- if (buf->asize == 0) {
62
- new_ptr = NULL;
63
- } else {
64
- new_ptr = buf->ptr;
65
- }
66
-
67
- /* Oversize the buffer by 50% to guarantee amortized linear time
68
- * complexity on append operations. */
69
- size_t new_size = (size_t)target_size + (size_t)target_size / 2;
70
-
71
- /* Account for terminating null byte. */
72
- new_size += 1;
73
-
74
- /* round allocation up to multiple of 8 */
75
- new_size = (new_size + 7) & ~7;
76
-
77
- if (new_size < (size_t)target_size /* Integer overflow. */
78
- || new_size > BUFSIZE_MAX /* Truncation overflow. */
79
- ) {
80
- if (target_size >= BUFSIZE_MAX) {
81
- /* No space for terminating null byte. */
82
- cmark_strbuf_overflow_err();
83
- return; /* unreachable */
84
- }
85
- /* Oversize by the maximum possible amount. */
86
- new_size = BUFSIZE_MAX;
87
- }
88
-
89
- new_ptr = (unsigned char *)realloc(new_ptr, new_size);
90
-
91
- if (!new_ptr) {
92
- perror("realloc in cmark_strbuf_grow");
93
- abort();
94
- }
95
-
96
- buf->asize = (bufsize_t)new_size;
97
- buf->ptr = new_ptr;
50
+ void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size) {
51
+ unsigned char *new_ptr;
52
+
53
+ if (target_size < buf->asize)
54
+ return;
55
+
56
+ if (buf->asize == 0) {
57
+ new_ptr = NULL;
58
+ } else {
59
+ new_ptr = buf->ptr;
60
+ }
61
+
62
+ /* Oversize the buffer by 50% to guarantee amortized linear time
63
+ * complexity on append operations. */
64
+ size_t new_size = (size_t)target_size + (size_t)target_size / 2;
65
+
66
+ /* Account for terminating null byte. */
67
+ new_size += 1;
68
+
69
+ /* round allocation up to multiple of 8 */
70
+ new_size = (new_size + 7) & ~7;
71
+
72
+ if (new_size < (size_t)target_size /* Integer overflow. */
73
+ || new_size > BUFSIZE_MAX /* Truncation overflow. */
74
+ ) {
75
+ if (target_size >= BUFSIZE_MAX) {
76
+ /* No space for terminating null byte. */
77
+ cmark_strbuf_overflow_err();
78
+ return; /* unreachable */
79
+ }
80
+ /* Oversize by the maximum possible amount. */
81
+ new_size = BUFSIZE_MAX;
82
+ }
83
+
84
+ new_ptr = (unsigned char *)realloc(new_ptr, new_size);
85
+
86
+ if (!new_ptr) {
87
+ perror("realloc in cmark_strbuf_grow");
88
+ abort();
89
+ }
90
+
91
+ buf->asize = (bufsize_t)new_size;
92
+ buf->ptr = new_ptr;
98
93
  }
99
94
 
100
- bufsize_t cmark_strbuf_len(const cmark_strbuf *buf)
101
- {
102
- return buf->size;
103
- }
95
+ bufsize_t cmark_strbuf_len(const cmark_strbuf *buf) { return buf->size; }
104
96
 
105
- void cmark_strbuf_free(cmark_strbuf *buf)
106
- {
107
- if (!buf) return;
97
+ void cmark_strbuf_free(cmark_strbuf *buf) {
98
+ if (!buf)
99
+ return;
108
100
 
109
- if (buf->ptr != cmark_strbuf__initbuf)
110
- free(buf->ptr);
101
+ if (buf->ptr != cmark_strbuf__initbuf)
102
+ free(buf->ptr);
111
103
 
112
- cmark_strbuf_init(buf, 0);
104
+ cmark_strbuf_init(buf, 0);
113
105
  }
114
106
 
115
- void cmark_strbuf_clear(cmark_strbuf *buf)
116
- {
117
- buf->size = 0;
107
+ void cmark_strbuf_clear(cmark_strbuf *buf) {
108
+ buf->size = 0;
118
109
 
119
- if (buf->asize > 0)
120
- buf->ptr[0] = '\0';
110
+ if (buf->asize > 0)
111
+ buf->ptr[0] = '\0';
121
112
  }
122
113
 
123
- void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, bufsize_t len)
124
- {
125
- if (len <= 0 || data == NULL) {
126
- cmark_strbuf_clear(buf);
127
- } else {
128
- if (data != buf->ptr) {
129
- if (len >= buf->asize)
130
- cmark_strbuf_grow(buf, len);
131
- memmove(buf->ptr, data, len);
132
- }
133
- buf->size = len;
134
- buf->ptr[buf->size] = '\0';
135
- }
114
+ void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,
115
+ bufsize_t len) {
116
+ if (len <= 0 || data == NULL) {
117
+ cmark_strbuf_clear(buf);
118
+ } else {
119
+ if (data != buf->ptr) {
120
+ if (len >= buf->asize)
121
+ cmark_strbuf_grow(buf, len);
122
+ memmove(buf->ptr, data, len);
123
+ }
124
+ buf->size = len;
125
+ buf->ptr[buf->size] = '\0';
126
+ }
136
127
  }
137
128
 
138
- void cmark_strbuf_sets(cmark_strbuf *buf, const char *string)
139
- {
140
- cmark_strbuf_set(buf, (const unsigned char *)string,
141
- string ? cmark_strbuf_safe_strlen(string) : 0);
129
+ void cmark_strbuf_sets(cmark_strbuf *buf, const char *string) {
130
+ cmark_strbuf_set(buf, (const unsigned char *)string,
131
+ string ? cmark_strbuf_safe_strlen(string) : 0);
142
132
  }
143
133
 
144
- void cmark_strbuf_putc(cmark_strbuf *buf, int c)
145
- {
146
- S_strbuf_grow_by(buf, 1);
147
- buf->ptr[buf->size++] = c;
148
- buf->ptr[buf->size] = '\0';
134
+ void cmark_strbuf_putc(cmark_strbuf *buf, int c) {
135
+ S_strbuf_grow_by(buf, 1);
136
+ buf->ptr[buf->size++] = (unsigned char)(c & 0xFF);
137
+ buf->ptr[buf->size] = '\0';
149
138
  }
150
139
 
151
- void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, bufsize_t len)
152
- {
153
- if (len <= 0)
154
- return;
140
+ void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data,
141
+ bufsize_t len) {
142
+ if (len <= 0)
143
+ return;
155
144
 
156
- S_strbuf_grow_by(buf, len);
157
- memmove(buf->ptr + buf->size, data, len);
158
- buf->size += len;
159
- buf->ptr[buf->size] = '\0';
145
+ S_strbuf_grow_by(buf, len);
146
+ memmove(buf->ptr + buf->size, data, len);
147
+ buf->size += len;
148
+ buf->ptr[buf->size] = '\0';
160
149
  }
161
150
 
162
- void cmark_strbuf_puts(cmark_strbuf *buf, const char *string)
163
- {
164
- cmark_strbuf_put(buf, (const unsigned char *)string,
165
- cmark_strbuf_safe_strlen(string));
151
+ void cmark_strbuf_puts(cmark_strbuf *buf, const char *string) {
152
+ cmark_strbuf_put(buf, (const unsigned char *)string,
153
+ cmark_strbuf_safe_strlen(string));
166
154
  }
167
155
 
168
- void cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap)
169
- {
170
- size_t expected_size = strlen(format);
171
- if (expected_size <= SIZE_MAX / 2)
172
- expected_size *= 2;
173
- S_strbuf_grow_by(buf, expected_size);
174
-
175
- while (1) {
176
- va_list args;
177
- va_copy(args, ap);
178
-
179
- int len = vsnprintf(
180
- (char *)buf->ptr + buf->size,
181
- buf->asize - buf->size,
182
- format, args
183
- );
184
- #ifndef HAVE_C99_SNPRINTF
185
- // Assume we're on Windows.
186
- if (len < 0) {
187
- len = _vscprintf(format, args);
188
- }
189
- #endif
156
+ void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,
157
+ const cmark_strbuf *buf) {
158
+ bufsize_t copylen;
190
159
 
191
- va_end(args);
160
+ assert(buf);
161
+ if (!data || datasize <= 0)
162
+ return;
192
163
 
193
- if (len < 0) {
194
- perror("vsnprintf in cmark_strbuf_vprintf");
195
- abort();
196
- }
164
+ data[0] = '\0';
197
165
 
198
- if ((size_t)len < (size_t)(buf->asize - buf->size)) {
199
- buf->size += len;
200
- break;
201
- }
166
+ if (buf->size == 0 || buf->asize <= 0)
167
+ return;
202
168
 
203
- S_strbuf_grow_by(buf, len);
204
- }
169
+ copylen = buf->size;
170
+ if (copylen > datasize - 1)
171
+ copylen = datasize - 1;
172
+ memmove(data, buf->ptr, copylen);
173
+ data[copylen] = '\0';
205
174
  }
206
175
 
207
- void cmark_strbuf_printf(cmark_strbuf *buf, const char *format, ...)
208
- {
209
- va_list ap;
210
-
211
- va_start(ap, format);
212
- cmark_strbuf_vprintf(buf, format, ap);
213
- va_end(ap);
176
+ void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b) {
177
+ cmark_strbuf t = *buf_a;
178
+ *buf_a = *buf_b;
179
+ *buf_b = t;
214
180
  }
215
181
 
216
- void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize, const cmark_strbuf *buf)
217
- {
218
- bufsize_t copylen;
219
-
220
- assert(buf);
221
- if (!data || datasize <= 0)
222
- return;
223
-
224
- data[0] = '\0';
182
+ unsigned char *cmark_strbuf_detach(cmark_strbuf *buf) {
183
+ unsigned char *data = buf->ptr;
225
184
 
226
- if (buf->size == 0 || buf->asize <= 0)
227
- return;
185
+ if (buf->asize == 0) {
186
+ /* return an empty string */
187
+ return (unsigned char *)calloc(1, 1);
188
+ }
228
189
 
229
- copylen = buf->size;
230
- if (copylen > datasize - 1)
231
- copylen = datasize - 1;
232
- memmove(data, buf->ptr, copylen);
233
- data[copylen] = '\0';
190
+ cmark_strbuf_init(buf, 0);
191
+ return data;
234
192
  }
235
193
 
236
- void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b)
237
- {
238
- cmark_strbuf t = *buf_a;
239
- *buf_a = *buf_b;
240
- *buf_b = t;
194
+ int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b) {
195
+ int result = memcmp(a->ptr, b->ptr, MIN(a->size, b->size));
196
+ return (result != 0) ? result
197
+ : (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
241
198
  }
242
199
 
243
- unsigned char *cmark_strbuf_detach(cmark_strbuf *buf)
244
- {
245
- unsigned char *data = buf->ptr;
200
+ bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos) {
201
+ if (pos >= buf->size)
202
+ return -1;
203
+ if (pos < 0)
204
+ pos = 0;
246
205
 
247
- if (buf->asize == 0) {
248
- /* return an empty string */
249
- return (unsigned char *)calloc(1, 1);
250
- }
206
+ const unsigned char *p =
207
+ (unsigned char *)memchr(buf->ptr + pos, c, buf->size - pos);
208
+ if (!p)
209
+ return -1;
251
210
 
252
- cmark_strbuf_init(buf, 0);
253
- return data;
211
+ return (bufsize_t)(p - (const unsigned char *)buf->ptr);
254
212
  }
255
213
 
256
- int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b)
257
- {
258
- int result = memcmp(a->ptr, b->ptr, MIN(a->size, b->size));
259
- return (result != 0) ? result :
260
- (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0;
261
- }
262
-
263
- bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos)
264
- {
265
- if (pos >= buf->size)
266
- return -1;
267
- if (pos < 0)
268
- pos = 0;
214
+ bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos) {
215
+ if (pos < 0 || buf->size == 0)
216
+ return -1;
217
+ if (pos >= buf->size)
218
+ pos = buf->size - 1;
269
219
 
270
- const unsigned char *p = (unsigned char *)memchr(buf->ptr + pos, c, buf->size - pos);
271
- if (!p)
272
- return -1;
220
+ for (bufsize_t i = pos; i >= 0; i--) {
221
+ if (buf->ptr[i] == (unsigned char)c)
222
+ return i;
223
+ }
273
224
 
274
- return (bufsize_t)(p - (const unsigned char *)buf->ptr);
225
+ return -1;
275
226
  }
276
227
 
277
- bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos)
278
- {
279
- if (pos < 0 || buf->size == 0)
280
- return -1;
281
- if (pos >= buf->size)
282
- pos = buf->size - 1;
283
-
284
- for (bufsize_t i = pos; i >= 0; i--) {
285
- if (buf->ptr[i] == (unsigned char) c)
286
- return i;
287
- }
228
+ void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len) {
229
+ if (len < 0)
230
+ len = 0;
288
231
 
289
- return -1;
232
+ if (len < buf->size) {
233
+ buf->size = len;
234
+ buf->ptr[buf->size] = '\0';
235
+ }
290
236
  }
291
237
 
292
- void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len)
293
- {
294
- if (len < 0)
295
- len = 0;
296
-
297
- if (len < buf->size) {
298
- buf->size = len;
299
- buf->ptr[buf->size] = '\0';
300
- }
301
- }
238
+ void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n) {
239
+ if (n > 0) {
240
+ if (n > buf->size)
241
+ n = buf->size;
242
+ buf->size = buf->size - n;
243
+ if (buf->size)
244
+ memmove(buf->ptr, buf->ptr + n, buf->size);
302
245
 
303
- void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n)
304
- {
305
- if (n > 0) {
306
- if (n > buf->size)
307
- n = buf->size;
308
- buf->size = buf->size - n;
309
- if (buf->size)
310
- memmove(buf->ptr, buf->ptr + n, buf->size);
311
-
312
- buf->ptr[buf->size] = '\0';
313
- }
246
+ buf->ptr[buf->size] = '\0';
247
+ }
314
248
  }
315
249
 
316
- void cmark_strbuf_rtrim(cmark_strbuf *buf)
317
- {
318
- if (!buf->size)
319
- return;
250
+ void cmark_strbuf_rtrim(cmark_strbuf *buf) {
251
+ if (!buf->size)
252
+ return;
320
253
 
321
- while (buf->size > 0) {
322
- if (!cmark_isspace(buf->ptr[buf->size - 1]))
323
- break;
254
+ while (buf->size > 0) {
255
+ if (!cmark_isspace(buf->ptr[buf->size - 1]))
256
+ break;
324
257
 
325
- buf->size--;
326
- }
258
+ buf->size--;
259
+ }
327
260
 
328
- buf->ptr[buf->size] = '\0';
261
+ buf->ptr[buf->size] = '\0';
329
262
  }
330
263
 
331
- void cmark_strbuf_trim(cmark_strbuf *buf)
332
- {
333
- bufsize_t i = 0;
264
+ void cmark_strbuf_trim(cmark_strbuf *buf) {
265
+ bufsize_t i = 0;
334
266
 
335
- if (!buf->size)
336
- return;
267
+ if (!buf->size)
268
+ return;
337
269
 
338
- while (i < buf->size && cmark_isspace(buf->ptr[i]))
339
- i++;
270
+ while (i < buf->size && cmark_isspace(buf->ptr[i]))
271
+ i++;
340
272
 
341
- cmark_strbuf_drop(buf, i);
273
+ cmark_strbuf_drop(buf, i);
342
274
 
343
- cmark_strbuf_rtrim(buf);
275
+ cmark_strbuf_rtrim(buf);
344
276
  }
345
277
 
346
278
  // Destructively modify string, collapsing consecutive
347
279
  // space and newline characters into a single space.
348
- void cmark_strbuf_normalize_whitespace(cmark_strbuf *s)
349
- {
350
- bool last_char_was_space = false;
351
- bufsize_t r, w;
352
-
353
- for (r = 0, w = 0; r < s->size; ++r) {
354
- switch (s->ptr[r]) {
355
- case ' ':
356
- case '\n':
357
- if (last_char_was_space)
358
- break;
359
-
360
- s->ptr[w++] = ' ';
361
- last_char_was_space = true;
362
- break;
363
-
364
- default:
365
- s->ptr[w++] = s->ptr[r];
366
- last_char_was_space = false;
367
- }
368
- }
369
-
370
- cmark_strbuf_truncate(s, w);
280
+ void cmark_strbuf_normalize_whitespace(cmark_strbuf *s) {
281
+ bool last_char_was_space = false;
282
+ bufsize_t r, w;
283
+
284
+ for (r = 0, w = 0; r < s->size; ++r) {
285
+ if (cmark_isspace(s->ptr[r])) {
286
+ if (!last_char_was_space) {
287
+ s->ptr[w++] = ' ';
288
+ last_char_was_space = true;
289
+ }
290
+ } else {
291
+ s->ptr[w++] = s->ptr[r];
292
+ last_char_was_space = false;
293
+ }
294
+ }
295
+
296
+ cmark_strbuf_truncate(s, w);
371
297
  }
372
298
 
373
299
  // Destructively unescape a string: remove backslashes before punctuation chars.
374
- extern void cmark_strbuf_unescape(cmark_strbuf *buf)
375
- {
376
- bufsize_t r, w;
300
+ extern void cmark_strbuf_unescape(cmark_strbuf *buf) {
301
+ bufsize_t r, w;
377
302
 
378
- for (r = 0, w = 0; r < buf->size; ++r) {
379
- if (buf->ptr[r] == '\\' && cmark_ispunct(buf->ptr[r + 1]))
380
- r++;
303
+ for (r = 0, w = 0; r < buf->size; ++r) {
304
+ if (buf->ptr[r] == '\\' && cmark_ispunct(buf->ptr[r + 1]))
305
+ r++;
381
306
 
382
- buf->ptr[w++] = buf->ptr[r];
383
- }
307
+ buf->ptr[w++] = buf->ptr[r];
308
+ }
384
309
 
385
- cmark_strbuf_truncate(buf, w);
310
+ cmark_strbuf_truncate(buf, w);
386
311
  }
@@ -14,13 +14,14 @@ extern "C" {
14
14
  typedef int bufsize_t;
15
15
 
16
16
  typedef struct {
17
- unsigned char *ptr;
18
- bufsize_t asize, size;
17
+ unsigned char *ptr;
18
+ bufsize_t asize, size;
19
19
  } cmark_strbuf;
20
20
 
21
21
  extern unsigned char cmark_strbuf__initbuf[];
22
22
 
23
- #define GH_BUF_INIT { cmark_strbuf__initbuf, 0, 0 }
23
+ #define GH_BUF_INIT \
24
+ { cmark_strbuf__initbuf, 0, 0 }
24
25
  #define BUFSIZE_MAX INT_MAX
25
26
 
26
27
  /**
@@ -44,23 +45,22 @@ bufsize_t cmark_strbuf_len(const cmark_strbuf *buf);
44
45
  int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b);
45
46
 
46
47
  unsigned char *cmark_strbuf_detach(cmark_strbuf *buf);
47
- void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize, const cmark_strbuf *buf);
48
+ void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize,
49
+ const cmark_strbuf *buf);
48
50
 
49
- static inline const char *cmark_strbuf_cstr(const cmark_strbuf *buf)
50
- {
51
- return (char *)buf->ptr;
51
+ static CMARK_INLINE const char *cmark_strbuf_cstr(const cmark_strbuf *buf) {
52
+ return (char *)buf->ptr;
52
53
  }
53
54
 
54
55
  #define cmark_strbuf_at(buf, n) ((buf)->ptr[n])
55
56
 
56
- void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, bufsize_t len);
57
+ void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data,
58
+ bufsize_t len);
57
59
  void cmark_strbuf_sets(cmark_strbuf *buf, const char *string);
58
60
  void cmark_strbuf_putc(cmark_strbuf *buf, int c);
59
- void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, bufsize_t len);
61
+ void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data,
62
+ bufsize_t len);
60
63
  void cmark_strbuf_puts(cmark_strbuf *buf, const char *string);
61
- void cmark_strbuf_printf(cmark_strbuf *buf, const char *format, ...)
62
- CMARK_ATTRIBUTE((format (printf, 2, 3)));
63
- void cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap);
64
64
  void cmark_strbuf_clear(cmark_strbuf *buf);
65
65
 
66
66
  bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos);
@@ -75,17 +75,15 @@ void cmark_strbuf_unescape(cmark_strbuf *s);
75
75
  /* Print error and abort. */
76
76
  void cmark_strbuf_overflow_err(void);
77
77
 
78
- static inline bufsize_t
79
- cmark_strbuf_check_bufsize(size_t size) {
80
- if (size > BUFSIZE_MAX) {
81
- cmark_strbuf_overflow_err();
82
- }
83
- return (bufsize_t)size;
78
+ static CMARK_INLINE bufsize_t cmark_strbuf_check_bufsize(size_t size) {
79
+ if (size > BUFSIZE_MAX) {
80
+ cmark_strbuf_overflow_err();
81
+ }
82
+ return (bufsize_t)size;
84
83
  }
85
84
 
86
- static inline bufsize_t
87
- cmark_strbuf_safe_strlen(const char *str) {
88
- return cmark_strbuf_check_bufsize(strlen(str));
85
+ static CMARK_INLINE bufsize_t cmark_strbuf_safe_strlen(const char *str) {
86
+ return cmark_strbuf_check_bufsize(strlen(str));
89
87
  }
90
88
 
91
89
  #ifdef __cplusplus