- Switched to Sixam.CST namespace and marked CSTNet namespace as obsolete.
- Performance improvements.
This commit is contained in:
Tony Bark 2020-12-13 05:19:18 -05:00
parent e8f7bf4d0a
commit 2d310cee53
9 changed files with 56 additions and 42 deletions

View file

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

View file

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

View file

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

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.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSTNet
namespace Sixam.CST
{
public static class CaretSeparatedText
public class CaretSeparatedText
{
const char CARET = '^';
static readonly string _lf = "\u000A";
static readonly string _cr = "\u000D";
static readonly string _crlf = "\u000D\u000A";
static readonly string _ls = "\u2028";
const string LF = "\u000A";
const string CR = "\u000D";
const string CRLF = "\u000D\u000A";
const string LS = "\u2028";
/// <summary>
/// Gets the value from the integer-based key.
/// Gets the value from the digit-based key.
/// </summary>
/// <returns>Returns the entry</returns>
public static string Parse(string content, int key)
{
var entries = NormalizeEntries(content);
return GetEntry(entries, key.ToString());
}
public static string Parse(string content, int key) => Parse(content, key.ToString());
/// <summary>
/// Gets the value from the string-based key.
@ -40,34 +40,28 @@ namespace CSTNet
{
if (!content.Contains(Environment.NewLine))
{
if (content.Contains(_lf))
content = content.Replace(_lf, Environment.NewLine);
if (content.Contains(LF))
content = content.Replace(LF, Environment.NewLine);
if (content.Contains(_cr))
content = content.Replace(_cr, Environment.NewLine);
if (content.Contains(CR))
content = content.Replace(CR, Environment.NewLine);
if (content.Contains(_crlf))
content = content.Replace(_crlf, Environment.NewLine);
if (content.Contains(CRLF))
content = content.Replace(CRLF, Environment.NewLine);
if (content.Contains(_ls))
content = content.Replace(_ls, Environment.NewLine);
if (content.Contains(LS))
content = content.Replace(LS, Environment.NewLine);
}
var lines = content.Split(new[] { $"{CARET}{Environment.NewLine}" },
StringSplitOptions.RemoveEmptyEntries);
var entries = new List<string>();
foreach (var line in lines)
{
// Skip comments
if (line.StartsWith("//") || line.StartsWith("#") ||
line.StartsWith("/*") || line.EndsWith("*/"))
continue;
entries.Add(line);
}
return entries;
return lines.Where(line =>
!line.StartsWith("//") &&
!line.StartsWith("#") &&
!line.StartsWith("/*") &&
!line.EndsWith("*/"))
.AsEnumerable();
}
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>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.2</Version>
<Authors>Tony Bark</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>
<Version>1.0.300</Version>
<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. ([key] ^[value]^)
CST.NET is a parser for the CST format.
</PackageDescription>
<RepositoryUrl>https://github.com/sixamsoft/cst-dotnet</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Product>CST.Net</Product>

View file

@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
changelog.md = changelog.md
README.md = README.md
Sixam.CST.sln.licenseheader = Sixam.CST.sln.licenseheader
EndProjectSection
EndProject
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,18 @@
# Change Log
## 1.0.300
- Switched to Sixam.CST namespace and marked CSTNet namespace as obsolete.
- Performance improvements.
## 1.0.2
- Fixed the multiple line parsing in the v2 format.
- Replaced "``[ENTRY NOT FOUND]``" message with "``***MISSING***``".
## 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