Index: src/libictranslate/ResourceManager.cpp =================================================================== diff -u -r9d10e42a5ed39ac9a7dddd973679296994c9bf0e -r945fdda3ea66a8ce8a09ee9307b04c3d79d518b3 --- src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision 9d10e42a5ed39ac9a7dddd973679296994c9bf0e) +++ src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision 945fdda3ea66a8ce8a09ee9307b04c3d79d518b3) @@ -258,42 +258,49 @@ return eResult_ContentWarning; // formatting strings check - tstring_t strRefFmt; - const tchar_t* pszData = rReferenceItem.m_pszText; - while((pszData = _tcschr(pszData, _t('%'))) != NULL) - { - pszData++; // it works assuming the string is null-terminated - switch(*pszData) - { - case _t('%'): - pszData++; - break; // it's a %% - skip it - default: - strRefFmt += *pszData; - } - } + std::set setRefFmt; + if(!rReferenceItem.GetFormatStrings(setRefFmt)) + return eResult_ContentWarning; - tstring_t strOwnFmt; - pszData = m_pszText; + std::set setThisFmt; + if(!GetFormatStrings(setThisFmt)) + return eResult_ContentWarning; + + if(setRefFmt != setThisFmt) + return eResult_ContentWarning; + + return eResult_Valid; +} + +bool CTranslationItem::GetFormatStrings(std::set& setFmtStrings) const +{ + setFmtStrings.clear(); + + const tchar_t* pszData = m_pszText; + const tchar_t* pszNext = NULL; + const size_t stMaxFmt = 256; + tchar_t szFmt[stMaxFmt]; while((pszData = _tcschr(pszData, _t('%'))) != NULL) { pszData++; // it works assuming the string is null-terminated - if(*pszData) - { - switch(*pszData) - { - case _t('%'): - pszData++; - break; // it's a %% - skip it - default: - strOwnFmt += *pszData; - } - } + + // search the end of fmt string + pszNext = pszData; + while(*pszNext && isalpha(*pszNext)) + pszNext++; + + // if we have bigger buffer needs than is available + if(pszNext - pszData >= stMaxFmt) + return false; + + // copy data + _tcsncpy(szFmt, pszData, pszNext - pszData); + szFmt[pszNext - pszData] = _T('\0'); + + setFmtStrings.insert(tstring_t(szFmt)); } - if(strRefFmt != strOwnFmt) - return eResult_ContentWarning; - return eResult_Valid; + return true; } CLangData::CLangData() : Index: src/libictranslate/ResourceManager.h =================================================================== diff -u -r82966de7c49e40c3f79a4bf14f9f4dd34793543e -r945fdda3ea66a8ce8a09ee9307b04c3d79d518b3 --- src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision 82966de7c49e40c3f79a4bf14f9f4dd34793543e) +++ src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision 945fdda3ea66a8ce8a09ee9307b04c3d79d518b3) @@ -20,6 +20,7 @@ #define __RESOURCEMANAGER_H__ #include "libictranslate.h" +#include #include #include #include @@ -92,6 +93,9 @@ ECompareResult Compare(const CTranslationItem& rReferenceItem); protected: + bool GetFormatStrings(std::set& setFmtStrings) const; + +protected: tchar_t* m_pszText; size_t m_stTextLength; uint_t m_uiChecksum;