| 1652 | |
| 1653 | |
| 1654 | static void |
| 1655 | icvYMLWriteString( CvFileStorage* fs, const char* key, |
| 1656 | const char* str, int quote CV_DEFAULT(0)) |
| 1657 | { |
| 1658 | char buf[CV_FS_MAX_LEN*4+16]; |
| 1659 | char* data = (char*)str; |
| 1660 | int i, len; |
| 1661 | |
| 1662 | if( !str ) |
| 1663 | CV_Error( CV_StsNullPtr, "Null string pointer" ); |
| 1664 | |
| 1665 | len = (int)strlen(str); |
| 1666 | if( len > CV_FS_MAX_LEN ) |
| 1667 | CV_Error( CV_StsBadArg, "The written string is too long" ); |
| 1668 | |
| 1669 | if( quote || len == 0 || str[0] != str[len-1] || (str[0] != '\"' && str[0] != '\'') ) |
| 1670 | { |
| 1671 | int need_quote = quote || len == 0; |
| 1672 | data = buf; |
| 1673 | *data++ = '\"'; |
| 1674 | for( i = 0; i < len; i++ ) |
| 1675 | { |
| 1676 | char c = str[i]; |
| 1677 | |
| 1678 | if( !need_quote && !cv_isalnum(c) && c != '_' && c != ' ' && c != '-' && |
| 1679 | c != '(' && c != ')' && c != '/' && c != '+' && c != ';' ) |
| 1680 | need_quote = 1; |
| 1681 | |
| 1682 | if( !cv_isalnum(c) && (!cv_isprint(c) || c == '\\' || c == '\'' || c == '\"') ) |
| 1683 | { |
| 1684 | *data++ = '\\'; |
| 1685 | if( cv_isprint(c) ) |
| 1686 | *data++ = c; |
| 1687 | else if( c == '\n' ) |
| 1688 | *data++ = 'n'; |
| 1689 | else if( c == '\r' ) |
| 1690 | *data++ = 'r'; |
| 1691 | else if( c == '\t' ) |
| 1692 | *data++ = 't'; |
| 1693 | else |
| 1694 | { |
| 1695 | sprintf( data, "x%02x", c ); |
| 1696 | data += 3; |
| 1697 | } |
| 1698 | } |
| 1699 | else |
| 1700 | *data++ = c; |
| 1701 | } |
| 1702 | if( !need_quote && (cv_isdigit(str[0]) || |
| 1703 | str[0] == '+' || str[0] == '-' || str[0] == '.' )) |
| 1704 | need_quote = 1; |
| 1705 | |
| 1706 | if( need_quote ) |
| 1707 | *data++ = '\"'; |
| 1708 | *data++ = '\0'; |
| 1709 | data = buf + !need_quote; |
| 1710 | } |
| 1711 |
nothing calls this directly
no test coverage detected