Skip to content

Commit 1f8f29a

Browse files
authored
Regex From String (#208)
1 parent 2d28bb9 commit 1f8f29a

File tree

11 files changed

+123
-4
lines changed

11 files changed

+123
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Utility Web App written in Blazor WebAssembly (WASM)
2323
- Url Encode
2424
- Url
2525
- Guid
26+
- Regex from String
2627
- SQL (IN Clause / LIKE)
2728
- Luhn
2829
- Hidden Char Finder ([Original](https://www.soscisurvey.de/tools/view-chars.php) [Source](https://github.com/BurninLeo/see-non-printable-characters/blob/main/view-chars.php))

docs/ACKNOWLEDGEMENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Humanizer
99
- Blazored.LocalStorage
1010
- [BlazorMonaco](https://github.com/serdarciplak/BlazorMonaco)
11+
- Fare
1112

1213
- OpenIconic https://www.appstudio.dev/app/OpenIconic.html
1314
- https://github.com/iconic/open-iconic

src/Utility.Test/GuidGeneratorTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void MultipleDeleteShouldBeEmpty()
100100
{
101101
var cut = RenderComponent<GuidGenerator>();
102102
cut.FindAll("button")[5].Click();
103-
string markup = "<textarea id=\"guids\" class=\"form-control\" value=\"\" ></textarea>";
103+
string markup = "<textarea id=\"guids\" class=\"form-control\" rows=\"5\" value=\"\"></textarea>";
104104
cut.FindAll("textarea")[0].MarkupMatches(markup); // guids
105105
}
106106

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Bunit;
2+
using Utility.Components.Regex;
3+
using Xunit;
4+
5+
namespace Utility.Test;
6+
7+
public class RegexFromStringTest: TestContext
8+
{
9+
public RegexFromStringTest() {}
10+
11+
//[Fact]
12+
public void RegexFromString_EmptyString_EmptyString()
13+
{
14+
var cut = RenderComponent<RegexFromString>();
15+
cut.FindAll("button")[0].Click();
16+
17+
RegexFromString regexFromString = cut.Instance;
18+
Assert.Equal(regexFromString.Output, string.Empty);
19+
}
20+
}

src/Utility.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{53EC20CC-B77E-4620-91E4-90D0FA828C52}"
1313
ProjectSection(SolutionItems) = preProject
1414
global.json = global.json
15+
..\README.md = ..\README.md
16+
..\docs\ACKNOWLEDGEMENTS.md = ..\docs\ACKNOWLEDGEMENTS.md
17+
..\docs\CHANGELOG.md = ..\docs\CHANGELOG.md
18+
..\docs\CONTRIBUTORS.md = ..\docs\CONTRIBUTORS.md
19+
..\docs\README.md = ..\docs\README.md
1520
EndProjectSection
1621
EndProject
1722
Global

src/Utility/Components/GuidGenerator/GuidGenerator.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
</div>
8787
</div>
8888
<div class="row">
89-
<textarea id="guids" class="form-control" @bind="NewGuids" rows="5"></textarea>
89+
<textarea id="guids" class="form-control" @bind="NewGuids" rows="@guidCount"></textarea>
9090
</div>
9191
</div>
9292

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
@using System.Text
2+
@using Fare
3+
@inject IJSRuntime JSRuntime
4+
5+
<div class="container">
6+
<div class="row">
7+
<div class="col">
8+
9+
<label class="label-control">Regular Expression:</label>
10+
<div class="input-group">
11+
<input type="regularExpression" id="regularExpression" name="regularExpression" class="form-control" @bind="RegularExpression">
12+
</div>
13+
14+
</div>
15+
16+
<div class="col">
17+
18+
<label class="label-control">Count:</label>
19+
<div class="input-group">
20+
<input type="count" id="count" name="count" class="form-control" @bind="Count">
21+
</div>
22+
23+
</div>
24+
25+
</div>
26+
27+
<div class="row">
28+
<div class="col">
29+
<button id="Generate" name="Generate" @onclick="Generate" class="btn btn-success float-right">Generate</button>
30+
</div>
31+
</div>
32+
33+
<div class="row">
34+
<div class="col">
35+
<div class="input-group">
36+
<textarea id="output" class="form-control" rows="@Count" @bind="Output"></textarea>
37+
<span class="input-group-btn">
38+
<button id="btnCopy" name="btnCopy" class="btn btn-info float-right" @onclick="Copy"><i class="far fa-copy"></i></button>
39+
</span>
40+
</div>
41+
</div>
42+
</div>
43+
44+
<div class="row">
45+
<div class="col">
46+
<p>Inspired from <a href="https://onlinestringtools.com/generate-string-from-regex" target="_blank">String from Regex Generator</a></p>
47+
</div>
48+
</div>
49+
50+
</div>
51+
52+
@code
53+
{
54+
[Parameter]
55+
public string Output { get; set; }
56+
57+
string RegularExpression;
58+
int Count;
59+
60+
protected override void OnInitialized()
61+
{
62+
RegularExpression = @"\d{1,5}";
63+
Count = 5;
64+
Output = "";
65+
}
66+
67+
private void Generate()
68+
{
69+
StringBuilder builder = new StringBuilder();
70+
for (int i = 0; i < Count; i++)
71+
{
72+
var xeger = new Xeger(RegularExpression);
73+
var random = xeger.Generate();
74+
75+
builder.Append(random + System.Environment.NewLine);
76+
}
77+
78+
Output = builder.ToString().Trim();
79+
}
80+
81+
async Task Copy()
82+
{
83+
await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", Output);
84+
}
85+
}

src/Utility/Components/Regex/RegexFromString.razor.css

Whitespace-only changes.

src/Utility/Pages/Index.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<li><a href="binary">Binary</a></li>
1818
<li><a href="stringconverter">String</a></li>
1919
<li><a href="stringconverter">Base64 Encode/Decode</a></li>
20+
<li><a href="stringconverter">Regex From String</a></li>
2021
<li><a href="epoch">Epoch</a></li>
2122
<li><a href="converter">time converter</a></li>
2223
<li><a href="converter">kb - mb - gb converter</a></li>

src/Utility/Pages/StringConvertor.razor

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
@using Utility.Components.StringConverter
44
@using Utility.Components.Base64
5+
@using Utility.Components.Regex
56

6-
<PageTitle>String Converter</PageTitle>
7+
<PageTitle>String Tools</PageTitle>
78

8-
<h1>String Converter</h1>
9+
<h1>String Tools</h1>
10+
11+
<RegexFromString />
12+
13+
<hr/>
914

1015
<Base64 Input="QWxleEhlZGxleQ==" />
1116

0 commit comments

Comments
 (0)