Project overhaul

This commit is contained in:
Tony Bark 2022-07-21 10:23:31 -04:00
parent 3de1fc5eca
commit 84c27a1b14
11 changed files with 78 additions and 169 deletions

View file

@ -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

View file

@ -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

View file

@ -9,13 +9,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View file

@ -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

View file

@ -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.

View file

@ -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***";
}
}

View file

@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.2.100</Version>
<TargetFrameworks>netstandard2.1;net6.0</TargetFrameworks>
<Version>1.0.400-beta1</Version>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Authors>Tony Bark, Sixam Software</Authors>
<Authors>Tony Bark</Authors>
<PackageDescription>
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.
</PackageDescription>
<RepositoryUrl>https://github.com/sixamsoft/cst-dotnet</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RootNamespace>Sixam.CST</RootNamespace>
<RepositoryUrl>https://github.com/tonytins/cstdotnet</RepositoryUrl>
<PackageLicenseExpression>BSD 3-Clause</PackageLicenseExpression>
</PropertyGroup>
</Project>

View file

@ -6,23 +6,46 @@ namespace CSTNet;
public class UIText
{
string Language { get; set; } = "english";
public string[] BasePath { get; set; } = { AppContext.BaseDirectory, "uitext" };
public UIText() { }
/// <summary>
/// Loads the language file.
/// </summary>
/// <param name="language">Language to load</param>
public UIText(string language)
{
Language = language;
}
/// <summary>
/// Loads the language file.
/// </summary>
/// <param name="language">Language to load</param>
/// <param name="basePath">Base directory for the language files.</param>
public UIText(string language, params string[] baseBath)
{
Language = language;
BasePath = baseBath;
}
/// <summary>
/// Get the text for the given id and key.
/// </summary>
/// <param name="id">The id of the text.</param>
/// <param name="key">The key of the text.</param>
/// <returns>The text for the given id and key.</returns>
public string GetText(int id, int key) => GetText(id, key.ToString());
/// <summary>
/// Get the text for the given id and key.
/// </summary>
/// <param name="id">The id of the text.</param>
/// <param name="key">The key of the text.</param>
/// <returns>The text for the given id and key.</returns>
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***";
}
}

View file

@ -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. ``<key> ^<text>^``) 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.
I license this project under the BSD-3-Clause license - see [LICENSE](LICENSE) for details.

View file

@ -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 ``/<directory>/<language>.dir`` directories and searching for CST files by their Id number. (e.g. _*154*_miscstrings.cst). By defualt, the base path is ``/<program directory>/uitext/<language>.dir``. For more info, see [usage.md](./usage.md).
## 1.0.300
- Minor patch.
## 1.0.3
- Backport switch to CSTNet namespace

View file

@ -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/<languae>.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/<languae>.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()
{