Changeset 263 for libyaml/trunk/src/emitter.c
- Timestamp:
- 12/27/07 07:05:17 (5 years ago)
- File:
-
- 1 edited
-
libyaml/trunk/src/emitter.c (modified) (91 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/src/emitter.c
r241 r263 7 7 8 8 #define FLUSH(emitter) \ 9 ((emitter-> buffer.pointer+5 < emitter->buffer.end)\9 ((emitter->output.pointer+5 < emitter->output.capacity) \ 10 10 || yaml_emitter_flush(emitter)) 11 11 … … 16 16 #define PUT(emitter,value) \ 17 17 (FLUSH(emitter) \ 18 && ( *(emitter->buffer.pointer++) = (yaml_char_t)(value),\18 && (JOIN_OCTET(emitter->output,(yaml_char_t)(value)), \ 19 19 emitter->column ++, \ 20 20 1)) … … 27 27 (FLUSH(emitter) \ 28 28 && ((emitter->line_break == YAML_CR_BREAK ? \ 29 (*(emitter->buffer.pointer++) = (yaml_char_t) '\r') :\29 JOIN_OCTET(emitter->output, (yaml_char_t) '\r') : \ 30 30 emitter->line_break == YAML_LN_BREAK ? \ 31 (*(emitter->buffer.pointer++) = (yaml_char_t) '\n') :\31 JOIN_OCTET(emitter->output, (yaml_char_t) '\n') : \ 32 32 emitter->line_break == YAML_CRLN_BREAK ? \ 33 ( *(emitter->buffer.pointer++) = (yaml_char_t) '\r',\34 *(emitter->buffer.pointer++) = (yaml_char_t) '\n') : 0),\33 (JOIN_OCTET(emitter->output, (yaml_char_t) '\r'), \ 34 JOIN_OCTET(emitter->output, (yaml_char_t) '\n')) : 0), \ 35 35 emitter->column = 0, \ 36 36 emitter->line ++, \ … … 43 43 #define WRITE(emitter,string) \ 44 44 (FLUSH(emitter) \ 45 && (COPY(emitter-> buffer,string), \45 && (COPY(emitter->output,string), \ 46 46 emitter->column ++, \ 47 47 1)) … … 57 57 string.pointer ++, \ 58 58 1) : \ 59 (COPY(emitter-> buffer,string), \59 (COPY(emitter->output,string), \ 60 60 emitter->column = 0, \ 61 61 emitter->line ++, \ … … 74 74 75 75 static int 76 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem);77 78 static int79 76 yaml_emitter_need_more_events(yaml_emitter_t *emitter); 80 77 … … 136 133 static int 137 134 yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 138 int root, int sequence, int mapping, intsimple_key);135 int is_root, int is_sequence, int is_mapping, int is_simple_key); 139 136 140 137 static int … … 262 259 263 260 /* 264 * Set an emitter error and return 0.265 */266 267 static int268 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem)269 {270 emitter->error = YAML_EMITTER_ERROR;271 emitter->problem = problem;272 273 return 0;274 }275 276 /*277 261 * Emit an event. 278 262 */ … … 287 271 288 272 while (!yaml_emitter_need_more_events(emitter)) { 289 if (!yaml_emitter_analyze_event(emitter, emitter->events.head)) 290 return 0; 291 if (!yaml_emitter_state_machine(emitter, emitter->events.head)) 273 if (!yaml_emitter_analyze_event(emitter, 274 emitter->events.list + emitter->events.head)) 275 return 0; 276 if (!yaml_emitter_state_machine(emitter, 277 emitter->events.list + emitter->events.head)) 292 278 return 0; 293 279 yaml_event_delete(&DEQUEUE(emitter, emitter->events)); … … 311 297 int level = 0; 312 298 int accumulate = 0; 313 yaml_event_t *event;299 size_t idx; 314 300 315 301 if (QUEUE_EMPTY(emitter, emitter->events)) 316 302 return 1; 317 303 318 switch (emitter->events. head->type) {304 switch (emitter->events.list[emitter->events.head].type) { 319 305 case YAML_DOCUMENT_START_EVENT: 320 306 accumulate = 1; … … 333 319 return 0; 334 320 335 for (event = emitter->events.head; event != emitter->events.tail; event ++) { 321 for (idx = emitter->events.head; idx < emitter->events.tail; idx ++) { 322 yaml_event_t *event = emitter->events.list+idx; 336 323 switch (event->type) { 337 324 case YAML_STREAM_START_EVENT: … … 365 352 yaml_tag_directive_t value, int allow_duplicates) 366 353 { 367 yaml_tag_directive_t *tag_directive;354 int idx; 368 355 yaml_tag_directive_t copy = { NULL, NULL }; 369 356 370 for ( tag_directive = emitter->tag_directives.start;371 tag_directive != emitter->tag_directives.top; tag_directive ++) {357 for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 358 yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 372 359 if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 373 360 if (allow_duplicates) 374 361 return 1; 375 return yaml_emitter_set_emitter_error(emitter, 376 "duplicate %TAG directive"); 362 return EMITTER_ERROR_INIT(emitter, "duplicate %TAG directive"); 377 363 } 378 364 } … … 381 367 copy.prefix = yaml_strdup(value.prefix); 382 368 if (!copy.handle || !copy.prefix) { 383 emitter->error = YAML_MEMORY_ERROR;369 MEMORY_ERROR_INIT(emitter); 384 370 goto error; 385 371 } … … 478 464 479 465 case YAML_EMIT_END_STATE: 480 return yaml_emitter_set_emitter_error(emitter,466 return EMITTER_ERROR_INIT(emitter, 481 467 "expected nothing after STREAM-END"); 482 468 … … 527 513 emitter->line = 0; 528 514 emitter->column = 0; 529 emitter-> whitespace = 1;530 emitter->i ndention = 1;515 emitter->is_whitespace = 1; 516 emitter->is_indention = 1; 531 517 532 518 if (emitter->encoding != YAML_UTF8_ENCODING) { … … 540 526 } 541 527 542 return yaml_emitter_set_emitter_error(emitter, 543 "expected STREAM-START"); 528 return EMITTER_ERROR_INIT(emitter, "expected STREAM-START"); 544 529 } 545 530 … … 560 545 }; 561 546 yaml_tag_directive_t *tag_directive; 562 int implicit; 547 int is_implicit; 548 int idx; 563 549 564 550 if (event->data.document_start.version_directive) { … … 568 554 } 569 555 570 for (tag_directive = event->data.document_start.tag_directives.start; 571 tag_directive != event->data.document_start.tag_directives.end; 572 tag_directive ++) { 556 for (idx = 0; idx < event->data.document_start.tag_directives.length; idx++) { 557 tag_directive = event->data.document_start.tag_directives.list+idx; 573 558 if (!yaml_emitter_analyze_tag_directive(emitter, *tag_directive)) 574 559 return 0; … … 583 568 } 584 569 585 i mplicit = event->data.document_start.implicit;586 if (!first || emitter-> canonical) {587 i mplicit = 0;570 is_implicit = event->data.document_start.is_implicit; 571 if (!first || emitter->is_canonical) { 572 is_implicit = 0; 588 573 } 589 574 590 575 if (event->data.document_start.version_directive) { 591 i mplicit = 0;576 is_implicit = 0; 592 577 if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0)) 593 578 return 0; … … 598 583 } 599 584 600 if (event->data.document_start.tag_directives.start 601 != event->data.document_start.tag_directives.end) { 602 implicit = 0; 603 for (tag_directive = event->data.document_start.tag_directives.start; 604 tag_directive != event->data.document_start.tag_directives.end; 605 tag_directive ++) { 585 if (event->data.document_start.tag_directives.length) { 586 is_implicit = 0; 587 for (idx = 0; idx < event->data.document_start.tag_directives.length; 588 idx++) { 589 tag_directive = event->data.document_start.tag_directives.list+idx; 606 590 if (!yaml_emitter_write_indicator(emitter, "%TAG", 1, 0, 0)) 607 591 return 0; … … 618 602 619 603 if (yaml_emitter_check_empty_document(emitter)) { 620 i mplicit = 0;621 } 622 623 if (!i mplicit) {604 is_implicit = 0; 605 } 606 607 if (!is_implicit) { 624 608 if (!yaml_emitter_write_indent(emitter)) 625 609 return 0; 626 610 if (!yaml_emitter_write_indicator(emitter, "---", 1, 0, 0)) 627 611 return 0; 628 if (emitter-> canonical) {612 if (emitter->is_canonical) { 629 613 if (!yaml_emitter_write_indent(emitter)) 630 614 return 0; … … 647 631 } 648 632 649 return yaml_emitter_set_emitter_error(emitter, 650 "expected DOCUMENT-START or STREAM-END"); 633 return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-START or STREAM-END"); 651 634 } 652 635 … … 677 660 if (!yaml_emitter_write_indent(emitter)) 678 661 return 0; 679 if (!event->data.document_end.i mplicit) {662 if (!event->data.document_end.is_implicit) { 680 663 if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) 681 664 return 0; … … 698 681 } 699 682 700 return yaml_emitter_set_emitter_error(emitter, 701 "expected DOCUMENT-END"); 683 return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-END"); 702 684 } 703 685 … … 724 706 emitter->flow_level --; 725 707 emitter->indent = POP(emitter, emitter->indents); 726 if (emitter-> canonical && !first) {708 if (emitter->is_canonical && !first) { 727 709 if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 728 710 return 0; … … 742 724 } 743 725 744 if (emitter-> canonical || emitter->column > emitter->best_width) {726 if (emitter->is_canonical || emitter->column > emitter->best_width) { 745 727 if (!yaml_emitter_write_indent(emitter)) 746 728 return 0; … … 773 755 emitter->flow_level --; 774 756 emitter->indent = POP(emitter, emitter->indents); 775 if (emitter-> canonical && !first) {757 if (emitter->is_canonical && !first) { 776 758 if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 777 759 return 0; … … 790 772 return 0; 791 773 } 792 if (emitter-> canonical || emitter->column > emitter->best_width) {774 if (emitter->is_canonical || emitter->column > emitter->best_width) { 793 775 if (!yaml_emitter_write_indent(emitter)) 794 776 return 0; 795 777 } 796 778 797 if (!emitter-> canonical && yaml_emitter_check_simple_key(emitter))779 if (!emitter->is_canonical && yaml_emitter_check_simple_key(emitter)) 798 780 { 799 781 if (!PUSH(emitter, emitter->states, … … 828 810 } 829 811 else { 830 if (emitter-> canonical || emitter->column > emitter->best_width) {812 if (emitter->is_canonical || emitter->column > emitter->best_width) { 831 813 if (!yaml_emitter_write_indent(emitter)) 832 814 return 0; … … 851 833 { 852 834 if (!yaml_emitter_increase_indent(emitter, 0, 853 (emitter-> mapping_context && !emitter->indention)))835 (emitter->is_mapping_context && !emitter->is_indention))) 854 836 return 0; 855 837 } … … 950 932 static int 951 933 yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 952 int root, int sequence, int mapping, intsimple_key)953 { 954 emitter-> root_context =root;955 emitter-> sequence_context =sequence;956 emitter-> mapping_context =mapping;957 emitter-> simple_key_context =simple_key;934 int is_root, int is_sequence, int is_mapping, int is_simple_key) 935 { 936 emitter->is_root_context = is_root; 937 emitter->is_sequence_context = is_sequence; 938 emitter->is_mapping_context = is_mapping; 939 emitter->is_simple_key_context = is_simple_key; 958 940 959 941 switch (event->type) … … 972 954 973 955 default: 974 return yaml_emitter_set_emitter_error(emitter,956 return EMITTER_ERROR_INIT(emitter, 975 957 "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS"); 976 958 } … … 1028 1010 return 0; 1029 1011 1030 if (emitter->flow_level || emitter-> canonical1012 if (emitter->flow_level || emitter->is_canonical 1031 1013 || event->data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE 1032 1014 || yaml_emitter_check_empty_sequence(emitter)) { … … 1052 1034 return 0; 1053 1035 1054 if (emitter->flow_level || emitter-> canonical1036 if (emitter->flow_level || emitter->is_canonical 1055 1037 || event->data.mapping_start.style == YAML_FLOW_MAPPING_STYLE 1056 1038 || yaml_emitter_check_empty_mapping(emitter)) { … … 1084 1066 return 0; 1085 1067 1086 return (emitter->events.head[0].type == YAML_SEQUENCE_START_EVENT 1087 && emitter->events.head[1].type == YAML_SEQUENCE_END_EVENT); 1068 return (emitter->events.list[emitter->events.head].type 1069 == YAML_SEQUENCE_START_EVENT && 1070 emitter->events.list[emitter->events.head+1].type 1071 == YAML_SEQUENCE_END_EVENT); 1088 1072 } 1089 1073 … … 1098 1082 return 0; 1099 1083 1100 return (emitter->events.head[0].type == YAML_MAPPING_START_EVENT 1101 && emitter->events.head[1].type == YAML_MAPPING_END_EVENT); 1084 return (emitter->events.list[emitter->events.head].type 1085 == YAML_MAPPING_START_EVENT && 1086 emitter->events.list[emitter->events.head+1].type 1087 == YAML_MAPPING_END_EVENT); 1102 1088 } 1103 1089 … … 1109 1095 yaml_emitter_check_simple_key(yaml_emitter_t *emitter) 1110 1096 { 1111 yaml_event_t *event = emitter->events. head;1097 yaml_event_t *event = emitter->events.list + emitter->events.head; 1112 1098 size_t length = 0; 1113 1099 … … 1119 1105 1120 1106 case YAML_SCALAR_EVENT: 1121 if (emitter->scalar_data. multiline)1107 if (emitter->scalar_data.is_multiline) 1122 1108 return 0; 1123 1109 length += emitter->anchor_data.anchor_length … … 1163 1149 int no_tag = (!emitter->tag_data.handle && !emitter->tag_data.suffix); 1164 1150 1165 if (no_tag && !event->data.scalar. plain_implicit1166 && !event->data.scalar. quoted_implicit) {1167 return yaml_emitter_set_emitter_error(emitter,1151 if (no_tag && !event->data.scalar.is_plain_implicit 1152 && !event->data.scalar.is_quoted_implicit) { 1153 return EMITTER_ERROR_INIT(emitter, 1168 1154 "neither tag nor implicit flags are specified"); 1169 1155 } … … 1172 1158 style = YAML_PLAIN_SCALAR_STYLE; 1173 1159 1174 if (emitter-> canonical)1160 if (emitter->is_canonical) 1175 1161 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1176 1162 1177 if (emitter-> simple_key_context && emitter->scalar_data.multiline)1163 if (emitter->is_simple_key_context && emitter->scalar_data.is_multiline) 1178 1164 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1179 1165 1180 1166 if (style == YAML_PLAIN_SCALAR_STYLE) 1181 1167 { 1182 if ((emitter->flow_level && !emitter->scalar_data. flow_plain_allowed)1183 || (!emitter->flow_level && !emitter->scalar_data. block_plain_allowed))1168 if ((emitter->flow_level && !emitter->scalar_data.is_flow_plain_allowed) 1169 || (!emitter->flow_level && !emitter->scalar_data.is_block_plain_allowed)) 1184 1170 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1185 1171 if (!emitter->scalar_data.length 1186 && (emitter->flow_level || emitter-> simple_key_context))1172 && (emitter->flow_level || emitter->is_simple_key_context)) 1187 1173 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1188 if (no_tag && !event->data.scalar. plain_implicit)1174 if (no_tag && !event->data.scalar.is_plain_implicit) 1189 1175 style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 1190 1176 } … … 1192 1178 if (style == YAML_SINGLE_QUOTED_SCALAR_STYLE) 1193 1179 { 1194 if (!emitter->scalar_data. single_quoted_allowed)1180 if (!emitter->scalar_data.is_single_quoted_allowed) 1195 1181 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1196 1182 } … … 1198 1184 if (style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE) 1199 1185 { 1200 if (!emitter->scalar_data. block_allowed1201 || emitter->flow_level || emitter-> simple_key_context)1186 if (!emitter->scalar_data.is_block_allowed 1187 || emitter->flow_level || emitter->is_simple_key_context) 1202 1188 style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 1203 1189 } 1204 1190 1205 if (no_tag && !event->data.scalar. quoted_implicit1191 if (no_tag && !event->data.scalar.is_quoted_implicit 1206 1192 && style != YAML_PLAIN_SCALAR_STYLE) 1207 1193 { … … 1226 1212 1227 1213 if (!yaml_emitter_write_indicator(emitter, 1228 (emitter->anchor_data. alias ? "*" : "&"), 1, 0, 0))1214 (emitter->anchor_data.is_alias ? "*" : "&"), 1, 0, 0)) 1229 1215 return 0; 1230 1216 … … 1280 1266 return yaml_emitter_write_plain_scalar(emitter, 1281 1267 emitter->scalar_data.value, emitter->scalar_data.length, 1282 !emitter-> simple_key_context);1268 !emitter->is_simple_key_context); 1283 1269 1284 1270 case YAML_SINGLE_QUOTED_SCALAR_STYLE: 1285 1271 return yaml_emitter_write_single_quoted_scalar(emitter, 1286 1272 emitter->scalar_data.value, emitter->scalar_data.length, 1287 !emitter-> simple_key_context);1273 !emitter->is_simple_key_context); 1288 1274 1289 1275 case YAML_DOUBLE_QUOTED_SCALAR_STYLE: 1290 1276 return yaml_emitter_write_double_quoted_scalar(emitter, 1291 1277 emitter->scalar_data.value, emitter->scalar_data.length, 1292 !emitter-> simple_key_context);1278 !emitter->is_simple_key_context); 1293 1279 1294 1280 case YAML_LITERAL_SCALAR_STYLE: … … 1316 1302 { 1317 1303 if (version_directive.major != 1 || version_directive.minor != 1) { 1318 return yaml_emitter_set_emitter_error(emitter, 1319 "incompatible %YAML directive"); 1304 return EMITTER_ERROR_INIT(emitter, "incompatible %YAML directive"); 1320 1305 } 1321 1306 … … 1336 1321 strlen((char *)tag_directive.prefix)); 1337 1322 1338 if (handle.start == handle.end) { 1339 return yaml_emitter_set_emitter_error(emitter, 1340 "tag handle must not be empty"); 1341 } 1342 1343 if (handle.start[0] != '!') { 1344 return yaml_emitter_set_emitter_error(emitter, 1345 "tag handle must start with '!'"); 1346 } 1347 1348 if (handle.end[-1] != '!') { 1349 return yaml_emitter_set_emitter_error(emitter, 1350 "tag handle must end with '!'"); 1323 if (!handle.capacity) { 1324 return EMITTER_ERROR_INIT(emitter, "tag handle must not be empty"); 1325 } 1326 1327 if (handle.buffer[0] != '!') { 1328 return EMITTER_ERROR_INIT(emitter, "tag handle must start with '!'"); 1329 } 1330 1331 if (handle.buffer[handle.capacity-1] != '!') { 1332 return EMITTER_ERROR_INIT(emitter, "tag handle must end with '!'"); 1351 1333 } 1352 1334 1353 1335 handle.pointer ++; 1354 1336 1355 while (handle.pointer < handle. end-1) {1337 while (handle.pointer < handle.capacity-1) { 1356 1338 if (!IS_ALPHA(handle)) { 1357 return yaml_emitter_set_emitter_error(emitter,1339 return EMITTER_ERROR_INIT(emitter, 1358 1340 "tag handle must contain alphanumerical characters only"); 1359 1341 } … … 1361 1343 } 1362 1344 1363 if (prefix.start == prefix.end) { 1364 return yaml_emitter_set_emitter_error(emitter, 1365 "tag prefix must not be empty"); 1345 if (!prefix.capacity) { 1346 return EMITTER_ERROR_INIT(emitter, "tag prefix must not be empty"); 1366 1347 } 1367 1348 … … 1375 1356 static int 1376 1357 yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, 1377 yaml_char_t *anchor, int alias)1358 yaml_char_t *anchor, int is_alias) 1378 1359 { 1379 1360 yaml_string_t string = STRING(anchor, strlen((char *)anchor)); 1380 1361 1381 if ( string.start == string.end) {1382 return yaml_emitter_set_emitter_error(emitter,alias ?1362 if (!string.capacity) { 1363 return EMITTER_ERROR_INIT(emitter, is_alias ? 1383 1364 "alias value must not be empty" : 1384 1365 "anchor value must not be empty"); 1385 1366 } 1386 1367 1387 while (string.pointer != string.end) {1368 while (string.pointer < string.capacity) { 1388 1369 if (!IS_ALPHA(string)) { 1389 return yaml_emitter_set_emitter_error(emitter,alias ?1370 return EMITTER_ERROR_INIT(emitter, is_alias ? 1390 1371 "alias value must contain alphanumerical characters only" : 1391 1372 "anchor value must contain alphanumerical characters only"); … … 1394 1375 } 1395 1376 1396 emitter->anchor_data.anchor = string. start;1397 emitter->anchor_data.anchor_length = string. end - string.start;1398 emitter->anchor_data. alias =alias;1377 emitter->anchor_data.anchor = string.buffer; 1378 emitter->anchor_data.anchor_length = string.capacity; 1379 emitter->anchor_data.is_alias = is_alias; 1399 1380 1400 1381 return 1; … … 1410 1391 { 1411 1392 yaml_string_t string = STRING(tag, strlen((char *)tag)); 1412 yaml_tag_directive_t *tag_directive; 1413 1414 if (string.start == string.end) { 1415 return yaml_emitter_set_emitter_error(emitter, 1416 "tag value must not be empty"); 1417 } 1418 1419 for (tag_directive = emitter->tag_directives.start; 1420 tag_directive != emitter->tag_directives.top; tag_directive ++) { 1393 size_t idx; 1394 1395 if (!string.capacity) { 1396 return EMITTER_ERROR_INIT(emitter, "tag value must not be empty"); 1397 } 1398 1399 for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 1400 yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 1421 1401 size_t prefix_length = strlen((char *)tag_directive->prefix); 1422 if (prefix_length < (size_t)(string.end - string.start)1423 && strncmp((char *)tag_directive->prefix, (char *)string. start,1402 if (prefix_length < string.capacity 1403 && strncmp((char *)tag_directive->prefix, (char *)string.buffer, 1424 1404 prefix_length) == 0) 1425 1405 { … … 1427 1407 emitter->tag_data.handle_length = 1428 1408 strlen((char *)tag_directive->handle); 1429 emitter->tag_data.suffix = string.start + prefix_length; 1430 emitter->tag_data.suffix_length = 1431 (string.end - string.start) - prefix_length; 1409 emitter->tag_data.suffix = string.buffer + prefix_length; 1410 emitter->tag_data.suffix_length = string.capacity - prefix_length; 1432 1411 return 1; 1433 1412 } 1434 1413 } 1435 1414 1436 emitter->tag_data.suffix = string. start;1437 emitter->tag_data.suffix_length = string. end - string.start;1415 emitter->tag_data.suffix = string.buffer; 1416 emitter->tag_data.suffix_length = string.capacity; 1438 1417 1439 1418 return 1; … … 1474 1453 emitter->scalar_data.length = length; 1475 1454 1476 if ( string.start == string.end)1477 { 1478 emitter->scalar_data. multiline = 0;1479 emitter->scalar_data. flow_plain_allowed = 0;1480 emitter->scalar_data. block_plain_allowed = 1;1481 emitter->scalar_data. single_quoted_allowed = 1;1482 emitter->scalar_data. block_allowed = 0;1455 if (!string.capacity) 1456 { 1457 emitter->scalar_data.is_multiline = 0; 1458 emitter->scalar_data.is_flow_plain_allowed = 0; 1459 emitter->scalar_data.is_block_plain_allowed = 1; 1460 emitter->scalar_data.is_single_quoted_allowed = 1; 1461 emitter->scalar_data.is_block_allowed = 0; 1483 1462 1484 1463 return 1; … … 1498 1477 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1499 1478 1500 while (string.pointer != string.end)1501 { 1502 if ( string.start ==string.pointer)1479 while (string.pointer < string.capacity) 1480 { 1481 if (!string.pointer) 1503 1482 { 1504 1483 if (CHECK(string, '#') || CHECK(string, ',') … … 1548 1527 1549 1528 if (!IS_PRINTABLE(string) 1550 || (!IS_ASCII(string) && !emitter-> unicode)) {1529 || (!IS_ASCII(string) && !emitter->is_unicode)) { 1551 1530 special_characters = 1; 1552 1531 } … … 1559 1538 { 1560 1539 spaces = 1; 1561 if ( string.start ==string.pointer) {1540 if (!string.pointer) { 1562 1541 leading = 1; 1563 1542 } … … 1570 1549 } 1571 1550 breaks = 1; 1572 if ( string.start ==string.pointer) {1551 if (!string.pointer) { 1573 1552 leading = 1; 1574 1553 } … … 1605 1584 } 1606 1585 1607 if ((spaces || breaks) && string.pointer == string. end-1)1586 if ((spaces || breaks) && string.pointer == string.capacity-1) 1608 1587 { 1609 1588 if (spaces && breaks) { … … 1626 1605 preceeded_by_space = IS_BLANKZ(string); 1627 1606 MOVE(string); 1628 if (string.pointer != string.end) {1607 if (string.pointer < string.capacity) { 1629 1608 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1630 1609 } 1631 1610 } 1632 1611 1633 emitter->scalar_data. multiline = line_breaks;1634 1635 emitter->scalar_data. flow_plain_allowed = 1;1636 emitter->scalar_data. block_plain_allowed = 1;1637 emitter->scalar_data. single_quoted_allowed = 1;1638 emitter->scalar_data. block_allowed = 1;1612 emitter->scalar_data.is_multiline = line_breaks; 1613 1614 emitter->scalar_data.is_flow_plain_allowed = 1; 1615 emitter->scalar_data.is_block_plain_allowed = 1; 1616 emitter->scalar_data.is_single_quoted_allowed = 1; 1617 emitter->scalar_data.is_block_allowed = 1; 1639 1618 1640 1619 if (leading_spaces || leading_breaks || trailing_spaces) { 1641 emitter->scalar_data. flow_plain_allowed = 0;1642 emitter->scalar_data. block_plain_allowed = 0;1643 emitter->scalar_data. block_allowed = 0;1620 emitter->scalar_data.is_flow_plain_allowed = 0; 1621 emitter->scalar_data.is_block_plain_allowed = 0; 1622 emitter->scalar_data.is_block_allowed = 0; 1644 1623 } 1645 1624 1646 1625 if (trailing_breaks) { 1647 emitter->scalar_data. flow_plain_allowed = 0;1648 emitter->scalar_data. block_plain_allowed = 0;1626 emitter->scalar_data.is_flow_plain_allowed = 0; 1627 emitter->scalar_data.is_block_plain_allowed = 0; 1649 1628 } 1650 1629 1651 1630 if (inline_breaks_spaces) { 1652 emitter->scalar_data. flow_plain_allowed = 0;1653 emitter->scalar_data. block_plain_allowed = 0;1654 emitter->scalar_data. single_quoted_allowed = 0;1631 emitter->scalar_data.is_flow_plain_allowed = 0; 1632 emitter->scalar_data.is_block_plain_allowed = 0; 1633 emitter->scalar_data.is_single_quoted_allowed = 0; 1655 1634 } 1656 1635 1657 1636 if (mixed_breaks_spaces || special_characters) { 1658 emitter->scalar_data. flow_plain_allowed = 0;1659 emitter->scalar_data. block_plain_allowed = 0;1660 emitter->scalar_data. single_quoted_allowed = 0;1661 emitter->scalar_data. block_allowed = 0;1637 emitter->scalar_data.is_flow_plain_allowed = 0; 1638 emitter->scalar_data.is_block_plain_allowed = 0; 1639 emitter->scalar_data.is_single_quoted_allowed = 0; 1640 emitter->scalar_data.is_block_allowed = 0; 1662 1641 } 1663 1642 1664 1643 if (line_breaks) { 1665 emitter->scalar_data. flow_plain_allowed = 0;1666 emitter->scalar_data. block_plain_allowed = 0;1644 emitter->scalar_data.is_flow_plain_allowed = 0; 1645 emitter->scalar_data.is_block_plain_allowed = 0; 1667 1646 } 1668 1647 1669 1648 if (flow_indicators) { 1670 emitter->scalar_data. flow_plain_allowed = 0;1649 emitter->scalar_data.is_flow_plain_allowed = 0; 1671 1650 } 1672 1651 1673 1652 if (block_indicators) { 1674 emitter->scalar_data. block_plain_allowed = 0;1653 emitter->scalar_data.is_block_plain_allowed = 0; 1675 1654 } 1676 1655 … … 1709 1688 return 0; 1710 1689 } 1711 if (event->data.scalar.tag && (emitter-> canonical ||1712 (!event->data.scalar. plain_implicit1713 && !event->data.scalar. quoted_implicit))) {1690 if (event->data.scalar.tag && (emitter->is_canonical || 1691 (!event->data.scalar.is_plain_implicit 1692 && !event->data.scalar.is_quoted_implicit))) { 1714 1693 if (!yaml_emitter_analyze_tag(emitter, event->data.scalar.tag)) 1715 1694 return 0; … … 1726 1705 return 0; 1727 1706 } 1728 if (event->data.sequence_start.tag && (emitter-> canonical ||1729 !event->data.sequence_start.i mplicit)) {1707 if (event->data.sequence_start.tag && (emitter->is_canonical || 1708 !event->data.sequence_start.is_implicit)) { 1730 1709 if (!yaml_emitter_analyze_tag(emitter, 1731 1710 event->data.sequence_start.tag)) … … 1740 1719 return 0; 1741 1720 } 1742 if (event->data.mapping_start.tag && (emitter-> canonical ||1743 !event->data.mapping_start.i mplicit)) {1721 if (event->data.mapping_start.tag && (emitter->is_canonical || 1722 !event->data.mapping_start.is_implicit)) { 1744 1723 if (!yaml_emitter_analyze_tag(emitter, 1745 1724 event->data.mapping_start.tag)) … … 1762 1741 if (!FLUSH(emitter)) return 0; 1763 1742 1764 *(emitter->buffer.pointer++) = (yaml_char_t) '\xEF';1765 *(emitter->buffer.pointer++) = (yaml_char_t) '\xBB';1766 *(emitter->buffer.pointer++) = (yaml_char_t) '\xBF';1743 JOIN_OCTET(emitter->output, (yaml_char_t) '\xEF'); 1744 JOIN_OCTET(emitter->output, (yaml_char_t) '\xBB'); 1745 JOIN_OCTET(emitter->output, (yaml_char_t) '\xBF'); 1767 1746 1768 1747 return 1; … … 1774 1753 int indent = (emitter->indent >= 0) ? emitter->indent : 0; 1775 1754 1776 if (!emitter->i ndention || emitter->column > indent1777 || (emitter->column == indent && !emitter-> whitespace)) {1755 if (!emitter->is_indention || emitter->column > indent 1756 || (emitter->column == indent && !emitter->is_whitespace)) { 1778 1757 if (!PUT_BREAK(emitter)) return 0; 1779 1758 } … … 1783 1762 } 1784 1763 1785 emitter-> whitespace = 1;1786 emitter->i ndention = 1;1764 emitter->is_whitespace = 1; 1765 emitter->is_indention = 1; 1787 1766 1788 1767 return 1; … … 1796 1775 yaml_string_t string = STRING((yaml_char_t *)indicator, strlen(indicator)); 1797 1776 1798 if (need_whitespace && !emitter-> whitespace) {1777 if (need_whitespace && !emitter->is_whitespace) { 1799 1778 if (!PUT(emitter, ' ')) return 0; 1800 1779 } 1801 1780 1802 while (string.pointer != string.end) {1781 while (string.pointer < string.capacity) { 1803 1782 if (!WRITE(emitter, string)) return 0; 1804 1783 } 1805 1784 1806 emitter-> whitespace = is_whitespace;1807 emitter->i ndention = (emitter->indention && is_indention);1785 emitter->is_whitespace = is_whitespace; 1786 emitter->is_indention = (emitter->is_indention && is_indention); 1808 1787 1809 1788 return 1; … … 1816 1795 yaml_string_t string = STRING(value, length); 1817 1796 1818 while (string.pointer != string.end) {1797 while (string.pointer < string.capacity) { 1819 1798 if (!WRITE(emitter, string)) return 0; 1820 1799 } 1821 1800 1822 emitter-> whitespace = 0;1823 emitter->i ndention = 0;1801 emitter->is_whitespace = 0; 1802 emitter->is_indention = 0; 1824 1803 1825 1804 return 1; … … 1832 1811 yaml_string_t string = STRING(value, length); 1833 1812 1834 if (!emitter-> whitespace) {1813 if (!emitter->is_whitespace) { 1835 1814 if (!PUT(emitter, ' ')) return 0; 1836 1815 } 1837 1816 1838 while (string.pointer != string.end) {1817 while (string.pointer < string.capacity) { 1839 1818 if (!WRITE(emitter, string)) return 0; 1840 1819 } 1841 1820 1842 emitter-> whitespace = 0;1843 emitter->i ndention = 0;1821 emitter->is_whitespace = 0; 1822 emitter->is_indention = 0; 1844 1823 1845 1824 return 1; … … 1853 1832 yaml_string_t string = STRING(value, length); 1854 1833 1855 if (need_whitespace && !emitter-> whitespace) {1834 if (need_whitespace && !emitter->is_whitespace) { 1856 1835 if (!PUT(emitter, ' ')) return 0; 1857 1836 } 1858 1837 1859 while (string.pointer != string.end) {1838 while (string.pointer < string.capacity) { 1860 1839 if (IS_ALPHA(string) 1861 1840 || CHECK(string, ';') || CHECK(string, '/') … … 1875 1854 unsigned int value; 1876 1855 while (width --) { 1877 value = *(string.pointer++); 1856 value = OCTET(string); 1857 string.pointer ++; 1878 1858 if (!PUT(emitter, '%')) return 0; 1879 1859 if (!PUT(emitter, (value >> 4) … … 1887 1867 } 1888 1868 1889 emitter-> whitespace = 0;1890 emitter->i ndention = 0;1869 emitter->is_whitespace = 0; 1870 emitter->is_indention = 0; 1891 1871 1892 1872 return 1; … … 1901 1881 int breaks = 0; 1902 1882 1903 if (!emitter-> whitespace) {1883 if (!emitter->is_whitespace) { 1904 1884 if (!PUT(emitter, ' ')) return 0; 1905 1885 } 1906 1886 1907 while (string.pointer != string.end)1887 while (string.pointer < string.capacity) 1908 1888 { 1909 1889 if (IS_SPACE(string)) … … 1926 1906 } 1927 1907 if (!WRITE_BREAK(emitter, string)) return 0; 1928 emitter->i ndention = 1;1908 emitter->is_indention = 1; 1929 1909 breaks = 1; 1930 1910 } … … 1935 1915 } 1936 1916 if (!WRITE(emitter, string)) return 0; 1937 emitter->i ndention = 0;1917 emitter->is_indention = 0; 1938 1918 spaces = 0; 1939 1919 breaks = 0; … … 1941 1921 } 1942 1922 1943 emitter-> whitespace = 0;1944 emitter->i ndention = 0;1923 emitter->is_whitespace = 0; 1924 emitter->is_indention = 0; 1945 1925 1946 1926 return 1; … … 1958 1938 return 0; 1959 1939 1960 while (string.pointer != string.end)1940 while (string.pointer < string.capacity) 1961 1941 { 1962 1942 if (IS_SPACE(string)) … … 1964 1944 if (allow_breaks && !spaces 1965 1945 && emitter->column > emitter->best_width 1966 && string.pointer != string.start1967 && string.pointer != string. end- 11946 && string.pointer != 0 1947 && string.pointer != string.capacity - 1 1968 1948 && !IS_SPACE_AT(string, 1)) { 1969 1949 if (!yaml_emitter_write_indent(emitter)) return 0; … … 1981 1961 } 1982 1962 if (!WRITE_BREAK(emitter, string)) return 0; 1983 emitter->i ndention = 1;1963 emitter->is_indention = 1; 1984 1964 breaks = 1; 1985 1965 } … … 1993 1973 } 1994 1974 if (!WRITE(emitter, string)) return 0; 1995 emitter->i ndention = 0;1975 emitter->is_indention = 0; 1996 1976 spaces = 0; 1997 1977 breaks = 0; … … 2002 1982 return 0; 2003 1983 2004 emitter-> whitespace = 0;2005 emitter->i ndention = 0;1984 emitter->is_whitespace = 0; 1985 emitter->is_indention = 0; 2006 1986 2007 1987 return 1; … … 2018 1998 return 0; 2019 1999 2020 while (string.pointer != string.end)2021 { 2022 if (!IS_PRINTABLE(string) || (!emitter-> unicode && !IS_ASCII(string))2000 while (string.pointer < string.capacity) 2001 { 2002 if (!IS_PRINTABLE(string) || (!emitter->is_unicode && !IS_ASCII(string)) 2023 2003 || IS_BOM(string) || IS_BREAK(string) 2024 2004 || CHECK(string, '"') || CHECK(string, '\\')) … … 2027 2007 unsigned int width; 2028 2008 unsigned int value; 2029 int k;2030 2031 octet = string.pointer[0];2009 int idx; 2010 2011 octet = OCTET(string); 2032 2012 width = (octet & 0x80) == 0x00 ? 1 : 2033 2013 (octet & 0xE0) == 0xC0 ? 2 : … … 2038 2018 (octet & 0xF0) == 0xE0 ? octet & 0x0F : 2039 2019 (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; 2040 for ( k = 1; k < (int)width; k++) {2041 octet = string.pointer[k];2020 for (idx = 1; idx < width; idx ++) { 2021 octet = OCTET_AT(string, idx); 2042 2022 value = (value << 6) + (octet & 0x3F); 2043 2023 } … … 2121 2101 width = 8; 2122 2102 } 2123 for ( k = (width-1)*4; k >= 0; k-= 4) {2124 int digit = (value >> k) & 0x0F;2103 for (idx = (width-1)*4; idx >= 0; idx -= 4) { 2104 int digit = (value >> idx) & 0x0F; 2125 2105 if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10))) 2126 2106 return 0; … … 2133 2113 if (allow_breaks && !spaces 2134 2114 && emitter->column > emitter->best_width 2135 && string.pointer != string.start2136 && string.pointer != string. end- 1) {2115 && string.pointer != 0 2116 && string.pointer != string.capacity - 1) { 2137 2117 if (!yaml_emitter_write_indent(emitter)) return 0; 2138 2118 if (IS_SPACE_AT(string, 1)) { … … 2156 2136 return 0; 2157 2137 2158 emitter-> whitespace = 0;2159 emitter->i ndention = 0;2138 emitter->is_whitespace = 0; 2139 emitter->is_indention = 0; 2160 2140 2161 2141 return 1; … … 2166 2146 yaml_string_t string) 2167 2147 { 2168 string.pointer = string. end;2169 if ( string.start ==string.pointer)2148 string.pointer = string.capacity; 2149 if (!string.pointer) 2170 2150 return -1; 2171 2151 do { 2172 2152 string.pointer --; 2173 } while (( *string.pointer& 0xC0) == 0x80);2153 } while ((OCTET(string) & 0xC0) == 0x80); 2174 2154 if (!IS_BREAK(string)) 2175 2155 return -1; 2176 if ( string.start ==string.pointer)2156 if (!string.pointer) 2177 2157 return 0; 2178 2158 do { 2179 2159 string.pointer --; 2180 } while (( *string.pointer& 0xC0) == 0x80);2160 } while ((OCTET(string) & 0xC0) == 0x80); 2181 2161 if (!IS_BREAK(string)) 2182 2162 return 0; … … 2199 2179 return 0; 2200 2180 2201 while (string.pointer != string.end)2181 while (string.pointer < string.capacity) 2202 2182 { 2203 2183 if (IS_BREAK(string)) 2204 2184 { 2205 2185 if (!WRITE_BREAK(emitter, string)) return 0; 2206 emitter->i ndention = 1;2186 emitter->is_indention = 1; 2207 2187 breaks = 1; 2208 2188 } … … 2213 2193 } 2214 2194 if (!WRITE(emitter, string)) return 0; 2215 emitter->i ndention = 0;2195 emitter->is_indention = 0; 2216 2196 breaks = 0; 2217 2197 } … … 2236 2216 return 0; 2237 2217 2238 while (string.pointer != string.end)2218 while (string.pointer < string.capacity) 2239 2219 { 2240 2220 if (IS_BREAK(string)) … … 2250 2230 } 2251 2231 if (!WRITE_BREAK(emitter, string)) return 0; 2252 emitter->i ndention = 1;2232 emitter->is_indention = 1; 2253 2233 breaks = 1; 2254 2234 } … … 2267 2247 if (!WRITE(emitter, string)) return 0; 2268 2248 } 2269 emitter->i ndention = 0;2249 emitter->is_indention = 0; 2270 2250 breaks = 0; 2271 2251 }
Note: See TracChangeset
for help on using the changeset viewer.
