X-Git-Url: https://vaikene.ee/gitweb/highlight.css?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Futil.h;h=486da25416e43be5bdb46ca024caa741d777c7e9;hb=77854ea7bd165f8d9afd2cba1490335a67001ab7;hp=4b5e4c9fd81ce62aa7778f8a233b11c5e157d116;hpb=12fe56ffc347b9a7b2a5ec140ec874038cde8c3b;p=evaf diff --git a/src/libs/Common/util.h b/src/libs/Common/util.h index 4b5e4c9..486da25 100644 --- a/src/libs/Common/util.h +++ b/src/libs/Common/util.h @@ -70,12 +70,61 @@ inline bool isFalse(QString const & str) * @li QVariant::Int - base 10 is used; * @li QVariant::Double - the decimal point is expecte to be '.' regardless which locale is used; * @li QVariant::Bool - tries to use isTrue() and isFalse() methods; otherwise performs a conversion to QVariant::uint; - * @li QVariant::Char - if the string begins with "\0x", expects it to be an ASCII code in hex; if the - * string begins with "\0", expects it to be an ASCII code in oct; otherwise uses the first character in the string; + * @li QVariant::Char - if the string begins with "\0x", expects it to be a UTF-16 code in hex; if the + * string begins with "\0", expects it to be a UTF-16 code in oct; if the string begins with "&", expects it to + * be a numeric character reference ("&#nnnn;" or "&#xhhhh;") or a predefined character entity reference; + * otherwise uses the first character in the string; */ COMMON_EXPORT QVariant toVariant(QString const & value, QVariant const & defaultValue); +/** + * Converts unicode strings to escaped 7-bit character arrays. + * @param str Unicode string + * @return Escaped 7-bit character array + * + * This function converts a unicode (or any) string to the escaped 7-bit character array. Characters that cannot + * be output directly as a printable 7-bit character are output as numeric character references. The result can be + * directly inserted into XML or HTML documents and later converted back with the eVaf::Common::strFromEscapedCharArray() + * function. + * + * For example, "Groß" becomes "Groß". + */ +COMMON_EXPORT QByteArray strToEscapedCharArray(QString const & str); + +/** + * Converts escaped 7-bit character arrays to unicode string. + * @param str Escaped 7-bit character array + * @return Unicode string + * + * This function converts an escaped 7-bit character array to the unicode string. Numeric character references and + * character entity references are expanded to actual unicode characters. + */ +COMMON_EXPORT QString strFromEscapedCharArray(QByteArray const & str); + +/** + * Converts binary arrays to escaped 7-bit character arrays + * @param src Binary array + * @return Escaped 7-bit character array + * + * This function converts a binary array to the escaped 7-bit character array. Bytes that cannot be output + * directly as printable 7-bit characters are output as numeric character references. The result can be directly + * inserted into XML or HTML documents and later converted back with the eVaf::Common::binFromEscapedCharArray() + * function. + * + * For example, "Hello\r\n" becomes "Hello ". + */ +COMMON_EXPORT QByteArray binToEscapedCharArray(QByteArray const & src); + +/** + * Converts escaped 7-bit character arrays to binary arrays + * @param str Escaped 7-bit character array + * @return Binary array + * + * This function converts an escaped 7-bit character array to the binary array. Numeric character references and + * character entoty references are expanded to characters and binary bytes. + */ +COMMON_EXPORT QByteArray binFromEscapedCharArray(QByteArray const & str); } // namespace eVaf::Common } // namespace eVaf