From 98b7209efba02f3a61431a0ed59c817993dbd51f Mon Sep 17 00:00:00 2001 From: Blake-Madden Date: Fri, 1 Dec 2023 12:26:46 -0500 Subject: [PATCH] Make font and file extension checks static, add more known extensions --- src/i18n_review.cpp | 109 ++++++++++++++++++++++----------------- src/i18n_review.h | 32 ++++++------ src/i18n_string_util.cpp | 8 ++- 3 files changed, 83 insertions(+), 66 deletions(-) diff --git a/src/i18n_review.cpp b/src/i18n_review.cpp index e117e8b..54568cc 100644 --- a/src/i18n_review.cpp +++ b/src/i18n_review.cpp @@ -12,6 +12,67 @@ using namespace i18n_string_util; namespace i18n_check { + // common font faces that we would usually ignore (client can add to this) + std::seti18n_review::m_font_names = { + L"Arial", + L"Courier New", + L"Garamond", + L"Calibri", + L"Gabriola", + L".Helvetica Neue DeskInterface", L".Lucida Grande UI", + L"Times New Roman", L"Georgia", L"Segoe UI", L"Segoe Script", + L"Century Gothic", L"Century", L"Cascadia Mono", L"URW Bookman L", + L"AR Berkley", L"Brush Script", L"Consolas", L"Century Schoolbook L", + L"Lucida Grande", L"Helvetica Neue", L"Liberation Serif", L"Luxi Serif", + L"Ms Shell Dlg", L"Ms Shell Dlg 2", L"Bitstream Vera Serif", L"URW Palladio L", + L"URW Chancery L", L"Comic Sans MS", L"DejaVu Serif", L"DejaVu LGC Serif", + L"Nimbus Sans L", L"URW Gothic L", L"Lucida Sans", L"Andale Mono", + L"Luxi Sans", L"Liberation Sans", L"Bitstream Vera Sans", L"DejaVu LGC Sans", + L"DejaVu Sans", L"Nimbus Mono L", L"Lucida Sans Typewriter", L"Luxi Mono", + L"DejaVu Sans Mono", L"DejaVu LGC Sans Mono", L"Bitstream Vera Sans Mono", + L"Liberation Mono", L"Franklin Gothic", L"Aptos", L"Grandview", L"Bierstadt" }; + + std::set i18n_review::m_file_extensions = { // documents + L"xml", L"html", L"htm", L"xhtml", L"rtf", + L"doc", L"docx", L"dot", L"docm", L"txt", L"ppt", L"pptx", + L"pdf", L"ps", L"odt", L"ott", L"odp", L"otp", L"pptm", + L"md", + // Visual Studio files + L"sln", L"csproj", L"json", + // macOS + L"dmg", L"proj", L"xbuild", L"xmlns", + // Database + L"mdb", L"db", + // Markdown files + L"md", L"Rmd", L"qmd", + // help files + L"hhc", L"hhk", L"hhp", + // spreadsheets + L"xls", L"xlsx", L"ods", L"csv", + // image formats + L"gif", L"jpg", L"jpeg", L"jpe", L"bmp", L"tiff", L"tif", + L"png", L"tga", L"svg", L"xcf", L"ico", L"psd", + L"hdr", L"pcx", + // webpages + L"asp", L"aspx", L"cfm", + L"cfml", L"php", L"php3", L"php4", + L"sgml", L"wmf", L"js", + // style sheets + L"css", + // movies + L"mov", L"qt", L"rv", L"rm", + L"wmv", L"mpg", L"mpeg", L"mpe", + L"avi", + // music + L"mp3", L"wav", L"wma", L"midi", + L"ra", L"ram", + // programs + L"exe", L"swf", L"vbs", + // source files + L"cpp", L"h", L"c", L"idl", L"cs", + // compressed files + L"gzip", L"bz2" }; + //-------------------------------------------------- i18n_review::i18n_review() { @@ -468,54 +529,6 @@ namespace i18n_check m_keywords = { L"return", L"else", L"if", L"goto", L"new", L"delete", L"throw" }; - // common font faces that we would usually ignore (client can add to this) - m_font_names = { L"Arial", L"Courier New", L"Garamond", L"Calibri", L"Gabriola", - L".Helvetica Neue DeskInterface", L".Lucida Grande UI", - L"Times New Roman", L"Georgia", L"Segoe UI", L"Segoe Script", - L"Century Gothic", L"Century", L"Cascadia Mono", L"URW Bookman L", - L"AR Berkley", L"Brush Script", L"Consolas", L"Century Schoolbook L", - L"Lucida Grande", L"Helvetica Neue", L"Liberation Serif", L"Luxi Serif", - L"Ms Shell Dlg", L"Ms Shell Dlg 2", L"Bitstream Vera Serif", L"URW Palladio L", - L"URW Chancery L", L"Comic Sans MS", L"DejaVu Serif", L"DejaVu LGC Serif", - L"Nimbus Sans L", L"URW Gothic L", L"Lucida Sans", L"Andale Mono", - L"Luxi Sans", L"Liberation Sans", L"Bitstream Vera Sans", L"DejaVu LGC Sans", - L"DejaVu Sans", L"Nimbus Mono L", L"Lucida Sans Typewriter", L"Luxi Mono", - L"DejaVu Sans Mono", L"DejaVu LGC Sans Mono", L"Bitstream Vera Sans Mono", - L"Liberation Mono", L"Franklin Gothic", L"Aptos", L"Grandview", L"Bierstadt" }; - - m_file_extensions = { // documents - L"xml", L"html", L"htm", L"xhtml", L"rtf", - L"doc", L"docx", L"dot", L"docm", L"txt", L"ppt", L"pptx", - L"pdf", L"ps", L"odt", L"ott", L"odp", L"otp", L"pptm", - L"md", - // help files - L"hhc", L"hhk", L"hhp", - // spreadsheets - L"xls", L"xlsx", L"ods", L"csv", - // image formats - L"gif", L"jpg", L"jpeg", L"jpe", L"bmp", L"tiff", L"tif", - L"png", L"tga", L"svg", L"xcf", L"ico", L"psd", - L"hdr", L"pcx", - // webpages - L"asp", L"aspx", L"cfm", - L"cfml", L"php", L"php3", L"php4", - L"sgml", L"wmf", L"js", - // style sheets - L"css", - // movies - L"mov", L"qt", L"rv", L"rm", - L"wmv", L"mpg", L"mpeg", L"mpe", - L"avi", - // music - L"mp3", L"wav", L"wma", L"midi", - L"ra", L"ram", - // programs - L"exe", L"swf", L"vbs", - // source files - L"cpp", L"h", L"c", L"idl", - // compressed files - L"gzip", L"bz2" }; - // variables whose CTORs take a string that should never be translated m_variable_types_to_ignore = { L"wxUxThemeHandle", L"wxRegKey", L"wxLoadedDLL", L"wxConfigPathChanger", L"wxWebViewEvent", diff --git a/src/i18n_review.h b/src/i18n_review.h index cf42042..cb2eba9 100644 --- a/src/i18n_review.h +++ b/src/i18n_review.h @@ -487,13 +487,23 @@ namespace i18n_check void set_min_words_for_classifying_unavailable_string(const size_t minVal) noexcept { m_min_words_for_unavailable_string = minVal; } /** @brief Adds a font face to be ignored if found as a string. - @param str The font face name.*/ - void add_font_name_to_ignore(const string_util::case_insensitive_wstring& str) + @param str The font face name.*/ + static void add_font_name_to_ignore(const string_util::case_insensitive_wstring& str) { m_font_names.emplace(str); } /** @brief Adds a file extension to be ignored if found as a string. - @param str The font face name.*/ - void add_file_extension_to_ignore(const string_util::case_insensitive_wstring& str) + @param str The font face name.*/ + static void add_file_extension_to_ignore(const string_util::case_insensitive_wstring& str) { m_file_extensions.emplace(str); } + /// @returns @c true if string is a known font face name. + /// @param str The string to review. + [[nodiscard]] + static bool is_font_name(const string_util::case_insensitive_wstring& str) + { return m_font_names.find(str) != m_font_names.cend(); } + /// @returns @c true if string is a known file extension. + /// @param str The string to review. + [[nodiscard]] + static bool is_file_extension(const string_util::case_insensitive_wstring& str) + { return m_file_extensions.find(str) != m_file_extensions.cend(); } protected: // traditionally, 80 chars is the recommended line width, // but 120 is a bit more reasonable @@ -593,16 +603,6 @@ namespace i18n_check [[nodiscard]] bool is_keyword(const std::wstring& str) const { return m_keywords.find(str) != m_keywords.cend(); } - /// @returns @c true if string is a known font face name. - /// @param str The string to review. - [[nodiscard]] - bool is_font_name(const string_util::case_insensitive_wstring& str) const - { return m_font_names.find(str) != m_font_names.cend(); } - /// @returns @c true if string is a known file extension. - /// @param str The string to review. - [[nodiscard]] - bool is_file_extension(const string_util::case_insensitive_wstring& str) const - { return m_file_extensions.find(str) != m_file_extensions.cend(); } /** @brief Logs a debug message. @param info Information, such as a string causing a parsing error. @param message An informational message. @@ -767,8 +767,8 @@ namespace i18n_check std::set m_variable_types_to_ignore; std::set m_known_internal_strings; std::set m_keywords; - std::set m_font_names; - std::set m_file_extensions; + static std::set m_font_names; + static std::set m_file_extensions; std::map m_deprecated_string_macros; std::map m_deprecated_string_functions; // results after parsing what the client should maybe review diff --git a/src/i18n_string_util.cpp b/src/i18n_string_util.cpp index 803ce59..1fe5644 100644 --- a/src/i18n_string_util.cpp +++ b/src/i18n_string_util.cpp @@ -167,9 +167,13 @@ namespace i18n_string_util } // 2-letter extensions else if (length >= 3 && text[length-3] == L'.' && - // translation files + // translation, source, and doc files (string_util::strnicmp(text+(length-2), L"mo", 2) == 0 || - string_util::strnicmp(text+(length-2), L"po", 2) == 0)) + string_util::strnicmp(text+(length-2), L"po", 2) == 0 || + string_util::strnicmp(text+(length-2), L"cs", 2) == 0 || + string_util::strnicmp(text+(length-2), L"js", 2) == 0 || + string_util::strnicmp(text+(length-2), L"db", 2) == 0 || + string_util::strnicmp(text+(length-2), L"md", 2) == 0)) { return true; } // tarball file name else if (length >= 7 && string_util::strnicmp(text+(length-7), L".tar.", 5) == 0)