X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Futil.h;h=de094b3e791d85ef6caec890a532f521709e1617;hb=926606ce83f3a702d67c5c2c42478b091f78fdc4;hp=799f8aacebb61a16df1d7a05b033a14ce4822adc;hpb=814d12e0a340ae11fa4a22077b37316aa41716d7;p=evaf diff --git a/src/libs/Common/util.h b/src/libs/Common/util.h index 799f8aa..de094b3 100644 --- a/src/libs/Common/util.h +++ b/src/libs/Common/util.h @@ -58,15 +58,45 @@ inline bool isFalse(QString const & str) * Converts strings to variant values * @param value The string * @param defaultValue The default value - * @param Variant value converted from the string or the default if failed + * @return value converted from the string or the default if failed * * This function converts strings to variant values. The type of the expected value is determined * from the default value. If the string fails to convert to the expected type, returns the * default value. + * + * If the default value is of one of the following types, then the following conversion rules are applied: + * @li QVariant::UInt - if the string begins with "0x", base 16 is used; if the string begins with "0", + * base 8 is used; otherwise base 10 is used; + * @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; */ 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::fromEscapedString() + * function. + */ +COMMON_EXPORT QByteArray toEscapedString(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 a unicode string. Numeric character references and + * character entity references are expanded to actual unicode characters. + */ +COMMON_EXPORT QString fromEscapedString(QByteArray const & str); } // namespace eVaf::Common } // namespace eVaf