Skip to content

Commit

Permalink
Make font and file extension checks static, add more known extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Dec 1, 2023
1 parent 84e4839 commit 98b7209
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 66 deletions.
109 changes: 61 additions & 48 deletions src/i18n_review.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::set<string_util::case_insensitive_wstring>i18n_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<string_util::case_insensitive_wstring> 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()
{
Expand Down Expand Up @@ -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",
Expand Down
32 changes: 16 additions & 16 deletions src/i18n_review.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -767,8 +767,8 @@ namespace i18n_check
std::set<std::wstring_view> m_variable_types_to_ignore;
std::set<string_util::case_insensitive_wstring> m_known_internal_strings;
std::set<std::wstring_view> m_keywords;
std::set<string_util::case_insensitive_wstring> m_font_names;
std::set<string_util::case_insensitive_wstring> m_file_extensions;
static std::set<string_util::case_insensitive_wstring> m_font_names;
static std::set<string_util::case_insensitive_wstring> m_file_extensions;
std::map<std::wstring_view, std::wstring_view> m_deprecated_string_macros;
std::map<std::wstring_view, std::wstring_view> m_deprecated_string_functions;
// results after parsing what the client should maybe review
Expand Down
8 changes: 6 additions & 2 deletions src/i18n_string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 98b7209

Please sign in to comment.