Changeset 264 for libyaml/trunk/src/emitter.c
- Timestamp:
- 12/27/07 12:14:01 (5 years ago)
- File:
-
- 1 edited
-
libyaml/trunk/src/emitter.c (modified) (43 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/src/emitter.c
r263 r264 14 14 */ 15 15 16 #define PUT(emitter, value)\16 #define PUT(emitter, value) \ 17 17 (FLUSH(emitter) \ 18 && (JOIN_OCTET(emitter->output, (yaml_char_t)(value)),\18 && (JOIN_OCTET(emitter->output, (yaml_char_t)(value)), \ 19 19 emitter->column ++, \ 20 20 1)) … … 41 41 */ 42 42 43 #define WRITE(emitter, string)\43 #define WRITE(emitter, string) \ 44 44 (FLUSH(emitter) \ 45 && (COPY(emitter->output, string),\45 && (COPY(emitter->output, string), \ 46 46 emitter->column ++, \ 47 47 1)) … … 51 51 */ 52 52 53 #define WRITE_BREAK(emitter, string)\53 #define WRITE_BREAK(emitter, string) \ 54 54 (FLUSH(emitter) \ 55 && (CHECK(string, '\n') ?\55 && (CHECK(string, '\n') ? \ 56 56 (PUT_BREAK(emitter), \ 57 57 string.pointer ++, \ 58 58 1) : \ 59 (COPY(emitter->output, string),\59 (COPY(emitter->output, string), \ 60 60 emitter->column = 0, \ 61 61 emitter->line ++, \ … … 67 67 68 68 YAML_DECLARE(int) 69 yaml_emitter_emit (yaml_emitter_t *emitter, yaml_event_t *event);69 yaml_emitter_emit_event(yaml_emitter_t *emitter, yaml_event_t *event); 70 70 71 71 /* … … 219 219 static int 220 220 yaml_emitter_write_indicator(yaml_emitter_t *emitter, 221 c har *indicator, int need_whitespace,221 const char *indicator, int need_whitespace, 222 222 int is_whitespace, int is_indention); 223 223 224 224 static int 225 225 yaml_emitter_write_anchor(yaml_emitter_t *emitter, 226 yaml_char_t *value, size_t length);226 const yaml_char_t *value, size_t length); 227 227 228 228 static int 229 229 yaml_emitter_write_tag_handle(yaml_emitter_t *emitter, 230 yaml_char_t *value, size_t length);230 const yaml_char_t *value, size_t length); 231 231 232 232 static int 233 233 yaml_emitter_write_tag_content(yaml_emitter_t *emitter, 234 yaml_char_t *value, size_t length, int need_whitespace);234 const yaml_char_t *value, size_t length, int need_whitespace); 235 235 236 236 static int 237 237 yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, 238 yaml_char_t *value, size_t length, int allow_breaks);238 const yaml_char_t *value, size_t length, int allow_breaks); 239 239 240 240 static int 241 241 yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter, 242 yaml_char_t *value, size_t length, int allow_breaks);242 const yaml_char_t *value, size_t length, int allow_breaks); 243 243 244 244 static int 245 245 yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, 246 yaml_char_t *value, size_t length, int allow_breaks);246 const yaml_char_t *value, size_t length, int allow_breaks); 247 247 248 248 static int 249 249 yaml_emitter_determine_chomping(yaml_emitter_t *emitter, 250 yaml_ string_t string);250 yaml_istring_t string); 251 251 252 252 static int 253 253 yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter, 254 yaml_char_t *value, size_t length);254 const yaml_char_t *value, size_t length); 255 255 256 256 static int 257 257 yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, 258 yaml_char_t *value, size_t length);258 const yaml_char_t *value, size_t length); 259 259 260 260 /* … … 263 263 264 264 YAML_DECLARE(int) 265 yaml_emitter_emit (yaml_emitter_t *emitter, yaml_event_t *event)265 yaml_emitter_emit_event(yaml_emitter_t *emitter, yaml_event_t *event) 266 266 { 267 267 if (!ENQUEUE(emitter, emitter->events, *event)) { … … 468 468 469 469 default: 470 assert( 1); /* Invalid state. */470 assert(0); /* Invalid state. */ 471 471 } 472 472 … … 1287 1287 1288 1288 default: 1289 assert( 1); /* Impossible. */1289 assert(0); /* Impossible. */ 1290 1290 } 1291 1291 … … 1316 1316 yaml_tag_directive_t tag_directive) 1317 1317 { 1318 yaml_ string_t handle =STRING(tag_directive.handle,1318 yaml_istring_t handle = ISTRING(tag_directive.handle, 1319 1319 strlen((char *)tag_directive.handle)); 1320 yaml_ string_t prefix =STRING(tag_directive.prefix,1320 yaml_istring_t prefix = ISTRING(tag_directive.prefix, 1321 1321 strlen((char *)tag_directive.prefix)); 1322 1322 1323 if (!handle. capacity) {1323 if (!handle.length) { 1324 1324 return EMITTER_ERROR_INIT(emitter, "tag handle must not be empty"); 1325 1325 } … … 1329 1329 } 1330 1330 1331 if (handle.buffer[handle. capacity-1] != '!') {1331 if (handle.buffer[handle.length-1] != '!') { 1332 1332 return EMITTER_ERROR_INIT(emitter, "tag handle must end with '!'"); 1333 1333 } … … 1335 1335 handle.pointer ++; 1336 1336 1337 while (handle.pointer < handle. capacity-1) {1337 while (handle.pointer < handle.length-1) { 1338 1338 if (!IS_ALPHA(handle)) { 1339 1339 return EMITTER_ERROR_INIT(emitter, … … 1343 1343 } 1344 1344 1345 if (!prefix. capacity) {1345 if (!prefix.length) { 1346 1346 return EMITTER_ERROR_INIT(emitter, "tag prefix must not be empty"); 1347 1347 } … … 1358 1358 yaml_char_t *anchor, int is_alias) 1359 1359 { 1360 yaml_ string_t string =STRING(anchor, strlen((char *)anchor));1361 1362 if (!string. capacity) {1360 yaml_istring_t string = ISTRING(anchor, strlen((char *)anchor)); 1361 1362 if (!string.length) { 1363 1363 return EMITTER_ERROR_INIT(emitter, is_alias ? 1364 1364 "alias value must not be empty" : … … 1366 1366 } 1367 1367 1368 while (string.pointer < string. capacity) {1368 while (string.pointer < string.length) { 1369 1369 if (!IS_ALPHA(string)) { 1370 1370 return EMITTER_ERROR_INIT(emitter, is_alias ? … … 1376 1376 1377 1377 emitter->anchor_data.anchor = string.buffer; 1378 emitter->anchor_data.anchor_length = string. capacity;1378 emitter->anchor_data.anchor_length = string.length; 1379 1379 emitter->anchor_data.is_alias = is_alias; 1380 1380 … … 1390 1390 yaml_char_t *tag) 1391 1391 { 1392 yaml_ string_t string =STRING(tag, strlen((char *)tag));1392 yaml_istring_t string = ISTRING(tag, strlen((char *)tag)); 1393 1393 size_t idx; 1394 1394 1395 if (!string. capacity) {1395 if (!string.length) { 1396 1396 return EMITTER_ERROR_INIT(emitter, "tag value must not be empty"); 1397 1397 } 1398 1398 1399 1399 for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 1400 yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 1400 yaml_tag_directive_t *tag_directive = 1401 STACK_ITER(emitter, emitter->tag_directives, idx); 1401 1402 size_t prefix_length = strlen((char *)tag_directive->prefix); 1402 if (prefix_length < string. capacity1403 if (prefix_length < string.length 1403 1404 && strncmp((char *)tag_directive->prefix, (char *)string.buffer, 1404 1405 prefix_length) == 0) … … 1408 1409 strlen((char *)tag_directive->handle); 1409 1410 emitter->tag_data.suffix = string.buffer + prefix_length; 1410 emitter->tag_data.suffix_length = string. capacity- prefix_length;1411 emitter->tag_data.suffix_length = string.length - prefix_length; 1411 1412 return 1; 1412 1413 } … … 1414 1415 1415 1416 emitter->tag_data.suffix = string.buffer; 1416 emitter->tag_data.suffix_length = string. capacity;1417 emitter->tag_data.suffix_length = string.length; 1417 1418 1418 1419 return 1; … … 1427 1428 yaml_char_t *value, size_t length) 1428 1429 { 1429 yaml_ string_t string =STRING(value, length);1430 yaml_istring_t string = ISTRING(value, length); 1430 1431 1431 1432 int block_indicators = 0; … … 1453 1454 emitter->scalar_data.length = length; 1454 1455 1455 if (!string. capacity)1456 if (!string.length) 1456 1457 { 1457 1458 emitter->scalar_data.is_multiline = 0; … … 1477 1478 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1478 1479 1479 while (string.pointer < string. capacity)1480 while (string.pointer < string.length) 1480 1481 { 1481 1482 if (!string.pointer) … … 1584 1585 } 1585 1586 1586 if ((spaces || breaks) && string.pointer == string. capacity-1)1587 if ((spaces || breaks) && string.pointer == string.length-1) 1587 1588 { 1588 1589 if (spaces && breaks) { … … 1605 1606 preceeded_by_space = IS_BLANKZ(string); 1606 1607 MOVE(string); 1607 if (string.pointer < string. capacity) {1608 if (string.pointer < string.length) { 1608 1609 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1609 1610 } … … 1770 1771 static int 1771 1772 yaml_emitter_write_indicator(yaml_emitter_t *emitter, 1772 c har *indicator, int need_whitespace,1773 const char *indicator, int need_whitespace, 1773 1774 int is_whitespace, int is_indention) 1774 1775 { 1775 yaml_ string_t string =STRING((yaml_char_t *)indicator, strlen(indicator));1776 yaml_istring_t string = ISTRING((yaml_char_t *)indicator, strlen(indicator)); 1776 1777 1777 1778 if (need_whitespace && !emitter->is_whitespace) { … … 1779 1780 } 1780 1781 1781 while (string.pointer < string. capacity) {1782 while (string.pointer < string.length) { 1782 1783 if (!WRITE(emitter, string)) return 0; 1783 1784 } … … 1791 1792 static int 1792 1793 yaml_emitter_write_anchor(yaml_emitter_t *emitter, 1793 yaml_char_t *value, size_t length)1794 { 1795 yaml_ string_t string =STRING(value, length);1796 1797 while (string.pointer < string. capacity) {1794 const yaml_char_t *value, size_t length) 1795 { 1796 yaml_istring_t string = ISTRING(value, length); 1797 1798 while (string.pointer < string.length) { 1798 1799 if (!WRITE(emitter, string)) return 0; 1799 1800 } … … 1807 1808 static int 1808 1809 yaml_emitter_write_tag_handle(yaml_emitter_t *emitter, 1809 yaml_char_t *value, size_t length)1810 { 1811 yaml_ string_t string =STRING(value, length);1810 const yaml_char_t *value, size_t length) 1811 { 1812 yaml_istring_t string = ISTRING(value, length); 1812 1813 1813 1814 if (!emitter->is_whitespace) { … … 1815 1816 } 1816 1817 1817 while (string.pointer < string. capacity) {1818 while (string.pointer < string.length) { 1818 1819 if (!WRITE(emitter, string)) return 0; 1819 1820 } … … 1827 1828 static int 1828 1829 yaml_emitter_write_tag_content(yaml_emitter_t *emitter, 1829 yaml_char_t *value, size_t length,1830 const yaml_char_t *value, size_t length, 1830 1831 int need_whitespace) 1831 1832 { 1832 yaml_ string_t string =STRING(value, length);1833 yaml_istring_t string = ISTRING(value, length); 1833 1834 1834 1835 if (need_whitespace && !emitter->is_whitespace) { … … 1836 1837 } 1837 1838 1838 while (string.pointer < string. capacity) {1839 while (string.pointer < string.length) { 1839 1840 if (IS_ALPHA(string) 1840 1841 || CHECK(string, ';') || CHECK(string, '/') … … 1875 1876 static int 1876 1877 yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, 1877 yaml_char_t *value, size_t length, int allow_breaks)1878 { 1879 yaml_ string_t string =STRING(value, length);1878 const yaml_char_t *value, size_t length, int allow_breaks) 1879 { 1880 yaml_istring_t string = ISTRING(value, length); 1880 1881 int spaces = 0; 1881 1882 int breaks = 0; … … 1885 1886 } 1886 1887 1887 while (string.pointer < string. capacity)1888 while (string.pointer < string.length) 1888 1889 { 1889 1890 if (IS_SPACE(string)) … … 1929 1930 static int 1930 1931 yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter, 1931 yaml_char_t *value, size_t length, int allow_breaks)1932 { 1933 yaml_ string_t string =STRING(value, length);1932 const yaml_char_t *value, size_t length, int allow_breaks) 1933 { 1934 yaml_istring_t string = ISTRING(value, length); 1934 1935 int spaces = 0; 1935 1936 int breaks = 0; … … 1938 1939 return 0; 1939 1940 1940 while (string.pointer < string. capacity)1941 while (string.pointer < string.length) 1941 1942 { 1942 1943 if (IS_SPACE(string)) … … 1944 1945 if (allow_breaks && !spaces 1945 1946 && emitter->column > emitter->best_width 1946 && string.pointer != 0 1947 && string.pointer != string.capacity - 1 1947 && string.pointer > 0 && string.pointer < string.length 1948 1948 && !IS_SPACE_AT(string, 1)) { 1949 1949 if (!yaml_emitter_write_indent(emitter)) return 0; … … 1990 1990 static int 1991 1991 yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, 1992 yaml_char_t *value, size_t length, int allow_breaks)1993 { 1994 yaml_ string_t string =STRING(value, length);1992 const yaml_char_t *value, size_t length, int allow_breaks) 1993 { 1994 yaml_istring_t string = ISTRING(value, length); 1995 1995 int spaces = 0; 1996 1996 … … 1998 1998 return 0; 1999 1999 2000 while (string.pointer < string. capacity)2000 while (string.pointer < string.length) 2001 2001 { 2002 2002 if (!IS_PRINTABLE(string) || (!emitter->is_unicode && !IS_ASCII(string)) … … 2113 2113 if (allow_breaks && !spaces 2114 2114 && emitter->column > emitter->best_width 2115 && string.pointer !=02116 && string.pointer != string.capacity - 1) {2115 && string.pointer > 0 2116 && string.pointer < string.length) { 2117 2117 if (!yaml_emitter_write_indent(emitter)) return 0; 2118 2118 if (IS_SPACE_AT(string, 1)) { … … 2144 2144 static int 2145 2145 yaml_emitter_determine_chomping(yaml_emitter_t *emitter, 2146 yaml_ string_t string)2147 { 2148 string.pointer = string. capacity;2146 yaml_istring_t string) 2147 { 2148 string.pointer = string.length; 2149 2149 if (!string.pointer) 2150 2150 return -1; … … 2167 2167 static int 2168 2168 yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter, 2169 yaml_char_t *value, size_t length)2170 { 2171 yaml_ string_t string =STRING(value, length);2169 const yaml_char_t *value, size_t length) 2170 { 2171 yaml_istring_t string = ISTRING(value, length); 2172 2172 int chomp = yaml_emitter_determine_chomping(emitter, string); 2173 2173 int breaks = 0; … … 2179 2179 return 0; 2180 2180 2181 while (string.pointer < string. capacity)2181 while (string.pointer < string.length) 2182 2182 { 2183 2183 if (IS_BREAK(string)) … … 2203 2203 static int 2204 2204 yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, 2205 yaml_char_t *value, size_t length)2206 { 2207 yaml_ string_t string =STRING(value, length);2205 const yaml_char_t *value, size_t length) 2206 { 2207 yaml_istring_t string = ISTRING(value, length); 2208 2208 int chomp = yaml_emitter_determine_chomping(emitter, string); 2209 2209 int breaks = 1; … … 2216 2216 return 0; 2217 2217 2218 while (string.pointer < string. capacity)2218 while (string.pointer < string.length) 2219 2219 { 2220 2220 if (IS_BREAK(string))
Note: See TracChangeset
for help on using the changeset viewer.
