diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-18 09:52:04 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-18 10:04:10 +0100 |
commit | bdc9bdccb61130355784800f99b4fd726d6c424d (patch) | |
tree | f3160884d66d8528ac818638bd2007ae19c8edc9 /svtools/source/svhtml | |
parent | 70e22d4996e71e019f62743893f041797f050361 (diff) |
tdf#123485 Excel 2003 xml file with xls extension detected as HTML
regression from
commit 7ea01578eed8459678369d0256de016930b3af40
Date: Fri Oct 19 13:04:43 2018 +0200
loplugin:staticvar in soltools..svx
turns out using std::lower_bound as a binary search is rather painful.
Change-Id: Ide6f5cf4ff91a8832daa43a7fec2f5cfc97fc94a
Reviewed-on: https://gerrit.libreoffice.org/67951
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svtools/source/svhtml')
-rw-r--r-- | svtools/source/svhtml/htmlkywd.cxx | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/svtools/source/svhtml/htmlkywd.cxx b/svtools/source/svhtml/htmlkywd.cxx index 3699c08accfe..92bcb9e9bce6 100644 --- a/svtools/source/svhtml/htmlkywd.cxx +++ b/svtools/source/svhtml/htmlkywd.cxx @@ -40,9 +40,18 @@ static bool sortCompare(const TokenEntry<T> & lhs, const TokenEntry<T> & rhs) return strcmp(lhs.sToken.data, rhs.sToken.data) < 0; } template<typename T> -static bool findCompare(const TokenEntry<T> & lhs, const OUString & s) +static bool findCompare(const TokenEntry<T> & lhs, const OUString & rhs) { - return s.compareToAscii(lhs.sToken.data) > 0; + return rhs.compareToAscii(lhs.sToken.data) > 0; +} +template<typename T, size_t LEN> +static T search(TokenEntry<T> const (&dataTable)[LEN], const OUString & key, T notFoundValue) +{ + auto findIt = std::lower_bound( std::begin(dataTable), std::end(dataTable), + key, findCompare<T> ); + if (findIt != std::end(dataTable) && key.compareToAscii(findIt->sToken.data)==0) + return findIt->nToken; + return notFoundValue; } using HTML_TokenEntry = TokenEntry<HtmlTokenId>; @@ -174,10 +183,7 @@ HtmlTokenId GetHTMLToken( const OUString& rName ) if( rName.startsWith( OOO_STRING_SVTOOLS_HTML_comment )) return HtmlTokenId::COMMENT; - auto findIt = std::lower_bound( std::begin(aHTMLTokenTab), std::end(aHTMLTokenTab), rName, findCompare<HtmlTokenId>); - if( findIt != std::end(aHTMLTokenTab) && !findCompare<HtmlTokenId>(*findIt, rName)) - return findIt->nToken; - return HtmlTokenId::NONE; + return search( aHTMLTokenTab, rName, HtmlTokenId::NONE); } using HTML_CharEntry = TokenEntry<sal_Unicode>; @@ -459,11 +465,7 @@ sal_Unicode GetHTMLCharName( const OUString& rName ) bSortCharKeyWords = true; } - auto findIt = std::lower_bound( std::begin(aHTMLCharNameTab), std::end(aHTMLCharNameTab), - rName, findCompare<sal_Unicode> ); - if (findIt != std::end(aHTMLCharNameTab) && !findCompare<sal_Unicode>(*findIt, rName)) - return findIt->nToken; - return 0; + return search<sal_Unicode>( aHTMLCharNameTab, rName, 0); } // Flag: Options table has already been sorted @@ -634,10 +636,7 @@ HtmlOptionId GetHTMLOption( const OUString& rName ) bSortOptionKeyWords = true; } - auto findIt = std::lower_bound( std::begin(aHTMLOptionTab), std::end(aHTMLOptionTab), rName, findCompare<HtmlOptionId>); - if (findIt != std::end(aHTMLOptionTab) && !findCompare<HtmlOptionId>(*findIt, rName)) - return findIt->nToken; - return HtmlOptionId::UNKNOWN; + return search( aHTMLOptionTab, rName, HtmlOptionId::UNKNOWN); } @@ -805,12 +804,7 @@ sal_uInt32 GetHTMLColor( const OUString& rName ) OUString aLowerCase(rName.toAsciiLowerCase()); - auto findIt = std::lower_bound( std::begin(aHTMLColorNameTab), std::end(aHTMLColorNameTab), - aLowerCase, findCompare<sal_uInt32> ); - if (findIt != std::end(aHTMLColorNameTab) && !findCompare<sal_uInt32>(*findIt, aLowerCase)) - return findIt->nToken; - - return HTML_NO_COLOR; + return search<sal_uInt32>( aHTMLColorNameTab, aLowerCase, HTML_NO_COLOR); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |