mirror of
https://github.com/tonytins/cstdotnet.git
synced 2025-03-15 06:01:25 +00:00
Migrated CST notebook from .NET Labs
- Added code of conduct - Updated README with requirements
This commit is contained in:
parent
2d6a9bb1d2
commit
0dce5e27ea
5 changed files with 296 additions and 2 deletions
14
README.md
14
README.md
|
@ -1,6 +1,8 @@
|
||||||
# CST.NET
|
# CST.NET
|
||||||
|
|
||||||
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.
|
[](https://opensource.org/licenses/MIT) [](code_of_conduct.md)
|
||||||
|
|
||||||
|
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 parsing the CST format.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
@ -17,7 +19,15 @@ Console.WriteLine(example);
|
||||||
|
|
||||||
## To-do
|
## To-do
|
||||||
|
|
||||||
- [ ] Support for arguments
|
- [ ] Support for arguments (e.g. ``%1``)
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- [.NET](https://dotnet.microsoft.com/download) 5+ or Core 3.1
|
||||||
|
- [.NET Interactive](https://github.com/dotnet/interactive/blob/main/README.md) for notebooks
|
||||||
|
- [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode) (does not require Jupyter)
|
||||||
|
- [nteract](https://nteract.io/) (requires Jupyter)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
132
code_of_conduct.md
Normal file
132
code_of_conduct.md
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
We as members, contributors, and leaders pledge to make participation in our
|
||||||
|
community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||||
|
identity and expression, level of experience, education, socio-economic status,
|
||||||
|
nationality, personal appearance, race, religion, or sexual identity
|
||||||
|
and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||||
|
diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to a positive environment for our
|
||||||
|
community include:
|
||||||
|
|
||||||
|
* Demonstrating empathy and kindness toward other people
|
||||||
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
|
* Giving and gracefully accepting constructive feedback
|
||||||
|
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
|
and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the
|
||||||
|
overall community
|
||||||
|
|
||||||
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery, and sexual attention or
|
||||||
|
advances of any kind
|
||||||
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or email
|
||||||
|
address, without their explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
|
Community leaders are responsible for clarifying and enforcing our standards of
|
||||||
|
acceptable behavior and will take appropriate and fair corrective action in
|
||||||
|
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||||
|
or harmful.
|
||||||
|
|
||||||
|
Community leaders have the right and responsibility to remove, edit, or reject
|
||||||
|
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||||
|
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||||
|
decisions when appropriate.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies within all community spaces, and also applies when
|
||||||
|
an individual is officially representing the community in public spaces.
|
||||||
|
Examples of representing our community include using an official e-mail address,
|
||||||
|
posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported to the community leaders responsible for enforcement at
|
||||||
|
[INSERT CONTACT METHOD].
|
||||||
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
|
|
||||||
|
All community leaders are obligated to respect the privacy and security of the
|
||||||
|
reporter of any incident.
|
||||||
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining
|
||||||
|
the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||||
|
unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing
|
||||||
|
clarity around the nature of the violation and an explanation of why the
|
||||||
|
behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series
|
||||||
|
of actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No
|
||||||
|
interaction with the people involved, including unsolicited interaction with
|
||||||
|
those enforcing the Code of Conduct, for a specified period of time. This
|
||||||
|
includes avoiding interactions in community spaces as well as external channels
|
||||||
|
like social media. Violating these terms may lead to a temporary or
|
||||||
|
permanent ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including
|
||||||
|
sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public
|
||||||
|
communication with the community for a specified period of time. No public or
|
||||||
|
private interaction with the people involved, including unsolicited interaction
|
||||||
|
with those enforcing the Code of Conduct, is allowed during this period.
|
||||||
|
Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community
|
||||||
|
standards, including sustained inappropriate behavior, harassment of an
|
||||||
|
individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within
|
||||||
|
the community.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||||
|
version 2.0, available at
|
||||||
|
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by
|
||||||
|
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see the FAQ at
|
||||||
|
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
||||||
|
at [https://www.contributor-covenant.org/translations][translations].
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
||||||
|
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||||
|
[FAQ]: https://www.contributor-covenant.org/faq
|
||||||
|
[translations]: https://www.contributor-covenant.org/translations
|
140
notebooks/cst.ipynb
Normal file
140
notebooks/cst.ipynb
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Caret-Separated Text\n",
|
||||||
|
"\n",
|
||||||
|
"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 translation. Any text which is not enclosed with carets is considered a comment and ignored.\n",
|
||||||
|
"\n",
|
||||||
|
"## CST.NET\n",
|
||||||
|
"\n",
|
||||||
|
"My parser, CST.NET, uses .NET's built-in indexing extension function to accomplish locating of each respective key. Originally, CST keys were only numbered-based but the indexing naturally elimates this restriction. There is no consequence for using something other numbers now. An additional normalizion process of line endings from the document's to the system's, if needed, happens before it reads the file. This was done in order to prevent avoid crashes."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"using System.IO;"
|
||||||
|
],
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"public static class CST\n",
|
||||||
|
"{\n",
|
||||||
|
" public static string GetValue(string cst, int key, params string[] args)\n",
|
||||||
|
" {\n",
|
||||||
|
" var entries = NormalizeEntries(cst);\n",
|
||||||
|
" return ReadEntries(entries, $\"{key}\", args);\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" public static string GetValue(string cst, string key, params string[] args)\n",
|
||||||
|
" {\n",
|
||||||
|
" var entries = NormalizeEntries(cst);\n",
|
||||||
|
" return ReadEntries(entries, key, args);\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" static IEnumerable<string> NormalizeEntries(string cst)\n",
|
||||||
|
" {\n",
|
||||||
|
" var lineBreaks = new string[] { \"^\\u000A\", \"^\\u000D\", \"^\\u000A\" };\n",
|
||||||
|
"\n",
|
||||||
|
" foreach (var line in lineBreaks)\n",
|
||||||
|
" {\n",
|
||||||
|
" var eol = Environment.NewLine; // System's line break\n",
|
||||||
|
"\n",
|
||||||
|
" // If the new line matches the system's, do nothing\n",
|
||||||
|
" if (line.Contains(eol))\n",
|
||||||
|
" continue;\n",
|
||||||
|
"\n",
|
||||||
|
" cst.Replace(line, eol);\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" return cst.Split(lineBreaks, StringSplitOptions.RemoveEmptyEntries);\n",
|
||||||
|
"\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" // TODO: support argument parameters\n",
|
||||||
|
" static string ReadEntries(IEnumerable<string> entries, string key, params string[] args)\n",
|
||||||
|
" {\n",
|
||||||
|
" var translation = \"[ENTRY NOT FOUND]\";\n",
|
||||||
|
"\n",
|
||||||
|
" // Search through array\n",
|
||||||
|
" foreach (var entry in entries)\n",
|
||||||
|
" {\n",
|
||||||
|
" // Locate index, trim carets and return translation\n",
|
||||||
|
" if (!entry.StartsWith(key))\n",
|
||||||
|
" continue;\n",
|
||||||
|
" \n",
|
||||||
|
" const char caret = '^';\n",
|
||||||
|
" // const char token = '%';\n",
|
||||||
|
"\n",
|
||||||
|
" var startIndex = entry.IndexOf(caret.ToString(),\n",
|
||||||
|
" StringComparison.OrdinalIgnoreCase);\n",
|
||||||
|
"\n",
|
||||||
|
" var line = entry.Substring(startIndex);\n",
|
||||||
|
"\n",
|
||||||
|
" /*foreach (var arg in args)\n",
|
||||||
|
" Regex.Replace(line, $\"%[1-100]\", arg);*/\n",
|
||||||
|
"\n",
|
||||||
|
" translation = line.Trim(caret);\n",
|
||||||
|
" }\n",
|
||||||
|
"\n",
|
||||||
|
" return translation;\n",
|
||||||
|
" }\n",
|
||||||
|
"}"
|
||||||
|
],
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"var v1Path = Path.Combine(Environment.CurrentDirectory, \"data\", \"v1.cst\");\n",
|
||||||
|
"var v1File = File.ReadAllText(v1Path);\n",
|
||||||
|
"var multiLine = CST.GetValue(v1File, 1);\n",
|
||||||
|
"var singleLine = CST.GetValue(v1File, 2);\n",
|
||||||
|
"Console.WriteLine(singleLine);\n",
|
||||||
|
"Console.WriteLine(singleLine);"
|
||||||
|
],
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"var v2Path = Path.Combine(Environment.CurrentDirectory, \"data\", \"v2.cst\");\n",
|
||||||
|
"var v2File = File.ReadAllText(v2Path);\n",
|
||||||
|
"var multiLineV2 = CST.GetValue(v2File, \"Multiline\");\n",
|
||||||
|
"var singleLineV2 = CST.GetValue(v2File, \"Singleline\");\n",
|
||||||
|
"Console.WriteLine(singleLineV2);\n",
|
||||||
|
"Console.WriteLine(multiLineV2);"
|
||||||
|
],
|
||||||
|
"outputs": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": ".NET (C#)",
|
||||||
|
"language": "C#",
|
||||||
|
"name": ".net-csharp"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"file_extension": ".cs",
|
||||||
|
"mimetype": "text/x-csharp",
|
||||||
|
"name": "C#",
|
||||||
|
"pygments_lexer": "csharp",
|
||||||
|
"version": "8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
8
notebooks/data/v1.cst
Normal file
8
notebooks/data/v1.cst
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
1 ^Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac dictum orci, at tincidunt nulla. Donec aliquet, eros non interdum posuere, ipsum sapien molestie nunc, nec facilisis libero ipsum et risus. In sed lorem vel ipsum placerat viverra.^
|
||||||
|
2 ^Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pharetra nunc nec erat finibus efficitur. Duis non ullamcorper purus. Donec sit amet ultricies sapien. Sed lacinia sem eu nunc gravida, vitae tincidunt eros tempus. Quisque nibh est, tempus sit amet purus at, facilisis cursus ante. Nam nisi purus, vehicula sed magna ac, lobortis aliquam urna. Sed condimentum, felis a placerat tincidunt, est augue pulvinar turpis, eu dictum leo diam quis mi. Nulla non efficitur neque, sed efficitur orci. Aliquam quis libero consequat, convallis tortor sit amet, varius orci.
|
||||||
|
|
||||||
|
Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc vel dictum eros, vitae mattis risus. Curabitur eget nisi interdum, euismod nisl in, fermentum turpis. Morbi a feugiat lacus. Duis ligula felis, commodo quis sodales ac, congue sit amet tortor. Sed vulputate, velit id interdum convallis, purus nisl interdum lorem, sit amet aliquam lacus sapien ac neque. Proin sit amet ultricies mi.^
|
||||||
|
3 ^Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam venenatis ac odio ut pretium. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec semper turpis tempor, bibendum sapien at, blandit neque. Vivamus hendrerit imperdiet elit, vel sollicitudin nulla luctus vel. Vivamus nisl quam, feugiat a diam aliquam, iaculis vestibulum nunc. Maecenas euismod leo enim, faucibus ultrices ipsum semper eu. Praesent ullamcorper justo at maximus ultricies.^
|
||||||
|
4^Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce justo dui, rhoncus a pulvinar sit amet, fermentum vitae lorem. Maecenas nec nisi sit amet eros rutrum congue. In sagittis suscipit arcu, ac vestibulum nunc feugiat volutpat.
|
||||||
|
|
||||||
|
Vivamus consequat velit dui, sit amet rhoncus dui malesuada a. Maecenas hendrerit commodo mi et scelerisque. Cras pharetra ultrices aliquam. Praesent ac efficitur magna, vitae scelerisque metus.^
|
4
notebooks/data/v2.cst
Normal file
4
notebooks/data/v2.cst
Normal file
|
@ -0,0 +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.^
|
||||||
|
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. Ut mattis eu tortor in bibendum. Integer mattis tincidunt aliquet. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce quis orci nisl.
|
||||||
|
|
||||||
|
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. Maecenas eget nibh et lectus auctor dignissim.^
|
Loading…
Add table
Reference in a new issue