mirror of
https://github.com/tonytins/cstdotnet.git
synced 2025-07-06 06:20:26 -04:00
1.0.300
- Switched to Sixam.CST namespace and marked CSTNet namespace as obsolete. - Performance improvements.
This commit is contained in:
parent
e8f7bf4d0a
commit
2d310cee53
9 changed files with 56 additions and 42 deletions
|
@ -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 { }
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue