Changeset 309 for libyaml/branches/stable/src/emitter.c
- Timestamp:
- 12/27/08 07:14:54 (4 years ago)
- File:
-
- 1 edited
-
libyaml/branches/stable/src/emitter.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/branches/stable/src/emitter.c
r241 r309 250 250 251 251 static int 252 yaml_emitter_ determine_chomping(yaml_emitter_t *emitter,252 yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter, 253 253 yaml_string_t string); 254 254 … … 1455 1455 int special_characters = 0; 1456 1456 1457 int inline_spaces = 0; 1458 int inline_breaks = 0; 1459 int leading_spaces = 0; 1460 int leading_breaks = 0; 1461 int trailing_spaces = 0; 1462 int trailing_breaks = 0; 1463 int inline_breaks_spaces = 0; 1464 int mixed_breaks_spaces = 0; 1465 1466 int preceeded_by_space = 0; 1467 int followed_by_space = 0; 1468 int spaces = 0; 1469 int breaks = 0; 1470 int mixed = 0; 1471 int leading = 0; 1457 int leading_space = 0; 1458 int leading_break = 0; 1459 int trailing_space = 0; 1460 int trailing_break = 0; 1461 int break_space = 0; 1462 int space_break = 0; 1463 1464 int preceeded_by_whitespace = 0; 1465 int followed_by_whitespace = 0; 1466 int previous_space = 0; 1467 int previous_break = 0; 1472 1468 1473 1469 emitter->scalar_data.value = value; … … 1495 1491 } 1496 1492 1497 preceeded_by_ space = 1;1498 followed_by_ space = IS_BLANKZ_AT(string, WIDTH(string));1493 preceeded_by_whitespace = 1; 1494 followed_by_whitespace = IS_BLANKZ_AT(string, WIDTH(string)); 1499 1495 1500 1496 while (string.pointer != string.end) … … 1516 1512 if (CHECK(string, '?') || CHECK(string, ':')) { 1517 1513 flow_indicators = 1; 1518 if (followed_by_ space) {1514 if (followed_by_whitespace) { 1519 1515 block_indicators = 1; 1520 1516 } 1521 1517 } 1522 1518 1523 if (CHECK(string, '-') && followed_by_ space) {1519 if (CHECK(string, '-') && followed_by_whitespace) { 1524 1520 flow_indicators = 1; 1525 1521 block_indicators = 1; … … 1536 1532 if (CHECK(string, ':')) { 1537 1533 flow_indicators = 1; 1538 if (followed_by_ space) {1534 if (followed_by_whitespace) { 1539 1535 block_indicators = 1; 1540 1536 } 1541 1537 } 1542 1538 1543 if (CHECK(string, '#') && preceeded_by_ space) {1539 if (CHECK(string, '#') && preceeded_by_whitespace) { 1544 1540 flow_indicators = 1; 1545 1541 block_indicators = 1; … … 1558 1554 if (IS_SPACE(string)) 1559 1555 { 1560 spaces = 1;1561 1556 if (string.start == string.pointer) { 1562 leading = 1; 1563 } 1564 } 1565 1557 leading_space = 1; 1558 } 1559 if (string.pointer+WIDTH(string) == string.end) { 1560 trailing_space = 1; 1561 } 1562 if (previous_break) { 1563 break_space = 1; 1564 } 1565 previous_space = 1; 1566 previous_break = 0; 1567 } 1566 1568 else if (IS_BREAK(string)) 1567 1569 { 1568 if (spaces) {1569 mixed = 1;1570 }1571 breaks = 1;1572 1570 if (string.start == string.pointer) { 1573 leading = 1; 1574 } 1575 } 1576 1577 else if (spaces || breaks) 1571 leading_break = 1; 1572 } 1573 if (string.pointer+WIDTH(string) == string.end) { 1574 trailing_break = 1; 1575 } 1576 if (previous_space) { 1577 space_break = 1; 1578 } 1579 previous_space = 0; 1580 previous_break = 1; 1581 } 1582 else 1578 1583 { 1579 if (leading) { 1580 if (spaces && breaks) { 1581 mixed_breaks_spaces = 1; 1582 } 1583 else if (spaces) { 1584 leading_spaces = 1; 1585 } 1586 else if (breaks) { 1587 leading_breaks = 1; 1588 } 1589 } 1590 else { 1591 if (mixed) { 1592 mixed_breaks_spaces = 1; 1593 } 1594 else if (spaces && breaks) { 1595 inline_breaks_spaces = 1; 1596 } 1597 else if (spaces) { 1598 inline_spaces = 1; 1599 } 1600 else if (breaks) { 1601 inline_breaks = 1; 1602 } 1603 } 1604 spaces = breaks = mixed = leading = 0; 1605 } 1606 1607 if ((spaces || breaks) && string.pointer == string.end-1) 1608 { 1609 if (spaces && breaks) { 1610 mixed_breaks_spaces = 1; 1611 } 1612 else if (spaces) { 1613 if (leading) { 1614 leading_spaces = 1; 1615 } 1616 trailing_spaces = 1; 1617 } 1618 else if (breaks) { 1619 if (leading) { 1620 leading_breaks = 1; 1621 } 1622 trailing_breaks = 1; 1623 } 1624 } 1625 1626 preceeded_by_space = IS_BLANKZ(string); 1584 previous_space = 0; 1585 previous_break = 0; 1586 } 1587 1588 preceeded_by_whitespace = IS_BLANKZ(string); 1627 1589 MOVE(string); 1628 1590 if (string.pointer != string.end) { 1629 followed_by_ space = IS_BLANKZ_AT(string, WIDTH(string));1591 followed_by_whitespace = IS_BLANKZ_AT(string, WIDTH(string)); 1630 1592 } 1631 1593 } … … 1638 1600 emitter->scalar_data.block_allowed = 1; 1639 1601 1640 if (leading_space s || leading_breaks || trailing_spaces) {1602 if (leading_space || leading_break || trailing_space || trailing_break) { 1641 1603 emitter->scalar_data.flow_plain_allowed = 0; 1642 1604 emitter->scalar_data.block_plain_allowed = 0; 1605 } 1606 1607 if (trailing_space) { 1643 1608 emitter->scalar_data.block_allowed = 0; 1644 1609 } 1645 1610 1646 if (trailing_breaks) { 1647 emitter->scalar_data.flow_plain_allowed = 0; 1648 emitter->scalar_data.block_plain_allowed = 0; 1649 } 1650 1651 if (inline_breaks_spaces) { 1611 if (break_space) { 1652 1612 emitter->scalar_data.flow_plain_allowed = 0; 1653 1613 emitter->scalar_data.block_plain_allowed = 0; … … 1655 1615 } 1656 1616 1657 if ( mixed_breaks_spaces|| special_characters) {1617 if (space_break || special_characters) { 1658 1618 emitter->scalar_data.flow_plain_allowed = 0; 1659 1619 emitter->scalar_data.block_plain_allowed = 0; … … 2163 2123 2164 2124 static int 2165 yaml_emitter_ determine_chomping(yaml_emitter_t *emitter,2125 yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter, 2166 2126 yaml_string_t string) 2167 2127 { 2128 char indent_hint[2]; 2129 char *chomp_hint = NULL; 2130 2131 if (IS_SPACE(string) || IS_BREAK(string)) 2132 { 2133 indent_hint[0] = '0' + (char)emitter->best_indent; 2134 indent_hint[1] = '\0'; 2135 if (!yaml_emitter_write_indicator(emitter, indent_hint, 0, 0, 0)) 2136 return 0; 2137 } 2138 2168 2139 string.pointer = string.end; 2169 2140 if (string.start == string.pointer) 2170 return -1; 2171 do { 2172 string.pointer --; 2173 } while ((*string.pointer & 0xC0) == 0x80); 2174 if (!IS_BREAK(string)) 2175 return -1; 2176 if (string.start == string.pointer) 2177 return 0; 2178 do { 2179 string.pointer --; 2180 } while ((*string.pointer & 0xC0) == 0x80); 2181 if (!IS_BREAK(string)) 2182 return 0; 2183 return +1; 2184 2141 { 2142 chomp_hint = "-"; 2143 } 2144 else 2145 { 2146 do { 2147 string.pointer --; 2148 } while ((*string.pointer & 0xC0) == 0x80); 2149 if (!IS_BREAK(string)) 2150 { 2151 chomp_hint = "-"; 2152 } 2153 else if (string.start == string.pointer) 2154 { 2155 chomp_hint = "+"; 2156 } 2157 else 2158 { 2159 do { 2160 string.pointer --; 2161 } while ((*string.pointer & 0xC0) == 0x80); 2162 if (IS_BREAK(string)) 2163 { 2164 chomp_hint = "+"; 2165 } 2166 } 2167 } 2168 2169 if (chomp_hint) 2170 { 2171 if (!yaml_emitter_write_indicator(emitter, chomp_hint, 0, 0, 0)) 2172 return 0; 2173 } 2174 2175 return 1; 2185 2176 } 2186 2177 … … 2190 2181 { 2191 2182 yaml_string_t string = STRING(value, length); 2192 int chomp = yaml_emitter_determine_chomping(emitter, string); 2193 int breaks = 0; 2194 2195 if (!yaml_emitter_write_indicator(emitter, 2196 chomp == -1 ? "|-" : chomp == +1 ? "|+" : "|", 1, 0, 0)) 2197 return 0; 2198 if (!yaml_emitter_write_indent(emitter)) 2199 return 0; 2183 int breaks = 1; 2184 2185 if (!yaml_emitter_write_indicator(emitter, "|", 1, 0, 0)) 2186 return 0; 2187 if (!yaml_emitter_write_block_scalar_hints(emitter, string)) 2188 return 0; 2189 if (!PUT_BREAK(emitter)) return 0; 2190 emitter->indention = 1; 2191 emitter->whitespace = 1; 2200 2192 2201 2193 while (string.pointer != string.end) … … 2226 2218 { 2227 2219 yaml_string_t string = STRING(value, length); 2228 int chomp = yaml_emitter_determine_chomping(emitter, string);2229 2220 int breaks = 1; 2230 int leading_spaces = 0; 2231 2232 if (!yaml_emitter_write_indicator(emitter, 2233 chomp == -1 ? ">-" : chomp == +1 ? ">+" : ">", 1, 0, 0)) 2234 return 0; 2235 if (!yaml_emitter_write_indent(emitter)) 2236 return 0; 2221 int leading_spaces = 1; 2222 2223 if (!yaml_emitter_write_indicator(emitter, ">", 1, 0, 0)) 2224 return 0; 2225 if (!yaml_emitter_write_block_scalar_hints(emitter, string)) 2226 return 0; 2227 if (!PUT_BREAK(emitter)) return 0; 2228 emitter->indention = 1; 2229 emitter->whitespace = 1; 2237 2230 2238 2231 while (string.pointer != string.end)
Note: See TracChangeset
for help on using the changeset viewer.
