Skip to content

Commit

Permalink
feat(ux): ✨ implement flag escaping (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Jun 23, 2023
1 parent d499a9b commit 8a657d3
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 57 deletions.
11 changes: 11 additions & 0 deletions src/Main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows.Controls;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -36,6 +37,16 @@ public static string ExtractFromQuery(Query query, int index)
: string.Join(" ", query.SearchTerms.Skip(index));
}

public static string ReplaceSearchBackslashes(string search)
{
return Regex.Replace(search, @"(\\(?!\\))", string.Empty);
}

public static string EscapePotentialFlags(string description)
{
return Regex.Replace(description, @" -", @" \-");
}

/// <summary>
/// Runs on plugin initialisation.
/// Expensive operations should be performed here.
Expand Down
42 changes: 32 additions & 10 deletions src/Structures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,35 @@ public TimeEntry(DetailedReportTimeEntryResponse timeEntryResponse, DetailedRepo
this.Project = this._me.GetProject(this.ProjectId);
}

public string? GetRawDescription(bool withTrailingSpace = false)
public string? GetRawDescription(bool withTrailingSpace = false, bool escapePotentialFlags = false)
{
if (string.IsNullOrEmpty(this._rawDescription))
{
return string.Empty;
}

string rawDescription = (escapePotentialFlags)
? Main.EscapePotentialFlags(this._rawDescription)
: this._rawDescription;

if (!withTrailingSpace)
{
return this._rawDescription;
return rawDescription;
}

return $"{this._rawDescription} ";
return $"{rawDescription} ";
}

public string Description
public string GetDescription(bool escapePotentialFlags = false)
{
get => (string.IsNullOrEmpty(this._rawDescription)) ? "(no description)" : this._rawDescription;
if (string.IsNullOrEmpty(this._rawDescription))
{
return "(no description)";
}

return (escapePotentialFlags)
? Main.EscapePotentialFlags(this._rawDescription)
: this._rawDescription;
}

public DateTimeOffset StartDate
Expand Down Expand Up @@ -527,24 +538,35 @@ object ICloneable.Clone()
return this.Clone();
}

public string? GetRawTitle(bool withTrailingSpace = false)
public string? GetRawTitle(bool withTrailingSpace = false, bool escapePotentialFlags = false)
{
if (string.IsNullOrEmpty(this._rawTitle))
{
return string.Empty;
}

string rawTitle = (escapePotentialFlags)
? Main.EscapePotentialFlags(this._rawTitle)
: this._rawTitle;

if (!withTrailingSpace)
{
return this._rawTitle;
return rawTitle;
}

return $"{this._rawTitle} ";
return $"{rawTitle} ";
}

public string Title
public string GetTitle(bool escapePotentialFlags = false)
{
get => (string.IsNullOrEmpty(this._rawTitle)) ? "(no description)" : this._rawTitle;
if (string.IsNullOrEmpty(this._rawTitle))
{
return "(no description)";
}

return (escapePotentialFlags)
? Main.EscapePotentialFlags(this._rawTitle)
: this._rawTitle;
}

public TimeSpan Elapsed
Expand Down
Loading

0 comments on commit 8a657d3

Please sign in to comment.