Update CST class for nullability and debug interop

- Changed preprocessor conditions to use DEBUG instead of NET8_0 for interop methods.
- Updated NormalizeEntries and GetEntry methods to accept nullable string parameters.
- Bumped project version to 2.1.101-alpha and updated changelog.
This commit is contained in:
Tony Bark 2026-01-07 04:25:06 -05:00
parent 89383db3c3
commit 2789562abd
3 changed files with 29 additions and 18 deletions

View file

@ -1,6 +1,6 @@
// This project is licensed under the BSD 3-Clause license. // This project is licensed under the BSD 3-Clause license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#if NET8_0 #if DEBUG
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#endif #endif
@ -30,7 +30,7 @@ public static class CST
return GetEntry(entries, key); return GetEntry(entries, key);
} }
#if (NET8_0 && DEBUG) #if DEBUG
[UnmanagedCallersOnly(EntryPoint = "parse")] [UnmanagedCallersOnly(EntryPoint = "parse")]
public static IntPtr Parse(IntPtr content, IntPtr key) public static IntPtr Parse(IntPtr content, IntPtr key)
{ {
@ -39,12 +39,13 @@ public static class CST
return Marshal.StringToHGlobalAnsi(GetEntry(entries, Marshal.PtrToStringAnsi(key))); return Marshal.StringToHGlobalAnsi(GetEntry(entries, Marshal.PtrToStringAnsi(key)));
} }
#endif #endif
/// <summary> /// <summary>
/// Normalizes the content by replacing various newline characters with Environment.NewLine and filters out comments. /// Normalizes the content by replacing various newline characters with Environment.NewLine and filters out comments.
/// </summary> /// </summary>
/// <param name="content">The content to normalize.</param> /// <param name="content">The content to normalize.</param>
/// <returns>An enumerable of normalized lines.</returns> /// <returns>An enumerable of normalized lines.</returns>
public static IEnumerable<string> NormalizeEntries(string content) static IEnumerable<string> NormalizeEntries(string? content)
{ {
var newLines = new[] { LF, CR, CRLF, LS }; var newLines = new[] { LF, CR, CRLF, LS };
@ -60,7 +61,7 @@ public static class CST
/// <param name="entries">The entries to search through.</param> /// <param name="entries">The entries to search through.</param>
/// <param name="key">The key to search for.</param> /// <param name="key">The key to search for.</param>
/// <returns>The value for the specified key, or a default string if not found.</returns> /// <returns>The value for the specified key, or a default string if not found.</returns>
static string GetEntry(IEnumerable<string> entries, string key) static string GetEntry(IEnumerable<string> entries, string? key)
{ {
// Iterate through the entries. // Iterate through the entries.
foreach (var entry in entries) foreach (var entry in entries)

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks> <TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<Version>2.2.100-alpha</Version> <Version>2.1.101-alpha</Version>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>

View file

@ -1,59 +1,69 @@
# Change Log # Change Log
## 2.1.100 ## 2.1
### 2.1.101
- Bumped target framework to .NET 10
### 2.1.100
- Removed `CaretSeparatedText` in favor of `CST` class - Removed `CaretSeparatedText` in favor of `CST` class
- Due to technical reasons, .NET Standard Standard support was removed - Due to technical reasons, .NET Standard Standard support was removed
### Experimental #### Experimental
- Parser function can now be consumed from non-.NET programming languages. - Parser function can now be consumed from non-.NET programming languages.
## 2.0.104 ## 2.0
### 2.0.104
- Support for .NET 8 - Support for .NET 8
## 2.0.102 ### 2.0.102
- Properly commented and documented the rest of the code. - Properly commented and documented the rest of the code.
## 2.0.100 ### 2.0.100
This version supports both .NET Standard 2.1 and .NET 6 and brings with it (much needed) quality of life changes internally. Apart from that, nothing has changed to the API itself apart from much needed documentation. This version supports both .NET Standard 2.1 and .NET 6 and brings with it (much needed) quality of life changes internally. Apart from that, nothing has changed to the API itself apart from much needed documentation.
### UIText class and interface #### UIText class and interface
Based on FreeSO's API, the `UIText` class allows for traversing in `/<directory>/<language>.dir` directories and searching CST files by their Id number. (e.g. \_*154*\_miscstrings.cst). By defualt, the base path is `/<program directory>/uitext/<language>.dir`. You may also create your own implementation based on these APIs using the `IUIText` interface which mine also uses. Based on FreeSO's API, the `UIText` class allows for traversing in `/<directory>/<language>.dir` directories and searching CST files by their Id number. (e.g. \_*154*\_miscstrings.cst). By defualt, the base path is `/<program directory>/uitext/<language>.dir`. You may also create your own implementation based on these APIs using the `IUIText` interface which mine also uses.
For more info, see [usage.md](./usage.md). For more info, see [usage.md](./usage.md).
## 1.0.300 ## 1.0
### 1.0.300
- Minor patch. - Minor patch.
## 1.0.3 ### 1.0.3
- Backport switch to CSTNet namespace - Backport switch to CSTNet namespace
- Internal improvements. - Internal improvements.
## 1.0.2 ### 1.0.2
- Fixed the multiple line parsing in the v2 format. - Fixed the multiple line parsing in the v2 format.
- Replaced "`[ENTRY NOT FOUND]`" message with "`***MISSING***`". - Replaced "`[ENTRY NOT FOUND]`" message with "`***MISSING***`".
## 1.0.1 ### 1.0.1
Despite only being a patch release, this includes a major refinement to the normalizing algorithm. Despite only being a patch release, this includes a major refinement to the normalizing algorithm.
### Rewrote normalizing algorithm #### Rewrote normalizing algorithm
The normalizing algorithm has been rewritten to be more efficient and hopefully more reliable. The new algorithm de-constructs each line after converting it to the system's native line ending. Then it searches for the key and returns value. The rewrite also normalizes line endings to match the system's within the entry itself before returning the final output. This should make things more stable and predictable. The normalizing algorithm has been rewritten to be more efficient and hopefully more reliable. The new algorithm de-constructs each line after converting it to the system's native line ending. Then it searches for the key and returns value. The rewrite also normalizes line endings to match the system's within the entry itself before returning the final output. This should make things more stable and predictable.
### Known issues #### Known issues
- Skipping comments is still a little buggy. - Skipping comments is still a little buggy.
- Multiline parsing with the v2 format is still a little unpredictable. - Multiline parsing with the v2 format is still a little unpredictable.
## 1.0.0 ### 1.0.0
- Initial release. - Initial release.