- Switched to Sixam.CST namespace and marked CSTNet namespace as obsolete.
- Renumbered patch version from single to triple digits.
- Performance improvements.
This commit is contained in:
Tony Bark 2020-12-13 06:54:54 -05:00 committed by GitHub
parent e8f7bf4d0a
commit 6dea456a25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 59 additions and 44 deletions

View file

@ -1,7 +1,7 @@
using System; using System;
using System.IO; using System.IO;
namespace CSTNet.Tests namespace Sixam.CST.Tests
{ {
static class CSTHelper static class CSTHelper
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using Xunit; using Xunit;
namespace CSTNet.Tests namespace Sixam.CST.Tests
{ {
public class MultilineTests public class MultilineTests
{ {

View file

@ -1,7 +1,8 @@
// This project is licensed under the MIT license. // This project is licensed under the MIT license.
using Xunit; using Xunit;
namespace CSTNet.Tests namespace Sixam.CST.Tests
{ {
public class SingleLineTests public class SingleLineTests
{ {

View file

@ -1,4 +1,4 @@
Singleline^Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies nulla eu tortor mattis, dictum posuere lacus ornare. Maecenas a massa in ligula finibus luctus eu vitae nibh. Proin imperdiet dapibus mauris quis placerat.^ Singleline^Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies nulla eu tortor mattis, dictum posuere lacus ornare. Maecenas a massa in ligula finibus luctus eu vitae nibh. Proin imperdiet dapibus mauris quis placerat.^
Multiline ^Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc gravida nunc non justo pretium consectetur. Sed tempus libero ac ligula aliquam elementum. Duis vitae interdum leo. Sed semper nulla %1 a lectus dictum dictum. Multiline ^Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc gravida nunc non justo pretium consectetur. Sed tempus libero ac ligula aliquam elementum. Duis vitae interdum leo. Sed semper nulla %1 a lectus dictum dictum.
Quisque vehicula, nisi ut scelerisque sodales, nisi ipsum sodales ipsum, in rutrum tellus lacus sed nibh. Etiam mauris velit, elementum sed placerat et, elementum et tellus. Duis vitae elit fermentum, viverra lorem in, lobortis elit^ Quisque vehicula, nisi ut scelerisque sodales, nisi ipsum sodales ipsum, in rutrum tellus lacus sed nibh. Etiam mauris velit, elementum sed placerat et, elementum et tellus. Duis vitae elit fermentum, viverra lorem in, lobortis elit.^

View file

@ -1,3 +0,0 @@
extensions: designer.cs generated.cs
extensions: .cs .cpp .h
// This project is licensed under the MIT license.

View file

@ -1,26 +1,26 @@
// This project is licensed under the MIT license. // This project is licensed under the MIT license.
// See the LICENSE file in the project root for more information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace CSTNet namespace Sixam.CST
{ {
public static class CaretSeparatedText public class CaretSeparatedText
{ {
const char CARET = '^'; const char CARET = '^';
static readonly string _lf = "\u000A"; const string LF = "\u000A";
static readonly string _cr = "\u000D"; const string CR = "\u000D";
static readonly string _crlf = "\u000D\u000A"; const string CRLF = "\u000D\u000A";
static readonly string _ls = "\u2028"; const string LS = "\u2028";
/// <summary> /// <summary>
/// Gets the value from the integer-based key. /// Gets the value from the digit-based key.
/// </summary> /// </summary>
/// <returns>Returns the entry</returns> /// <returns>Returns the entry</returns>
public static string Parse(string content, int key) public static string Parse(string content, int key) => Parse(content, key.ToString());
{
var entries = NormalizeEntries(content);
return GetEntry(entries, key.ToString());
}
/// <summary> /// <summary>
/// Gets the value from the string-based key. /// Gets the value from the string-based key.
@ -40,34 +40,28 @@ namespace CSTNet
{ {
if (!content.Contains(Environment.NewLine)) if (!content.Contains(Environment.NewLine))
{ {
if (content.Contains(_lf)) if (content.Contains(LF))
content = content.Replace(_lf, Environment.NewLine); content = content.Replace(LF, Environment.NewLine);
if (content.Contains(_cr)) if (content.Contains(CR))
content = content.Replace(_cr, Environment.NewLine); content = content.Replace(CR, Environment.NewLine);
if (content.Contains(_crlf)) if (content.Contains(CRLF))
content = content.Replace(_crlf, Environment.NewLine); content = content.Replace(CRLF, Environment.NewLine);
if (content.Contains(_ls)) if (content.Contains(LS))
content = content.Replace(_ls, Environment.NewLine); content = content.Replace(LS, Environment.NewLine);
} }
var lines = content.Split(new[] { $"{CARET}{Environment.NewLine}" }, var lines = content.Split(new[] { $"{CARET}{Environment.NewLine}" },
StringSplitOptions.RemoveEmptyEntries); StringSplitOptions.RemoveEmptyEntries);
var entries = new List<string>();
foreach (var line in lines) return lines.Where(line =>
{ !line.StartsWith("//") &&
// Skip comments !line.StartsWith("#") &&
if (line.StartsWith("//") || line.StartsWith("#") || !line.StartsWith("/*") &&
line.StartsWith("/*") || line.EndsWith("*/")) !line.EndsWith("*/"))
continue; .AsEnumerable();
entries.Add(line);
}
return entries;
} }
static string GetEntry(IEnumerable<string> entries, string key) static string GetEntry(IEnumerable<string> entries, string key)
@ -90,3 +84,9 @@ namespace CSTNet
} }
} }
} }
namespace CSTNet
{
[Obsolete("CaretSeparatedText has moved to the Sixam.CST namespace.")]
public class CaretSeparatedText : Sixam.CST.CaretSeparatedText { }
}

View file

@ -2,9 +2,13 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.2</Version> <Version>1.0.300</Version>
<Authors>Tony Bark</Authors> <Authors>Tony Bark, Sixam Software</Authors>
<PackageDescription>Caret-Separated Text (or CST) is a key-value pair format represented by numbers or words as keys and the value is the string enclosed between carets (^) that contains the contents. CST.NET is a library for prasing the CST format.</PackageDescription> <PackageDescription>
Caret-Separated Text (or CST) is a key-value pair format represented by numbers or words as keys and the value is the string enclosed between carets that contains the contents. ([key] ^[value]^)
CST.NET is a parser for the CST format.
</PackageDescription>
<RepositoryUrl>https://github.com/sixamsoft/cst-dotnet</RepositoryUrl> <RepositoryUrl>https://github.com/sixamsoft/cst-dotnet</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<Product>CST.Net</Product> <Product>CST.Net</Product>

View file

@ -11,7 +11,7 @@ Caret-Separated Text (or CST) is a key-value pair format represented by digits o
``` ```
```csharp ```csharp
#r "nuget:CSTNet,1.0.2" #r "nuget:CSTNet,1.0.300"
using System; using System;
using System.IO; using System.IO;
using CSTNet; using CSTNet;

View file

@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig .editorconfig = .editorconfig
changelog.md = changelog.md changelog.md = changelog.md
README.md = README.md README.md = README.md
Sixam.CST.sln.licenseheader = Sixam.CST.sln.licenseheader
EndProjectSection EndProjectSection
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sixam.CST.Tests", "CSTNet.Tests\Sixam.CST.Tests.csproj", "{B6A98C64-1419-4B9A-99CA-72BB11D29472}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sixam.CST.Tests", "CSTNet.Tests\Sixam.CST.Tests.csproj", "{B6A98C64-1419-4B9A-99CA-72BB11D29472}"

View file

@ -0,0 +1,4 @@
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

@ -1,11 +1,19 @@
# Change Log # Change Log
## 1.0.300
- Switched to Sixam.CST namespace and marked CSTNet namespace as obsolete.
- Performance improvements.
- Patch numbers are now in the triple digits.
## 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 point 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