From 84c27a1b1415f75287e38f756cd5245d0d72b964 Mon Sep 17 00:00:00 2001 From: Tony Bark <35226681+tonytins@users.noreply.github.com> Date: Thu, 21 Jul 2022 10:23:31 -0400 Subject: [PATCH] Project overhaul --- .editorconfig | 128 ----------------------- .github/workflows/dotnet.yml | 4 +- CSTNet.Tests/CSTNet.Tests.csproj | 6 +- CSTNet.sln | 2 - CSTNet.sln.licenseheader | 4 - CSTNet/{CaretSeparatedText.cs => CST.cs} | 7 +- CSTNet/CSTNet.csproj | 14 +-- CSTNet/UIText.cs | 26 ++++- README.md | 9 +- changelog.md | 14 ++- usage.md | 33 +++--- 11 files changed, 78 insertions(+), 169 deletions(-) delete mode 100644 .editorconfig delete mode 100644 CSTNet.sln.licenseheader rename CSTNet/{CaretSeparatedText.cs => CST.cs} (96%) diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 45a6ca1..0000000 --- a/.editorconfig +++ /dev/null @@ -1,128 +0,0 @@ -# Default settings: -# A newline ending every file -# Use 4 spaces as indentation -[*] -charset = utf-8 -end_of_line = crlf -indent_style = space -indent_size = 4 -insert_final_newline = false -trim_trailing_whitespace = true - -# VB and C# files -[*.{vb,cs}] -# avoid this. unless absolutely necessary -dotnet_style_qualification_for_field = false : suggestion -dotnet_style_qualification_for_property = false : suggestion -dotnet_style_qualification_for_method = false : suggestion -dotnet_style_qualification_for_event = false : suggestion - -# use language keywords instead of BCL types -dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion -dotnet_style_predefined_type_for_member_access = true : suggestion - -# Use camel_case for or internal constant fields -dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields -dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style - -dotnet_naming_symbols.constant_fields.applicable_kinds = field -dotnet_naming_symbols.constant_fields.required_modifiers = const - -dotnet_naming_style.pascal_case_style.capitalization = all_upper - -# Comment this group and uncomment out the next group if you don't want _ prefixed fields. - -# internal and fields should be _camelCase -dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion -dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style - -dotnet_naming_symbols.private_internal_fields.applicable_kinds = field -dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal - -dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case - -# Public members must be capitalized - -dotnet_naming_rule.public_members_must_be_capitalized.symbols = public_symbols -dotnet_naming_symbols.public_symbols.applicable_kinds = property,method,field,event,delegate -dotnet_naming_symbols.public_symbols.applicable_accessibilities = public - -dotnet_naming_rule.public_members_must_be_capitalized.style = first_word_upper_case_style -dotnet_naming_style.first_word_upper_case_style.capitalization = first_word_upper - -dotnet_naming_rule.public_members_must_be_capitalized.severity = suggestion - -# Code style defaults -dotnet_sort_system_directives_first = true -csharp_preserve_single_line_blocks = true -csharp_preserve_single_line_statements = false - -# Expression-level preferences -dotnet_style_object_initializer = true : suggestion -dotnet_style_collection_initializer = true : suggestion -dotnet_style_explicit_tuple_names = true : suggestion -dotnet_style_coalesce_expression = true : suggestion -dotnet_style_null_propagation = true : suggestion - -[*.cs] -# New line preferences -csharp_new_line_before_open_brace = all -csharp_new_line_before_else = true -csharp_new_line_before_catch = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_between_query_expression_clauses = true - -# Indentation preferences -csharp_indent_block_contents = true -csharp_indent_braces = false -csharp_indent_case_contents = true -csharp_indent_switch_labels = true -csharp_indent_labels = one_less_than_current - -# only use var when it's obvious what the variable type is -csharp_style_var_for_built_in_types = true : none -csharp_style_var_when_type_is_apparent = true : none -csharp_style_var_elsewhere = true : suggestion - -# Code style defaults -dotnet_sort_system_directives_first = true -csharp_preserve_single_line_blocks = true -csharp_preserve_single_line_statements = false - -# Pattern matching -csharp_style_pattern_matching_over_is_with_cast_check = true : suggestion -csharp_style_pattern_matching_over_as_with_null_check = true : suggestion -csharp_style_inlined_variable_declaration = true : suggestion - -# Null checking preferences -csharp_style_throw_expression = true : warning -csharp_style_conditional_delegate_call = true : warning - -# Space preferences -csharp_space_after_cast = false -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_after_comma = true -csharp_space_after_dot = false -csharp_space_after_keywords_in_control_flow_statements = true -csharp_space_after_semicolon_in_for_statement = true -csharp_space_around_binary_operators = before_and_after -csharp_space_around_declaration_statements = do_not_ignore -csharp_space_before_colon_in_inheritance_clause = true -csharp_space_before_comma = false -csharp_space_before_dot = false -csharp_space_before_open_square_brackets = false -csharp_space_before_semicolon_in_for_statement = false -csharp_space_between_empty_square_brackets = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_call_parameter_list_parentheses = false -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_parentheses = false -csharp_space_between_square_brackets = false \ No newline at end of file diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 9f3947f..aaf581a 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -2,9 +2,9 @@ name: .NET on: push: - branches: [master, "releases/**"] + branches: [main, master, "releases/**"] pull_request: - branches: [master, "releases/**"] + branches: [main, master, "releases/**"] jobs: build: runs-on: ubuntu-latest diff --git a/CSTNet.Tests/CSTNet.Tests.csproj b/CSTNet.Tests/CSTNet.Tests.csproj index a15dfbb..e0f2c87 100644 --- a/CSTNet.Tests/CSTNet.Tests.csproj +++ b/CSTNet.Tests/CSTNet.Tests.csproj @@ -9,13 +9,13 @@ - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/CSTNet.sln b/CSTNet.sln index a57ac6e..38eee8a 100644 --- a/CSTNet.sln +++ b/CSTNet.sln @@ -5,10 +5,8 @@ VisualStudioVersion = 16.0.30717.126 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CCFCE2DB-C18F-4D88-B025-19ED62BD2A1D}" ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig changelog.md = changelog.md README.md = README.md - CSTNet.sln.licenseheader = CSTNet.sln.licenseheader usage.md = usage.md EndProjectSection EndProject diff --git a/CSTNet.sln.licenseheader b/CSTNet.sln.licenseheader deleted file mode 100644 index df4e2e0..0000000 --- a/CSTNet.sln.licenseheader +++ /dev/null @@ -1,4 +0,0 @@ -extensions: designer.cs generated.cs -extensions: .cs .cpp .h -// This project is licensed under the MIT license. -// See the LICENSE file in the project root for more information. \ No newline at end of file diff --git a/CSTNet/CaretSeparatedText.cs b/CSTNet/CST.cs similarity index 96% rename from CSTNet/CaretSeparatedText.cs rename to CSTNet/CST.cs index 82c1f34..296ab09 100644 --- a/CSTNet/CaretSeparatedText.cs +++ b/CSTNet/CST.cs @@ -3,7 +3,10 @@ namespace CSTNet; -public class CaretSeparatedText +[Obsolete("Use CST class instead.")] +public class CaretSeparatedText : CST { } + +public class CST { const char CARET = '^'; const string LF = "\u000A"; @@ -78,3 +81,5 @@ public class CaretSeparatedText return "***MISSING***"; } } + + diff --git a/CSTNet/CSTNet.csproj b/CSTNet/CSTNet.csproj index 3751e5d..3bfa41e 100644 --- a/CSTNet/CSTNet.csproj +++ b/CSTNet/CSTNet.csproj @@ -1,19 +1,19 @@ - net6.0 - 1.2.100 + netstandard2.1;net6.0 + 1.0.400-beta1 enable + latest enable - Tony Bark, Sixam Software + Tony Bark Caret-Separated Text (or CST) is a key-value pair format represented by digits or words as keys and the value as text enclosed between carets. ([key] ^[value]^) - Sixam.CST provides you the framework for parsing the CST format. + CSTNet provides you the framework for parsing the CST format. - https://github.com/sixamsoft/cst-dotnet - MIT - Sixam.CST + https://github.com/tonytins/cstdotnet + BSD 3-Clause diff --git a/CSTNet/UIText.cs b/CSTNet/UIText.cs index 29f8437..2b6b3a7 100644 --- a/CSTNet/UIText.cs +++ b/CSTNet/UIText.cs @@ -6,23 +6,46 @@ namespace CSTNet; public class UIText { string Language { get; set; } = "english"; + public string[] BasePath { get; set; } = { AppContext.BaseDirectory, "uitext" }; public UIText() { } + /// + /// Loads the language file. + /// + /// Language to load public UIText(string language) { Language = language; } + + /// + /// Loads the language file. + /// + /// Language to load + /// Base directory for the language files. public UIText(string language, params string[] baseBath) { Language = language; BasePath = baseBath; } + /// + /// Get the text for the given id and key. + /// + /// The id of the text. + /// The key of the text. + /// The text for the given id and key. public string GetText(int id, int key) => GetText(id, key.ToString()); + /// + /// Get the text for the given id and key. + /// + /// The id of the text. + /// The key of the text. + /// The text for the given id and key. public string GetText(int id, string key) { var basePath = Path.Combine(BasePath); @@ -46,9 +69,10 @@ public class UIText continue; var content = File.ReadAllText(file); - return CaretSeparatedText.Parse(content, key); + return CST.Parse(content, key); } return "***MISSING***"; } } + diff --git a/README.md b/README.md index ccc362a..7be1e98 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # CSTNet -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](code_of_conduct.md) +[![GitHub license](https://img.shields.io/github/license/tonytins/cstdotnet)](https://github.com/tonytins/cstdotnet/blob/main/LICENSE) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/tonytins/cstdotnet/.NET/main) ![GitHub commit activity](https://img.shields.io/github/commit-activity/w/tonytins/cstdotnet) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](code_of_conduct.md) Caret-Separated Text (or CST) is a key-value pair format represented by digits or words as keys and the value as text enclosed between carets. (e.g. `` ^^``) Any text which is not enclosed with carets is considered a comment and ignored. Neither strings nor comments may use the caret character. CST.NET is a library for parsing the CST format. +## Architecture + CST.NET uses .NET's built-in indexing extension function to accomplish locating of each respective key. As a consequence, it does not matter what you use for keys. I added an additional normalization to the pipeline that converts the document's line endings to the system's, in order to prevent crashes. ## Usage @@ -21,9 +23,12 @@ See [usage.md](./usage.md). ## Requirements - [.NET](https://dotnet.microsoft.com/download) 6 or later. +- IDEs or Editors + - [Visual Studio Code](https://code.visualstudio.com/) + - [Visual Studio 2022](https://visualstudio.microsoft.com/) - [.NET Interactive](https://github.com/dotnet/interactive/blob/main/README.md) for notebooks (optional). - [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode) or [nteract](https://nteract.io/). ## License -I license this project under the MIT license - see [LICENSE](LICENSE) for details. \ No newline at end of file +I license this project under the BSD-3-Clause license - see [LICENSE](LICENSE) for details. \ No newline at end of file diff --git a/changelog.md b/changelog.md index eda581c..1201d3e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,10 @@ # Change Log -## 1.1.100 +## 1.0.400 -This version removes support for .NET Standard 2.0 in favor of .NET 6 and brings with it (much needed) quality of life changes to the project. Apart from that, nothing has changed to the API itself and you can continue to use to 1.1.100 on all platforms where .NET Standard 2.0 is [supported](https://dotnet.microsoft.com/platform/dotnet-standard). +This version supports both .NET Standard 2.1 and .NET 6 and brings with it (much needed) quality of life changes on the project side of things. Apart from that, nothing has changed to the API itself apart from much needed documentation. -From 1.1 onward, CSTNet will only target LTS releases. This is why .NET 5 was skipped, despite the initial platform unification. +From this version onward, CSTNet will only target LTS releases. This is why .NET 5 was skipped, despite the initial platform unification. ### Project Changes @@ -12,12 +12,18 @@ With the move to .NET 6.0, this version brings with it a lot of quality of life ### Nullable Reference Types -The only significant architectural change that was finally enabled with this release is [nullable reference types](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/nullable-reference-types). This feature was introduced in .NET Core 3.0 and .NET Standard 2.1, respectfully, but not the .NET Framework. Nullable values are already taken care of by the library but this ensures that it will be enforced. The reason why I never switched to 2.1 before was because the Sims community has historically targeted the .NET Framework, and that doesn't support anything after 3.0. +The only significant architectural change that was finally enabled with this release is [nullable reference types](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/nullable-reference-types). This feature was introduced in .NET Core 3.0 and .NET Standard 2.1, respectfully, but not the .NET Framework. Nullable values are already taken care of by the library but this ensures that it is always enforced. + +Due to the Sims community historically using the .NET Framework, this feature was not enabled by default. Starting with this version, it is enabled as modern tools now use latest .NET SDK. ### UIText class The UIText class allows for travseing in ``//.dir`` directories and searching for CST files by their Id number. (e.g. _*154*_miscstrings.cst). By defualt, the base path is ``//uitext/.dir``. For more info, see [usage.md](./usage.md). +## 1.0.300 + +- Minor patch. + ## 1.0.3 - Backport switch to CSTNet namespace diff --git a/usage.md b/usage.md index c108b41..b9a6856 100644 --- a/usage.md +++ b/usage.md @@ -2,32 +2,30 @@ ## Basic Parsing +If you want to create your own internal CST parsing framework, you can use the `CST` or `CaretSeparatedText` class directly. + ```text 1 ^The quick brown fox jumps over the lazy dog.^ ``` ```csharp -#r "nuget:Sixam.CST,1.1.100" // If using notebooks -using Sixam.CST; +#r "nuget:CSTNet,1.0.400-beta1" // If using notebooks +using CSTNet; var file = File.ReadAllText("example.cst"); -var example = CaretSeparatedText.Parse(file, 1); +var example = CST.Parse(file, 1); +// "The quick brown fox jumps over the lazy dog." Console.WriteLine(example); ``` -## Complex Scenarios +## In Production -In production, CST files were used in The Sims Online to provide translations It was required that they were prefixed with numbers enclosed in underscores, known as the ID. The IDs were used to locate the right file without knowing it's name. Meanwhile, each translation was split into their respective ``uitext/.dir`` directories: - -- ``uitext/english.dir/_154_miscstrings.cst`` -- ``uitext/swedish.dir/_154_miscstrings.cst`` - -Starting with 1.1, the UIText class provides methods that directorly map to these directories relative to the application's. +Based on FreeSO's public APIs, the UIText class provides a basic production infrastructure to be used in production. Starting with 0.1.400, the UIText class provides methods that directory map to these directories relative to the application's. ```csharp -#r "nuget:Sixam.CST,1.1.100" -using Sixam.CST; +#r "nuget:CSTNet,1.0.300" +using CSTNet; var english = new UIText(); // UIText assumes English var swedish = new UIText("swedish"); @@ -38,15 +36,20 @@ Console.WriteLine(engExample); Console.WriteLine(sweExample); ``` -Note that the IDs and keys in both ``GetText()`` examples remains the same. This is because it was historically assumed that the English and translations files were identical. However, the original never saw any new languages added. +In The Sims Online, it was required translation were prefixed with numbers enclosed in underscores, known as the ID. The IDs were used to locate the right file without having to remember it's name. Meanwhile, each translation was split into their respective ``uitext/.dir`` directories: + +- ``uitext/english.dir/_154_miscstrings.cst`` +- ``uitext/swedish.dir/_154_miscstrings.cst`` + +Note that that ``UIText`` class uses the above mentioned ``CST.Parse()`` method to parse the files. ### Changing base directories If you want to change the base directory, you can. Though, this is still a work in progress and not recommended. ```csharp -#r "nuget:Sixam.CST,1.1" -using Sixam.CST; +#r "nuget:CSTNet,1.0.300" +using CSTNet; var example = new UIText() {