From 2363d0f9ba5eae0c79fc9f8f53068f8489e67e85 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 9 Nov 2022 17:09:31 +0100 Subject: [PATCH] Improve editor property capitalization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Don't capitalize stop words such as "at", "in" or "to". - Add more acronyms to capitalize. Co-authored-by: Rémi Verschelde (cherry picked from commit aafa816946dbf06e71f48b2fc4c7a1edf1eec65c) --- editor/editor_property_name_processor.cpp | 27 +++++++++++++++++++++++ editor/editor_property_name_processor.h | 1 + 2 files changed, 28 insertions(+) diff --git a/editor/editor_property_name_processor.cpp b/editor/editor_property_name_processor.cpp index ac7377c06cd..0e83db73f96 100644 --- a/editor/editor_property_name_processor.cpp +++ b/editor/editor_property_name_processor.cpp @@ -64,6 +64,10 @@ String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const Vector parts = p_name.split("_", false); for (int i = 0; i < parts.size(); i++) { + // Articles/conjunctions/prepositions which should only be capitalized if first word. + if (i != 0 && stop_words.find(parts[i]) != -1) { + continue; + } const Map::Element *remap = capitalize_string_remaps.find(parts[i]); if (remap) { parts.write[i] = remap->get(); @@ -143,6 +147,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["gdscript"] = "GDScript"; capitalize_string_remaps["ggx"] = "GGX"; capitalize_string_remaps["gi"] = "GI"; + capitalize_string_remaps["gl"] = "GL"; capitalize_string_remaps["glb"] = "GLB"; capitalize_string_remaps["gles2"] = "GLES2"; capitalize_string_remaps["gles3"] = "GLES3"; @@ -157,6 +162,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["html"] = "HTML"; capitalize_string_remaps["http"] = "HTTP"; capitalize_string_remaps["id"] = "ID"; + capitalize_string_remaps["ids"] = "IDs"; capitalize_string_remaps["igd"] = "IGD"; capitalize_string_remaps["ik"] = "IK"; capitalize_string_remaps["image@2x"] = "Image @2x"; @@ -222,6 +228,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["sv"] = "SV"; capitalize_string_remaps["svg"] = "SVG"; capitalize_string_remaps["tcp"] = "TCP"; + capitalize_string_remaps["tls"] = "TLS"; capitalize_string_remaps["ui"] = "UI"; capitalize_string_remaps["url"] = "URL"; capitalize_string_remaps["urls"] = "URLs"; @@ -248,9 +255,29 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() { capitalize_string_remaps["wifi"] = "Wi-Fi"; capitalize_string_remaps["x86"] = "x86"; capitalize_string_remaps["xr"] = "XR"; + capitalize_string_remaps["xray"] = "X-Ray"; capitalize_string_remaps["xy"] = "XY"; capitalize_string_remaps["xz"] = "XZ"; capitalize_string_remaps["yz"] = "YZ"; + + // Articles, conjunctions, prepositions. + stop_words.push_back("a"); + stop_words.push_back("an"); + stop_words.push_back("and"); + stop_words.push_back("as"); + stop_words.push_back("at"); + stop_words.push_back("by"); + stop_words.push_back("for"); + stop_words.push_back("in"); + stop_words.push_back("not"); + stop_words.push_back("of"); + stop_words.push_back("on"); + stop_words.push_back("or"); + stop_words.push_back("over"); + stop_words.push_back("per"); + stop_words.push_back("the"); + stop_words.push_back("then"); + stop_words.push_back("to"); } EditorPropertyNameProcessor::~EditorPropertyNameProcessor() { diff --git a/editor/editor_property_name_processor.h b/editor/editor_property_name_processor.h index 351736550f8..5d795653992 100644 --- a/editor/editor_property_name_processor.h +++ b/editor/editor_property_name_processor.h @@ -40,6 +40,7 @@ class EditorPropertyNameProcessor : public Node { mutable Map capitalize_string_cache; Map capitalize_string_remaps; + LocalVector stop_words; // Exceptions that shouldn't be capitalized. // Capitalizes property path segments. String _capitalize_name(const String &p_name) const;