Add Options, Functions and Settings to convert Node-Names and Strings to kebab-case

- refactored and renamed String::_camelcase_to_underscore to String:_separate_compound_words
- refactored String::to_snake_case to work with the refactored String::_separate_compound_words
- created char_utils::is_hyphen to catch all hyphen variants in kebab-case conversion
- created String::to_kebab_case using the new String::_separate_compound_words
- created corresponding Documentation in String and StringName
- simplified both switch statements in EditorNode and ProjectDialog
- added new kebab-casing Option for Node Names in ProjectSettings
- added missing camelCase Options to Scene- and Node-Names in ProjectSettings
- simplified Mono RuntimeInterop Functions
- hooked up the ConnectionsDialog
- created additional Unit Tests
This commit is contained in:
Priahoud
2024-07-28 21:32:28 +02:00
committed by priahoud
parent 06c71fbf40
commit bf963e767e
20 changed files with 195 additions and 114 deletions

View File

@@ -1451,6 +1451,14 @@ TEST_CASE("[String] Capitalize against many strings") {
output = "Snake Snake Case";
CHECK(input.capitalize() == output);
input = "kebab-case";
output = "Kebab Case";
CHECK(input.capitalize() == output);
input = "kebab-kebab-case";
output = "Kebab Kebab Case";
CHECK(input.capitalize() == output);
input = "sha256sum";
output = "Sha 256 Sum";
CHECK(input.capitalize() == output);
@@ -1471,6 +1479,14 @@ TEST_CASE("[String] Capitalize against many strings") {
output = "Snake Case Function( Snake Case Arg )";
CHECK(input.capitalize() == output);
input = "kebab-case-function( kebab-case-arg )";
output = "Kebab Case Function( Kebab Case Arg )";
CHECK(input.capitalize() == output);
input = "kebab_case_function( kebab_case_arg )";
output = "Kebab Case Function( Kebab Case Arg )";
CHECK(input.capitalize() == output);
input = U"словоСлово_слово слово";
output = U"Слово Слово Слово Слово";
CHECK(input.capitalize() == output);
@@ -1489,35 +1505,37 @@ struct StringCasesTestCase {
const char32_t *camel_case;
const char32_t *pascal_case;
const char32_t *snake_case;
const char32_t *kebab_case;
};
TEST_CASE("[String] Checking case conversion methods") {
StringCasesTestCase test_cases[] = {
/* clang-format off */
{ U"2D", U"2d", U"2d", U"2d" },
{ U"2d", U"2d", U"2d", U"2d" },
{ U"2db", U"2Db", U"2Db", U"2_db" },
{ U"Vector3", U"vector3", U"Vector3", U"vector_3" },
{ U"sha256", U"sha256", U"Sha256", U"sha_256" },
{ U"Node2D", U"node2d", U"Node2d", U"node_2d" },
{ U"RichTextLabel", U"richTextLabel", U"RichTextLabel", U"rich_text_label" },
{ U"HTML5", U"html5", U"Html5", U"html_5" },
{ U"Node2DPosition", U"node2dPosition", U"Node2dPosition", U"node_2d_position" },
{ U"Number2Digits", U"number2Digits", U"Number2Digits", U"number_2_digits" },
{ U"get_property_list", U"getPropertyList", U"GetPropertyList", U"get_property_list" },
{ U"get_camera_2d", U"getCamera2d", U"GetCamera2d", U"get_camera_2d" },
{ U"_physics_process", U"physicsProcess", U"PhysicsProcess", U"_physics_process" },
{ U"bytes2var", U"bytes2Var", U"Bytes2Var", U"bytes_2_var" },
{ U"linear2db", U"linear2Db", U"Linear2Db", U"linear_2_db" },
{ U"sha256sum", U"sha256Sum", U"Sha256Sum", U"sha_256_sum" },
{ U"camelCase", U"camelCase", U"CamelCase", U"camel_case" },
{ U"PascalCase", U"pascalCase", U"PascalCase", U"pascal_case" },
{ U"snake_case", U"snakeCase", U"SnakeCase", U"snake_case" },
{ U"Test TEST test", U"testTestTest", U"TestTestTest", U"test_test_test" },
{ U"словоСлово_слово слово", U"словоСловоСловоСлово", U"СловоСловоСловоСлово", U"слово_слово_слово_слово" },
{ U"λέξηΛέξη_λέξη λέξη", U"λέξηΛέξηΛέξηΛέξη", U"ΛέξηΛέξηΛέξηΛέξη", U"λέξη_λέξη_λέξη_λέξη" },
{ U"բառԲառառ բառ", U"բառԲառԲառԲառ", U"ԲառԲառԲառԲառ", U"բառառառառ" },
{ nullptr, nullptr, nullptr, nullptr },
{ U"2D", U"2d", U"2d", U"2d", U"2d" },
{ U"2d", U"2d", U"2d", U"2d", U"2d" },
{ U"2db", U"2Db", U"2Db", U"2_db", U"2-db" },
{ U"Vector3", U"vector3", U"Vector3", U"vector_3", U"vector-3" },
{ U"sha256", U"sha256", U"Sha256", U"sha_256", U"sha-256" },
{ U"Node2D", U"node2d", U"Node2d", U"node_2d", U"node-2d" },
{ U"RichTextLabel", U"richTextLabel", U"RichTextLabel", U"rich_text_label", U"rich-text-label" },
{ U"HTML5", U"html5", U"Html5", U"html_5", U"html-5" },
{ U"Node2DPosition", U"node2dPosition", U"Node2dPosition", U"node_2d_position", U"node-2d-position" },
{ U"Number2Digits", U"number2Digits", U"Number2Digits", U"number_2_digits", U"number-2-digits" },
{ U"get_property_list", U"getPropertyList", U"GetPropertyList", U"get_property_list", U"get-property-list" },
{ U"get_camera_2d", U"getCamera2d", U"GetCamera2d", U"get_camera_2d", U"get-camera-2d" },
{ U"_physics_process", U"physicsProcess", U"PhysicsProcess", U"_physics_process", U"-physics-process" },
{ U"bytes2var", U"bytes2Var", U"Bytes2Var", U"bytes_2_var", U"bytes-2-var" },
{ U"linear2db", U"linear2Db", U"Linear2Db", U"linear_2_db", U"linear-2-db" },
{ U"sha256sum", U"sha256Sum", U"Sha256Sum", U"sha_256_sum", U"sha-256-sum" },
{ U"camelCase", U"camelCase", U"CamelCase", U"camel_case", U"camel-case" },
{ U"PascalCase", U"pascalCase", U"PascalCase", U"pascal_case", U"pascal-case" },
{ U"snake_case", U"snakeCase", U"SnakeCase", U"snake_case", U"snake-case" },
{ U"kebab-case", U"kebabCase", U"KebabCase", U"kebab_case", U"kebab-case" },
{ U"Test TEST test", U"testTestTest", U"TestTestTest", U"test_test_test", U"test-test-test" },
{ U"словоСлово_слово слово", U"словоСловоСловоСлово", U"СловоСловоСловоСлово", U"слово_слово_слово_слово", U"слово-слово-слово-слово" },
{ U"λέξηΛέξη_λέξη λέξη", U"λέξηΛέξηΛέξηΛέξη", U"ΛέξηΛέξηΛέξηΛέξη", U"λέξη_λέξη_λέξη_λέξη", U"λέξη-λέξη-λέξη-λέξη" },
{ U"բառԲառառ բառ", U"բառԲառԲառԲառ", U"ԲառԲառԲառԲառ", U"բառառառառ", U"բառ-բառ-բառ-բառ" },
{ nullptr, nullptr, nullptr, nullptr, nullptr },
/* clang-format on */
};
@@ -1527,6 +1545,7 @@ TEST_CASE("[String] Checking case conversion methods") {
CHECK(input.to_camel_case() == test_cases[idx].camel_case);
CHECK(input.to_pascal_case() == test_cases[idx].pascal_case);
CHECK(input.to_snake_case() == test_cases[idx].snake_case);
CHECK(input.to_kebab_case() == test_cases[idx].kebab_case);
idx++;
}
}