-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathUtils.cs
More file actions
95 lines (74 loc) · 2.71 KB
/
Copy pathUtils.cs
File metadata and controls
95 lines (74 loc) · 2.71 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ScriptHelper
{
static class Utils
{
public static string TextBetweenBrackets(string input)
{
int startIndex = input.IndexOf('[');
int endIndex = input.IndexOf(']');
if (startIndex != -1 && endIndex != -1 && endIndex > startIndex)
{
return input.Substring(startIndex + 1, endIndex - startIndex - 1);
}
return string.Empty;
}
public static string makePendingMessage(string model)
{
return "awaiting reponse from " + model + "\n";
}
public static string stripNonASCII(string input)
{
return Regex.Replace(input, @"[^\u0000-\u007F]+", "");
}
public static string rightOfArrow(string input)
{
int startIndex = input.IndexOf('>');
if (startIndex != -1)
{
return input.Substring(startIndex + 1);
}
return input;
}
public static string JSONFixer(string incorrectJson)
{
// remove trailing and leading space
incorrectJson = incorrectJson.Trim();
// Remove whitespace between double [[ or ]]
incorrectJson = Regex.Replace(incorrectJson, @"\[\s+\[", "[[");
incorrectJson = Regex.Replace(incorrectJson, @"\]\s+\]", "]]");
// Remove white space ", " to ","
incorrectJson = Regex.Replace(incorrectJson, "\",\\s+", "\",");
//inserts missing " at beginning and end of string
incorrectJson = InsertQuote(incorrectJson);
incorrectJson = incorrectJson.Substring(1, incorrectJson.Length - 2);
incorrectJson = incorrectJson.Replace("[[", "[").Replace("]]", "]");
incorrectJson = "[" + incorrectJson + "]";
return incorrectJson;
}
public static string InsertQuote(string inputString)
{
var sb = new StringBuilder();
for (int i = 0; i < inputString.Length; i++)
{
sb.Append(inputString[i]);
// Check for the pattern '",x' where x is any character not '"'
if (i > 1 && inputString[i - 2] == '"' && inputString[i - 1] == ',' && inputString[i] != '"')
{
// Insert '"' before x
sb.Insert(sb.Length - 1, '"');
}
}
return sb.ToString();
}
public static void nop()
{
return;
}
}
}