diff options
author | Karlson2k <k2k@narod.ru> | 2013-10-19 15:30:50 +0400 |
---|---|---|
committer | Karlson2k <k2k@narod.ru> | 2013-10-19 15:58:27 +0400 |
commit | 8ce2293cb59c2b6ceee81bd398bb55b14a3c2fec (patch) | |
tree | 6daa53a91f1f048efee93ca97943843432a5b88a | |
parent | bf9424e47d6025a43654d3dff4d62178ca86ca7d (diff) |
CharsetConverter: 'logicalToVisualBiDi' ability to fail on bad strings
-rw-r--r-- | xbmc/utils/CharsetConverter.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/xbmc/utils/CharsetConverter.cpp b/xbmc/utils/CharsetConverter.cpp index 2a75c62af2..0c2bf0086f 100644 --- a/xbmc/utils/CharsetConverter.cpp +++ b/xbmc/utils/CharsetConverter.cpp @@ -289,7 +289,7 @@ enum StdConversionType /* Keep it in sync with CCharsetConverter::CInnerConverte class CCharsetConverter::CInnerConverter { public: - static bool logicalToVisualBiDi(const std::u32string& stringSrc, std::u32string& stringDst, FriBidiCharType base = FRIBIDI_TYPE_LTR); + static bool logicalToVisualBiDi(const std::u32string& stringSrc, std::u32string& stringDst, FriBidiCharType base = FRIBIDI_TYPE_LTR, const bool failOnBadString = false); template<class INPUT,class OUTPUT> static bool stdConvert(StdConversionType convertType, const INPUT& strSource, OUTPUT& strDest, bool failOnInvalidChar = false); @@ -487,7 +487,7 @@ bool CCharsetConverter::CInnerConverter::convert(iconv_t type, int multiplier, c return true; } -bool CCharsetConverter::CInnerConverter::logicalToVisualBiDi(const std::u32string& stringSrc, std::u32string& stringDst, FriBidiCharType base /*= FRIBIDI_TYPE_LTR*/) +bool CCharsetConverter::CInnerConverter::logicalToVisualBiDi(const std::u32string& stringSrc, std::u32string& stringDst, FriBidiCharType base /*= FRIBIDI_TYPE_LTR*/, const bool failOnBadString /*= false*/) { stringDst.clear(); @@ -518,6 +518,7 @@ bool CCharsetConverter::CInnerConverter::logicalToVisualBiDi(const std::u32strin return false; } + bool bidiFailed = false; FriBidiCharType baseCopy = base; // preserve same value for all lines, required because fribidi_log2vis will modify parameter value if (fribidi_log2vis((const FriBidiChar*)(stringSrc.c_str() + lineStart), lineLen, &baseCopy, visual, NULL, NULL, NULL)) { @@ -525,9 +526,17 @@ bool CCharsetConverter::CInnerConverter::logicalToVisualBiDi(const std::u32strin const int newLen = fribidi_remove_bidi_marks(visual, lineLen, NULL, NULL, NULL); if (newLen > 0) stringDst.append((const char32_t*)visual, (size_t)newLen); + else if (newLen < 0) + bidiFailed = failOnBadString; } + else + bidiFailed = failOnBadString; + free(visual); + if (bidiFailed) + return false; + lineStart = lineEnd; } while (lineStart < srcLen); |