-
Notifications
You must be signed in to change notification settings - Fork 2
/
DocSyntax.cs
77 lines (67 loc) · 2.16 KB
/
DocSyntax.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// DocGen Source
//
// Copyright (c) 2019 ADAM MAJCHEREK ALL RIGHTS RESERVED
//
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace DocGen
{
internal static class DocSyntax
{
/// <summary>
/// Gets markdown file by adding .md extension. exdi?
/// </summary>
internal static string GetMarkdownFile(string fileName) => $"{fileName}.md";
/// <summary>
/// Returns reference to a markdown file for given Type.
/// </summary>
internal static string CollectMarkDownReference(Type t)
{
var baseTypeName = CollectTypeName(t);
return GetMarkdownFile($"{AppConfig.Loaded.DeploySidebarPath}{baseTypeName}");
}
/// <summary>
/// Returns a name in markdown environment of given Type.
/// </summary>
internal static string CollectTypeName(Type t) => "obj" + t.Name;
/// <summary>
/// Removes all spaces and new lines from string.
/// </summary>
internal static string RemoveSpaces(string str)
{
if (string.IsNullOrEmpty(str))
return str;
var line = Regex.Replace(str, @"\t|\n|\r", "");
while (line.IndexOf(" ", StringComparison.Ordinal) >= 0)
{
line = line.Replace(" ", " ");
}
return line;
}
/// <summary>
/// Fixes string by replacing all not allowed characters.
/// </summary>
internal static string FixVarName(string str)
{
FixVarName(ref str);
return str;
}
/// <summary>
/// Fixes string by replacing all not allowed characters.
/// </summary>
internal static bool FixVarName(ref string str)
{
char[] banned =
{
' ', '(', ')', '[', ']', '"', '"',
"'"[0], '<', '>', ',', '?', '/',
'!', '-', '+', '=', '`'
};
var p = str;
str = banned.Aggregate(str, (current, c) => current.Replace(c, '_'));
return p != str;
}
}
}