mirror of
https://github.com/tonytins/cstdotnet.git
synced 2025-10-16 19:03:37 -04:00
Updated notebook with the tweaked algorithm
This commit is contained in:
parent
efa9c5535f
commit
dfea139f95
3 changed files with 23 additions and 49 deletions
|
@ -63,46 +63,36 @@
|
|||
" /// <remarks>This stage ensures there are no crashes during parsing.</remarks>\n",
|
||||
" static IEnumerable<string> NormalizeEntries(string content)\n",
|
||||
" {\n",
|
||||
"\n",
|
||||
" /* \n",
|
||||
" I tried putting the end carets with the different\n",
|
||||
" line endings in with the split function but it didn't work \n",
|
||||
" */\n",
|
||||
" if (!content.Contains($\"{CARET}{Environment.NewLine}\"))\n",
|
||||
" if (!content.Contains(Environment.NewLine))\n",
|
||||
" {\n",
|
||||
" if (content.Contains($\"{CARET}{_lf}\"))\n",
|
||||
" content = content.Replace($\"{CARET}{_lf}\",\n",
|
||||
" $\"{CARET}{Environment.NewLine}\");\n",
|
||||
" if (content.Contains(_lf))\n",
|
||||
" content = content.Replace(_lf, Environment.NewLine);\n",
|
||||
"\n",
|
||||
" if (content.Contains($\"{CARET}{_cr}\"))\n",
|
||||
" content = content.Replace($\"{CARET}{_cr}\",\n",
|
||||
" $\"{CARET}{Environment.NewLine}\");\n",
|
||||
" if (content.Contains(_cr))\n",
|
||||
" content = content.Replace(_cr, Environment.NewLine);\n",
|
||||
"\n",
|
||||
" if (content.Contains($\"{CARET}{_crlf}\"))\n",
|
||||
" content = content.Replace($\"{CARET}{_crlf}\",\n",
|
||||
" $\"{CARET}{Environment.NewLine}\");\n",
|
||||
" if (content.Contains(_crlf))\n",
|
||||
" content = content.Replace(_crlf, Environment.NewLine);\n",
|
||||
"\n",
|
||||
" if (content.Contains($\"{CARET}{_ls}\"))\n",
|
||||
" content = content.Replace($\"{CARET}{_ls}\",\n",
|
||||
" $\"{CARET}{Environment.NewLine}\");\n",
|
||||
" if (content.Contains(_ls))\n",
|
||||
" content = content.Replace(_ls, Environment.NewLine);\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" var entries = content.Split(new[] { $\"{CARET}{Environment.NewLine}\" },\n",
|
||||
" var lines = content.Split(new[] { $\"{CARET}{Environment.NewLine}\" },\n",
|
||||
" StringSplitOptions.RemoveEmptyEntries);\n",
|
||||
" var newContent = new List<string>();\n",
|
||||
" var entries = new List<string>();\n",
|
||||
"\n",
|
||||
" foreach (var entry in entries)\n",
|
||||
" foreach (var line in lines)\n",
|
||||
" {\n",
|
||||
" // Skip comments\n",
|
||||
" if (entry.StartsWith(@\"//\") || entry.StartsWith(\"#\") ||\n",
|
||||
" entry.StartsWith(\"/*\") || entry.EndsWith(\"*/\"))\n",
|
||||
" if (line.StartsWith(\"//\") || line.StartsWith(\"#\") ||\n",
|
||||
" line.StartsWith(\"/*\") || line.EndsWith(\"*/\"))\n",
|
||||
" continue;\n",
|
||||
"\n",
|
||||
" newContent.Add(entry);\n",
|
||||
" entries.Add(line);\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" return newContent;\n",
|
||||
" return entries;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" static string GetEntry(IEnumerable<string> entries, string key)\n",
|
||||
|
@ -110,32 +100,18 @@
|
|||
" // Search through list\n",
|
||||
" foreach (var entry in entries)\n",
|
||||
" {\n",
|
||||
" // Locate index, trim carets and return translation\n",
|
||||
" // If the line doesn't start with the key, keep searching.\n",
|
||||
" if (!entry.StartsWith(key))\n",
|
||||
" continue;\n",
|
||||
"\n",
|
||||
" // Locate index, trim carets and return translation.\n",
|
||||
" var startIndex = entry.IndexOf(CARET);\n",
|
||||
" var line = entry.Substring(startIndex);\n",
|
||||
"\n",
|
||||
" if (!line.Contains(Environment.NewLine))\n",
|
||||
" {\n",
|
||||
" if (line.Contains(_lf))\n",
|
||||
" line = line.Replace(_lf, Environment.NewLine);\n",
|
||||
"\n",
|
||||
" if (line.Contains(_cr))\n",
|
||||
" line = line.Replace(_cr, Environment.NewLine);\n",
|
||||
"\n",
|
||||
" if (line.Contains(_crlf))\n",
|
||||
" line = line.Replace(_crlf, Environment.NewLine);\n",
|
||||
"\n",
|
||||
" if (line.Contains(_ls))\n",
|
||||
" line = line.Replace(_ls, Environment.NewLine);\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" return line.TrimStart(CARET).TrimEnd(CARET);\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" return \"[ENTRY NOT FOUND]\";\n",
|
||||
" return \"***MISSING***\";\n",
|
||||
" }\n",
|
||||
"}"
|
||||
],
|
||||
|
@ -206,7 +182,7 @@
|
|||
{
|
||||
"output_type": "execute_result",
|
||||
"data": {
|
||||
"text/plain": "Multiline v2:\r\n[ENTRY NOT FOUND]\r\n"
|
||||
"text/plain": "Multiline v2:\r\n***MISSING***\r\n"
|
||||
},
|
||||
"execution_count": 1,
|
||||
"metadata": {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue