| | 1045 | /* |
|---|
| | 1046 | * Check if the document content is an empty scalar. |
|---|
| | 1047 | */ |
|---|
| | 1048 | |
|---|
| | 1049 | static int |
|---|
| | 1050 | yaml_emitter_check_empty_document(yaml_emitter_t *emitter) |
|---|
| | 1051 | { |
|---|
| | 1052 | return 0; |
|---|
| | 1053 | } |
|---|
| | 1054 | |
|---|
| | 1055 | /* |
|---|
| | 1056 | * Check if the next events represent an empty sequence. |
|---|
| | 1057 | */ |
|---|
| | 1058 | |
|---|
| | 1059 | static int |
|---|
| | 1060 | yaml_emitter_check_empty_sequence(yaml_emitter_t *emitter) |
|---|
| | 1061 | { |
|---|
| | 1062 | if (emitter->events.tail - emitter->events.head < 2) |
|---|
| | 1063 | return 0; |
|---|
| | 1064 | |
|---|
| | 1065 | return (emitter->events.head[0].type == YAML_SEQUENCE_START_EVENT |
|---|
| | 1066 | && emitter->events.head[1].type == YAML_SEQUENCE_END_EVENT); |
|---|
| | 1067 | } |
|---|
| | 1068 | |
|---|
| | 1069 | /* |
|---|
| | 1070 | * Check if the next events represent an empty mapping. |
|---|
| | 1071 | */ |
|---|
| | 1072 | |
|---|
| | 1073 | static int |
|---|
| | 1074 | yaml_emitter_check_empty_mapping(yaml_emitter_t *emitter) |
|---|
| | 1075 | { |
|---|
| | 1076 | if (emitter->events.tail - emitter->events.head < 2) |
|---|
| | 1077 | return 0; |
|---|
| | 1078 | |
|---|
| | 1079 | return (emitter->events.head[0].type == YAML_MAPPING_START_EVENT |
|---|
| | 1080 | && emitter->events.head[1].type == YAML_MAPPING_END_EVENT); |
|---|
| | 1081 | } |
|---|
| | 1082 | |
|---|
| | 1083 | /* |
|---|
| | 1084 | * Check if the next node can be expressed as a simple key. |
|---|
| | 1085 | */ |
|---|
| | 1086 | |
|---|
| | 1087 | static int |
|---|
| | 1088 | yaml_emitter_check_simple_key(yaml_emitter_t *emitter) |
|---|
| | 1089 | { |
|---|
| | 1090 | yaml_event_t *event = emitter->events.head; |
|---|
| | 1091 | size_t length = 0; |
|---|
| | 1092 | |
|---|
| | 1093 | switch (event->type) |
|---|
| | 1094 | { |
|---|
| | 1095 | case YAML_ALIAS_EVENT: |
|---|
| | 1096 | length += emitter->anchor_data.anchor_length; |
|---|
| | 1097 | break; |
|---|
| | 1098 | |
|---|
| | 1099 | case YAML_SCALAR_EVENT: |
|---|
| | 1100 | if (emitter->scalar_data.multiline) |
|---|
| | 1101 | return 0; |
|---|
| | 1102 | length += emitter->anchor_data.anchor_length |
|---|
| | 1103 | + emitter->tag_data.handle_length |
|---|
| | 1104 | + emitter->tag_data.suffix_length |
|---|
| | 1105 | + emitter->scalar_data.length; |
|---|
| | 1106 | break; |
|---|
| | 1107 | |
|---|
| | 1108 | case YAML_SEQUENCE_START_EVENT: |
|---|
| | 1109 | if (!yaml_emitter_check_empty_sequence(emitter)) |
|---|
| | 1110 | return 0; |
|---|
| | 1111 | length += emitter->anchor_data.anchor_length |
|---|
| | 1112 | + emitter->tag_data.handle_length |
|---|
| | 1113 | + emitter->tag_data.suffix_length; |
|---|
| | 1114 | break; |
|---|
| | 1115 | |
|---|
| | 1116 | case YAML_MAPPING_START_EVENT: |
|---|
| | 1117 | if (!yaml_emitter_check_empty_sequence(emitter)) |
|---|
| | 1118 | return 0; |
|---|
| | 1119 | length += emitter->anchor_data.anchor_length |
|---|
| | 1120 | + emitter->tag_data.handle_length |
|---|
| | 1121 | + emitter->tag_data.suffix_length; |
|---|
| | 1122 | break; |
|---|
| | 1123 | |
|---|
| | 1124 | default: |
|---|
| | 1125 | return 0; |
|---|
| | 1126 | } |
|---|
| | 1127 | |
|---|
| | 1128 | if (length > 128) |
|---|
| | 1129 | return 0; |
|---|
| | 1130 | |
|---|
| | 1131 | return 1; |
|---|
| | 1132 | } |
|---|
| | 1133 | |
|---|
| | 1134 | /* |
|---|
| | 1135 | * Determine an acceptable scalar style. |
|---|
| | 1136 | */ |
|---|
| | 1137 | |
|---|
| | 1138 | static int |
|---|
| | 1139 | yaml_emitter_select_scalar_style(yaml_emitter_t *emitter, yaml_event_t *event) |
|---|
| | 1140 | { |
|---|
| | 1141 | yaml_scalar_style_t style = event->data.scalar.style; |
|---|
| | 1142 | |
|---|
| | 1143 | if (style == YAML_ANY_SCALAR_STYLE) |
|---|
| | 1144 | style = YAML_PLAIN_SCALAR_STYLE; |
|---|
| | 1145 | |
|---|
| | 1146 | if (emitter->canonical) |
|---|
| | 1147 | style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; |
|---|
| | 1148 | |
|---|
| | 1149 | if (emitter->simple_key_context && emitter->scalar_data.multiline) |
|---|
| | 1150 | style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; |
|---|
| | 1151 | |
|---|
| | 1152 | if (style == YAML_PLAIN_SCALAR_STYLE) |
|---|
| | 1153 | { |
|---|
| | 1154 | if ((emitter->flow_level && !emitter->scalar_data.flow_plain_allowed) |
|---|
| | 1155 | || (!emitter->flow_level && !emitter->scalar_data.block_plain_allowed)) |
|---|
| | 1156 | style = YAML_SINGLE_QUOTED_SCALAR_STYLE; |
|---|
| | 1157 | if (!emitter->scalar_data.length |
|---|
| | 1158 | && (emitter->flow_level || emitter->simple_key_context)) |
|---|
| | 1159 | style = YAML_SINGLE_QUOTED_SCALAR_STYLE; |
|---|
| | 1160 | if (!event->data.scalar.plain_implicit |
|---|
| | 1161 | && !emitter->tag_data.handle && !emitter->tag_data.suffix) |
|---|
| | 1162 | style = YAML_SINGLE_QUOTED_SCALAR_STYLE; |
|---|
| | 1163 | } |
|---|
| | 1164 | |
|---|
| | 1165 | if (style == YAML_SINGLE_QUOTED_SCALAR_STYLE) |
|---|
| | 1166 | { |
|---|
| | 1167 | if (!emitter->scalar_data.single_quoted_allowed) |
|---|
| | 1168 | style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; |
|---|
| | 1169 | } |
|---|
| | 1170 | |
|---|
| | 1171 | if (style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE) |
|---|
| | 1172 | { |
|---|
| | 1173 | if (!emitter->scalar_data.block_allowed) |
|---|
| | 1174 | style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; |
|---|
| | 1175 | } |
|---|
| | 1176 | |
|---|
| | 1177 | if (!emitter->tag_data.handle && !emitter->tag_data.suffix) |
|---|
| | 1178 | { |
|---|
| | 1179 | if (!event->data.scalar.plain_implicit |
|---|
| | 1180 | && !event->data.scalar.quoted_implicit) { |
|---|
| | 1181 | return yaml_emitter_set_emitter_error(emitter, |
|---|
| | 1182 | "neither tag nor implicit flags are specified"); |
|---|
| | 1183 | } |
|---|
| | 1184 | |
|---|
| | 1185 | if (event->data.scalar.plain_implicit |
|---|
| | 1186 | && style != YAML_PLAIN_SCALAR_STYLE) { |
|---|
| | 1187 | emitter->tag_data.handle = (yaml_char_t *)"!"; |
|---|
| | 1188 | emitter->tag_data.handle_length = 1; |
|---|
| | 1189 | } |
|---|
| | 1190 | } |
|---|
| | 1191 | |
|---|
| | 1192 | emitter->scalar_data.style = style; |
|---|
| | 1193 | |
|---|
| | 1194 | return 1; |
|---|
| | 1195 | } |
|---|
| | 1196 | |
|---|
| | 1197 | /* |
|---|
| | 1198 | * Write an achor. |
|---|
| | 1199 | */ |
|---|
| | 1200 | |
|---|
| | 1201 | static int |
|---|
| | 1202 | yaml_emitter_process_anchor(yaml_emitter_t *emitter) |
|---|
| | 1203 | { |
|---|
| | 1204 | if (!emitter->anchor_data.anchor) |
|---|
| | 1205 | return 1; |
|---|
| | 1206 | |
|---|
| | 1207 | if (!yaml_emitter_write_indicator(emitter, |
|---|
| | 1208 | (emitter->anchor_data.alias ? "*" : "&"), 1, 0, 0)) |
|---|
| | 1209 | return 0; |
|---|
| | 1210 | |
|---|
| | 1211 | return yaml_emitter_write_anchor(emitter, |
|---|
| | 1212 | emitter->anchor_data.anchor, emitter->anchor_data.anchor_length); |
|---|
| | 1213 | } |
|---|
| | 1214 | |
|---|
| | 1215 | /* |
|---|
| | 1216 | * Write a tag. |
|---|
| | 1217 | */ |
|---|
| | 1218 | |
|---|
| | 1219 | static int |
|---|
| | 1220 | yaml_emitter_process_tag(yaml_emitter_t *emitter) |
|---|
| | 1221 | { |
|---|
| | 1222 | if (!emitter->tag_data.handle && !emitter->tag_data.suffix) |
|---|
| | 1223 | return 1; |
|---|
| | 1224 | |
|---|
| | 1225 | if (emitter->tag_data.handle) |
|---|
| | 1226 | { |
|---|
| | 1227 | if (!yaml_emitter_write_tag_handle(emitter, emitter->tag_data.handle, |
|---|
| | 1228 | emitter->tag_data.handle_length)) |
|---|
| | 1229 | return 0; |
|---|
| | 1230 | if (emitter->tag_data.suffix) { |
|---|
| | 1231 | if (!yaml_emitter_write_tag_content(emitter, emitter->tag_data.suffix, |
|---|
| | 1232 | emitter->tag_data.suffix_length)) |
|---|
| | 1233 | return 0; |
|---|
| | 1234 | } |
|---|
| | 1235 | } |
|---|
| | 1236 | else |
|---|
| | 1237 | { |
|---|
| | 1238 | if (!yaml_emitter_write_indicator(emitter, "!<", 1, 0, 0)) |
|---|
| | 1239 | return 0; |
|---|
| | 1240 | if (!yaml_emitter_write_tag_content(emitter, emitter->tag_data.suffix, |
|---|
| | 1241 | emitter->tag_data.suffix_length)) |
|---|
| | 1242 | return 0; |
|---|
| | 1243 | if (!yaml_emitter_write_indicator(emitter, ">", 0, 0, 0)) |
|---|
| | 1244 | return 0; |
|---|
| | 1245 | } |
|---|
| | 1246 | |
|---|
| | 1247 | return 1; |
|---|
| | 1248 | } |
|---|
| | 1249 | |
|---|
| | 1250 | /* |
|---|
| | 1251 | * Write a scalar. |
|---|
| | 1252 | */ |
|---|
| | 1253 | |
|---|
| | 1254 | static int |
|---|
| | 1255 | yaml_emitter_process_scalar(yaml_emitter_t *emitter) |
|---|
| | 1256 | { |
|---|
| | 1257 | switch (emitter->scalar_data.style) |
|---|
| | 1258 | { |
|---|
| | 1259 | case YAML_PLAIN_SCALAR_STYLE: |
|---|
| | 1260 | return yaml_emitter_write_plain_scalar(emitter, |
|---|
| | 1261 | emitter->scalar_data.value, emitter->scalar_data.length, |
|---|
| | 1262 | !emitter->simple_key_context); |
|---|
| | 1263 | |
|---|
| | 1264 | case YAML_SINGLE_QUOTED_SCALAR_STYLE: |
|---|
| | 1265 | return yaml_emitter_write_single_quoted_scalar(emitter, |
|---|
| | 1266 | emitter->scalar_data.value, emitter->scalar_data.length, |
|---|
| | 1267 | !emitter->simple_key_context); |
|---|
| | 1268 | |
|---|
| | 1269 | case YAML_DOUBLE_QUOTED_SCALAR_STYLE: |
|---|
| | 1270 | return yaml_emitter_write_double_quoted_scalar(emitter, |
|---|
| | 1271 | emitter->scalar_data.value, emitter->scalar_data.length, |
|---|
| | 1272 | !emitter->simple_key_context); |
|---|
| | 1273 | |
|---|
| | 1274 | case YAML_LITERAL_SCALAR_STYLE: |
|---|
| | 1275 | return yaml_emitter_write_literal_scalar(emitter, |
|---|
| | 1276 | emitter->scalar_data.value, emitter->scalar_data.length); |
|---|
| | 1277 | |
|---|
| | 1278 | case YAML_FOLDED_SCALAR_STYLE: |
|---|
| | 1279 | return yaml_emitter_write_folded_scalar(emitter, |
|---|
| | 1280 | emitter->scalar_data.value, emitter->scalar_data.length); |
|---|
| | 1281 | |
|---|
| | 1282 | default: |
|---|
| | 1283 | assert(1); /* Impossible. */ |
|---|
| | 1284 | } |
|---|
| | 1285 | |
|---|
| | 1286 | return 0; |
|---|
| | 1287 | } |
|---|
| | 1288 | |
|---|
| | 1289 | /* |
|---|
| | 1290 | * Check if a %YAML directive is valid. |
|---|
| | 1291 | */ |
|---|
| | 1292 | |
|---|
| | 1293 | static int |
|---|
| | 1294 | yaml_emitter_analyze_version_directive(yaml_emitter_t *emitter, |
|---|
| | 1295 | yaml_version_directive_t version_directive) |
|---|
| | 1296 | { |
|---|
| | 1297 | if (version_directive.major != 1 || version_directive.minor != 1) { |
|---|
| | 1298 | return yaml_emitter_set_emitter_error(emitter, |
|---|
| | 1299 | "incompatible %YAML directive"); |
|---|
| | 1300 | } |
|---|
| | 1301 | |
|---|
| | 1302 | return 1; |
|---|
| | 1303 | } |
|---|
| | 1304 | |
|---|
| | 1305 | /* |
|---|
| | 1306 | * Check if a %TAG directive is valid. |
|---|
| | 1307 | */ |
|---|
| | 1308 | |
|---|
| | 1309 | static int |
|---|
| | 1310 | yaml_emitter_analyze_tag_directive(yaml_emitter_t *emitter, |
|---|
| | 1311 | yaml_tag_directive_t tag_directive) |
|---|
| | 1312 | { |
|---|
| | 1313 | yaml_string_t handle = STRING(tag_directive.handle, |
|---|
| | 1314 | strlen((char *)tag_directive.handle)); |
|---|
| | 1315 | yaml_string_t prefix = STRING(tag_directive.prefix, |
|---|
| | 1316 | strlen((char *)tag_directive.prefix)); |
|---|
| | 1317 | |
|---|
| | 1318 | if (handle.start == handle.end) { |
|---|
| | 1319 | return yaml_emitter_set_emitter_error(emitter, |
|---|
| | 1320 | "tag handle must not be empty"); |
|---|
| | 1321 | } |
|---|
| | 1322 | |
|---|
| | 1323 | if (handle.start[0] != '!') { |
|---|
| | 1324 | return yaml_emitter_set_emitter_error(emitter, |
|---|
| | 1325 | "tag handle must start with '!'"); |
|---|
| | 1326 | } |
|---|
| | 1327 | |
|---|
| | 1328 | if (handle.end[-1] != '!') { |
|---|
| | 1329 | return yaml_emitter_set_emitter_error(emitter, |
|---|
| | 1330 | "tag handle must end with '!'"); |
|---|
| | 1331 | } |
|---|
| | 1332 | |
|---|
| | 1333 | handle.pointer ++; |
|---|
| | 1334 | |
|---|
| | 1335 | while (handle.pointer != handle.end-1) { |
|---|
| | 1336 | if (!IS_ALPHA(handle)) { |
|---|
| | 1337 | return yaml_emitter_set_emitter_error(emitter, |
|---|
| | 1338 | "tag handle must contain alphanumerical characters only"); |
|---|
| | 1339 | } |
|---|
| | 1340 | MOVE(handle); |
|---|
| | 1341 | } |
|---|
| | 1342 | |
|---|
| | 1343 | if (prefix.start == prefix.end) { |
|---|
| | 1344 | return yaml_emitter_set_emitter_error(emitter, |
|---|
| | 1345 | "tag prefix must not be empty"); |
|---|
| | 1346 | } |
|---|
| | 1347 | |
|---|
| | 1348 | return 1; |
|---|
| | 1349 | } |
|---|
| | 1350 | |
|---|
| | 1351 | /* |
|---|
| | 1352 | * Check if an anchor is valid. |
|---|
| | 1353 | */ |
|---|
| | 1354 | |
|---|
| | 1355 | static int |
|---|
| | 1356 | yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, |
|---|
| | 1357 | yaml_char_t *anchor, int alias) |
|---|
| | 1358 | { |
|---|
| | 1359 | yaml_string_t string = STRING(anchor, strlen((char *)anchor)); |
|---|
| | 1360 | |
|---|
| | 1361 | if (string.start == string.end) { |
|---|
| | 1362 | return yaml_emitter_set_emitter_error(emitter, alias ? |
|---|
| | 1363 | "alias value must not be empty" : |
|---|
| | 1364 | "anchor value must not be empty"); |
|---|
| | 1365 | } |
|---|
| | 1366 | |
|---|
| | 1367 | while (string.pointer != string.end) { |
|---|
| | 1368 | if (!IS_ALPHA(string)) { |
|---|
| | 1369 | return yaml_emitter_set_emitter_error(emitter, alias ? |
|---|
| | 1370 | "alias value must contain alphanumerical characters only" : |
|---|
| | 1371 | "anchor value must contain alphanumerical characters only"); |
|---|
| | 1372 | } |
|---|
| | 1373 | MOVE(string); |
|---|
| | 1374 | } |
|---|
| | 1375 | } |
|---|
| | 1376 | |
|---|
| | 1377 | /* |
|---|
| | 1378 | * Check if a tag is valid. |
|---|
| | 1379 | */ |
|---|
| | 1380 | |
|---|
| | 1381 | static int |
|---|
| | 1382 | yaml_emitter_analyze_tag(yaml_emitter_t *emitter, |
|---|
| | 1383 | yaml_char_t *tag) |
|---|
| | 1384 | { |
|---|
| | 1385 | yaml_string_t string = STRING(tag, strlen((char *)tag)); |
|---|
| | 1386 | yaml_tag_directive_t *tag_directive; |
|---|
| | 1387 | |
|---|
| | 1388 | if (string.start == string.end) { |
|---|
| | 1389 | return yaml_emitter_set_emitter_error(emitter, |
|---|
| | 1390 | "tag value must not be empty"); |
|---|
| | 1391 | } |
|---|
| | 1392 | |
|---|
| | 1393 | for (tag_directive = emitter->tag_directives.start; |
|---|
| | 1394 | tag_directive != emitter->tag_directives.end; tag_directive ++) { |
|---|
| | 1395 | size_t prefix_length = strlen((char *)tag_directive->prefix); |
|---|
| | 1396 | if (prefix_length < (string.end - string.start) |
|---|
| | 1397 | && strncmp((char *)tag_directive->prefix, (char *)string.start, |
|---|
| | 1398 | prefix_length) == 0) |
|---|
| | 1399 | { |
|---|
| | 1400 | emitter->tag_data.handle = tag_directive->handle; |
|---|
| | 1401 | emitter->tag_data.handle_length = |
|---|
| | 1402 | strlen((char *)tag_directive->handle); |
|---|
| | 1403 | emitter->tag_data.suffix = string.start + prefix_length; |
|---|
| | 1404 | emitter->tag_data.suffix_length = |
|---|
| | 1405 | (string.end - string.start) - prefix_length; |
|---|
| | 1406 | return 1; |
|---|
| | 1407 | } |
|---|
| | 1408 | } |
|---|
| | 1409 | |
|---|
| | 1410 | emitter->tag_data.suffix = string.start; |
|---|
| | 1411 | emitter->tag_data.suffix_length = string.end - string.start; |
|---|
| | 1412 | |
|---|
| | 1413 | return 1; |
|---|
| | 1414 | } |
|---|
| | 1415 | |
|---|
| | 1416 | /* |
|---|
| | 1417 | * Check if a scalar is valid. |
|---|
| | 1418 | */ |
|---|
| | 1419 | |
|---|
| | 1420 | static int |
|---|
| | 1421 | yaml_emitter_analyze_scalar(yaml_emitter_t *emitter, |
|---|
| | 1422 | yaml_char_t *value, size_t length) |
|---|
| | 1423 | { |
|---|
| | 1424 | yaml_string_t string = STRING(value, length); |
|---|
| | 1425 | |
|---|
| | 1426 | int block_indicators = 0; |
|---|
| | 1427 | int flow_indicators = 0; |
|---|
| | 1428 | int line_breaks = 0; |
|---|
| | 1429 | int special_characters = 0; |
|---|
| | 1430 | |
|---|
| | 1431 | int inline_spaces = 0; |
|---|
| | 1432 | int inline_breaks = 0; |
|---|
| | 1433 | int leading_spaces = 0; |
|---|
| | 1434 | int leading_breaks = 0; |
|---|
| | 1435 | int trailing_spaces = 0; |
|---|
| | 1436 | int trailing_breaks = 0; |
|---|
| | 1437 | int inline_breaks_spaces = 0; |
|---|
| | 1438 | int mixed_breaks_spaces = 0; |
|---|
| | 1439 | |
|---|
| | 1440 | int preceeded_by_space = 0; |
|---|
| | 1441 | int followed_by_space = 0; |
|---|
| | 1442 | int spaces = 0; |
|---|
| | 1443 | int breaks = 0; |
|---|
| | 1444 | int mixed = 0; |
|---|
| | 1445 | int leading = 0; |
|---|
| | 1446 | |
|---|
| | 1447 | emitter->scalar_data.value = value; |
|---|
| | 1448 | emitter->scalar_data.length = length; |
|---|
| | 1449 | |
|---|
| | 1450 | if (string.start == string.end) |
|---|
| | 1451 | { |
|---|
| | 1452 | emitter->scalar_data.multiline = 0; |
|---|
| | 1453 | emitter->scalar_data.flow_plain_allowed = 0; |
|---|
| | 1454 | emitter->scalar_data.block_plain_allowed = 1; |
|---|
| | 1455 | emitter->scalar_data.single_quoted_allowed = 1; |
|---|
| | 1456 | emitter->scalar_data.block_allowed = 0; |
|---|
| | 1457 | |
|---|
| | 1458 | return 1; |
|---|
| | 1459 | } |
|---|
| | 1460 | |
|---|
| | 1461 | if ((CHECK_AT(string, '-', 0) |
|---|
| | 1462 | && CHECK_AT(string, '-', 1) |
|---|
| | 1463 | && CHECK_AT(string, '-', 2)) |
|---|
| | 1464 | || (CHECK_AT(string, '.', 0) |
|---|
| | 1465 | && CHECK_AT(string, '.', 1) |
|---|
| | 1466 | && CHECK_AT(string, '.', 2))) { |
|---|
| | 1467 | block_indicators = 1; |
|---|
| | 1468 | flow_indicators = 1; |
|---|
| | 1469 | } |
|---|
| | 1470 | |
|---|
| | 1471 | preceeded_by_space = 1; |
|---|
| | 1472 | followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); |
|---|
| | 1473 | |
|---|
| | 1474 | while (string.pointer != string.end) |
|---|
| | 1475 | { |
|---|
| | 1476 | if (string.start == string.pointer) |
|---|
| | 1477 | { |
|---|
| | 1478 | if (CHECK(string, '#') || CHECK(string, ',') |
|---|
| | 1479 | || CHECK(string, '[') || CHECK(string, ']') |
|---|
| | 1480 | || CHECK(string, '{') || CHECK(string, '}') |
|---|
| | 1481 | || CHECK(string, '&') || CHECK(string, '*') |
|---|
| | 1482 | || CHECK(string, '!') || CHECK(string, '|') |
|---|
| | 1483 | || CHECK(string, '>') || CHECK(string, '\'') |
|---|
| | 1484 | || CHECK(string, '"') || CHECK(string, '%') |
|---|
| | 1485 | || CHECK(string, '@') || CHECK(string, '`')) { |
|---|
| | 1486 | flow_indicators = 1; |
|---|
| | 1487 | block_indicators = 1; |
|---|
| | 1488 | } |
|---|
| | 1489 | |
|---|
| | 1490 | if (CHECK(string, '?') || CHECK(string, ':')) { |
|---|
| | 1491 | flow_indicators = 1; |
|---|
| | 1492 | if (followed_by_space) { |
|---|
| | 1493 | block_indicators = 1; |
|---|
| | 1494 | } |
|---|
| | 1495 | } |
|---|
| | 1496 | |
|---|
| | 1497 | if (CHECK(string, '-') && followed_by_space) { |
|---|
| | 1498 | flow_indicators = 1; |
|---|
| | 1499 | block_indicators = 1; |
|---|
| | 1500 | } |
|---|
| | 1501 | } |
|---|
| | 1502 | else |
|---|
| | 1503 | { |
|---|
| | 1504 | if (CHECK(string, ',') || CHECK(string, '?') |
|---|
| | 1505 | || CHECK(string, '[') || CHECK(string, ']') |
|---|
| | 1506 | || CHECK(string, '{') || CHECK(string, '}')) { |
|---|
| | 1507 | flow_indicators = 1; |
|---|
| | 1508 | } |
|---|
| | 1509 | |
|---|
| | 1510 | if (CHECK(string, ':')) { |
|---|
| | 1511 | flow_indicators = 1; |
|---|
| | 1512 | if (followed_by_space) { |
|---|
| | 1513 | block_indicators = 1; |
|---|
| | 1514 | } |
|---|
| | 1515 | } |
|---|
| | 1516 | |
|---|
| | 1517 | if (CHECK(string, '#') && preceeded_by_space) { |
|---|
| | 1518 | flow_indicators = 1; |
|---|
| | 1519 | block_indicators = 1; |
|---|
| | 1520 | } |
|---|
| | 1521 | } |
|---|
| | 1522 | |
|---|
| | 1523 | if (!IS_PRINTABLE(string) |
|---|
| | 1524 | || (!IS_ASCII(string) && !emitter->unicode)) { |
|---|
| | 1525 | special_characters = 1; |
|---|
| | 1526 | } |
|---|
| | 1527 | |
|---|
| | 1528 | if (IS_BREAK(string)) { |
|---|
| | 1529 | line_breaks = 1; |
|---|
| | 1530 | } |
|---|
| | 1531 | |
|---|
| | 1532 | if (IS_SPACE(string)) |
|---|
| | 1533 | { |
|---|
| | 1534 | spaces = 1; |
|---|
| | 1535 | if (string.start == string.pointer) { |
|---|
| | 1536 | leading = 1; |
|---|
| | 1537 | } |
|---|
| | 1538 | } |
|---|
| | 1539 | |
|---|
| | 1540 | else if (IS_BREAK(string)) |
|---|
| | 1541 | { |
|---|
| | 1542 | if (spaces) { |
|---|
| | 1543 | mixed = 1; |
|---|
| | 1544 | } |
|---|
| | 1545 | breaks = 1; |
|---|
| | 1546 | if (string.start == string.pointer) { |
|---|
| | 1547 | leading = 1; |
|---|
| | 1548 | } |
|---|
| | 1549 | } |
|---|
| | 1550 | |
|---|
| | 1551 | else if (spaces || breaks) |
|---|
| | 1552 | { |
|---|
| | 1553 | if (leading) { |
|---|
| | 1554 | if (spaces && breaks) { |
|---|
| | 1555 | mixed_breaks_spaces = 1; |
|---|
| | 1556 | } |
|---|
| | 1557 | else if (spaces) { |
|---|
| | 1558 | leading_spaces = 1; |
|---|
| | 1559 | } |
|---|
| | 1560 | else if (breaks) { |
|---|
| | 1561 | leading_breaks = 1; |
|---|
| | 1562 | } |
|---|
| | 1563 | } |
|---|
| | 1564 | else { |
|---|
| | 1565 | if (mixed) { |
|---|
| | 1566 | mixed_breaks_spaces = 1; |
|---|
| | 1567 | } |
|---|
| | 1568 | else if (spaces && breaks) { |
|---|
| | 1569 | inline_breaks_spaces = 1; |
|---|
| | 1570 | } |
|---|
| | 1571 | else if (spaces) { |
|---|
| | 1572 | inline_spaces = 1; |
|---|
| | 1573 | } |
|---|
| | 1574 | else if (breaks) { |
|---|
| | 1575 | inline_breaks = 1; |
|---|
| | 1576 | } |
|---|
| | 1577 | } |
|---|
| | 1578 | spaces = breaks = mixed = leading = 0; |
|---|
| | 1579 | } |
|---|
| | 1580 | |
|---|
| | 1581 | preceeded_by_space = IS_BLANKZ(string); |
|---|
| | 1582 | MOVE(string); |
|---|
| | 1583 | if (string.pointer != string.end) { |
|---|
| | 1584 | followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); |
|---|
| | 1585 | } |
|---|
| | 1586 | } |
|---|
| | 1587 | |
|---|
| | 1588 | emitter->scalar_data.multiline = line_breaks; |
|---|
| | 1589 | |
|---|
| | 1590 | emitter->scalar_data.flow_plain_allowed = 1; |
|---|
| | 1591 | emitter->scalar_data.block_plain_allowed = 1; |
|---|
| | 1592 | emitter->scalar_data.single_quoted_allowed = 1; |
|---|
| | 1593 | emitter->scalar_data.block_allowed = 1; |
|---|
| | 1594 | |
|---|
| | 1595 | if (leading_spaces || leading_breaks || trailing_spaces) { |
|---|
| | 1596 | emitter->scalar_data.flow_plain_allowed = 0; |
|---|
| | 1597 | emitter->scalar_data.block_plain_allowed = 0; |
|---|
| | 1598 | emitter->scalar_data.block_allowed = 0; |
|---|
| | 1599 | } |
|---|
| | 1600 | |
|---|
| | 1601 | if (trailing_breaks) { |
|---|
| | 1602 | emitter->scalar_data.flow_plain_allowed = 0; |
|---|
| | 1603 | emitter->scalar_data.block_plain_allowed = 0; |
|---|
| | 1604 | } |
|---|
| | 1605 | |
|---|
| | 1606 | if (inline_breaks_spaces) { |
|---|
| | 1607 | emitter->scalar_data.flow_plain_allowed = 0; |
|---|
| | 1608 | emitter->scalar_data.block_plain_allowed = 0; |
|---|
| | 1609 | emitter->scalar_data.single_quoted_allowed = 0; |
|---|
| | 1610 | } |
|---|
| | 1611 | |
|---|
| | 1612 | if (mixed_breaks_spaces || special_characters) { |
|---|
| | 1613 | emitter->scalar_data.flow_plain_allowed = 0; |
|---|
| | 1614 | emitter->scalar_data.block_plain_allowed = 0; |
|---|
| | 1615 | emitter->scalar_data.single_quoted_allowed = 0; |
|---|
| | 1616 | emitter->scalar_data.block_allowed = 0; |
|---|
| | 1617 | } |
|---|
| | 1618 | |
|---|
| | 1619 | if (line_breaks) { |
|---|
| | 1620 | emitter->scalar_data.flow_plain_allowed = 0; |
|---|
| | 1621 | emitter->scalar_data.block_plain_allowed = 0; |
|---|
| | 1622 | } |
|---|
| | 1623 | |
|---|
| | 1624 | if (flow_indicators) { |
|---|
| | 1625 | emitter->scalar_data.flow_plain_allowed = 0; |
|---|
| < |
|---|