| 1442 | \****************************************************************************************/ |
| 1443 | |
| 1444 | static void |
| 1445 | icvYMLWrite( CvFileStorage* fs, const char* key, const char* data ) |
| 1446 | { |
| 1447 | int i, keylen = 0; |
| 1448 | int datalen = 0; |
| 1449 | int struct_flags; |
| 1450 | char* ptr; |
| 1451 | |
| 1452 | struct_flags = fs->struct_flags; |
| 1453 | |
| 1454 | if( key && key[0] == '\0' ) |
| 1455 | key = 0; |
| 1456 | |
| 1457 | if( CV_NODE_IS_COLLECTION(struct_flags) ) |
| 1458 | { |
| 1459 | if( (CV_NODE_IS_MAP(struct_flags) ^ (key != 0)) ) |
| 1460 | CV_Error( CV_StsBadArg, "An attempt to add element without a key to a map, " |
| 1461 | "or add element with key to sequence" ); |
| 1462 | } |
| 1463 | else |
| 1464 | { |
| 1465 | fs->is_first = 0; |
| 1466 | struct_flags = CV_NODE_EMPTY | (key ? CV_NODE_MAP : CV_NODE_SEQ); |
| 1467 | } |
| 1468 | |
| 1469 | if( key ) |
| 1470 | { |
| 1471 | keylen = (int)strlen(key); |
| 1472 | if( keylen == 0 ) |
| 1473 | CV_Error( CV_StsBadArg, "The key is an empty" ); |
| 1474 | |
| 1475 | if( keylen > CV_FS_MAX_LEN ) |
| 1476 | CV_Error( CV_StsBadArg, "The key is too long" ); |
| 1477 | } |
| 1478 | |
| 1479 | if( data ) |
| 1480 | datalen = (int)strlen(data); |
| 1481 | |
| 1482 | if( CV_NODE_IS_FLOW(struct_flags) ) |
| 1483 | { |
| 1484 | int new_offset; |
| 1485 | ptr = fs->buffer; |
| 1486 | if( !CV_NODE_IS_EMPTY(struct_flags) ) |
| 1487 | *ptr++ = ','; |
| 1488 | new_offset = (int)(ptr - fs->buffer_start) + keylen + datalen; |
| 1489 | if( new_offset > fs->wrap_margin && new_offset - fs->struct_indent > 10 ) |
| 1490 | { |
| 1491 | fs->buffer = ptr; |
| 1492 | ptr = icvFSFlush(fs); |
| 1493 | } |
| 1494 | else |
| 1495 | *ptr++ = ' '; |
| 1496 | } |
| 1497 | else |
| 1498 | { |
| 1499 | ptr = icvFSFlush(fs); |
| 1500 | if( !CV_NODE_IS_MAP(struct_flags) ) |
| 1501 | { |
no test coverage detected