mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
add custom base option
2 to 62
This commit is contained in:
parent
c0cbdd938e
commit
0799555315
3 changed files with 64 additions and 7 deletions
|
@ -63,6 +63,7 @@ public override String ToPrefixString()
|
|||
public static readonly ReplCodeMenuEntry i = new ReplCodeMenuEntry("i", Resources.ReplCodeMenuEntry_i_Auto_increment_number, Resources.ReplCodeMenuCategory_Incremental);
|
||||
public static readonly ReplCodeMenuEntry ia = new ReplCodeMenuEntry("ia", Resources.ReplCodeMenuEntry_ia_Auto_increment_alphanumeric, Resources.ReplCodeMenuCategory_Incremental);
|
||||
public static readonly ReplCodeMenuEntry iAa = new ReplCodeMenuEntry("iAa", Resources.ReplCodeMenuEntry_iAa_Auto_increment_alphanumeric_all, Resources.ReplCodeMenuCategory_Incremental);
|
||||
public static readonly ReplCodeMenuEntry ib = new ReplCodeMenuEntry("ib", Resources.ReplCodeMenuEntry_ib_Auto_increment_base_alphanumeric, Resources.ReplCodeMenuCategory_Incremental);
|
||||
public static readonly ReplCodeMenuEntry ix = new ReplCodeMenuEntry("ix", Resources.ReplCodeMenuEntry_ix_Auto_increment_hexadecimal, Resources.ReplCodeMenuCategory_Incremental);
|
||||
public static readonly ReplCodeMenuEntry rn = new ReplCodeMenuEntry("rn", Resources.ReplCodeMenuEntry_rn_Random_number_0_to_9, Resources.ReplCodeMenuCategory_Random);
|
||||
public static readonly ReplCodeMenuEntry ra = new ReplCodeMenuEntry("ra", Resources.ReplCodeMenuEntry_ra_Random_alphanumeric_char, Resources.ReplCodeMenuCategory_Random);
|
||||
|
@ -90,7 +91,7 @@ public class NameParser
|
|||
public NameParserType Type { get; private set; }
|
||||
public int MaxNameLength { get; set; }
|
||||
public int MaxTitleLength { get; set; }
|
||||
public int AutoIncrementNumber { get; set; } // %i, %ia, %iAa, %ix
|
||||
public int AutoIncrementNumber { get; set; } // %i, %ia, %ib, %iAa, %ix
|
||||
public Image Picture { get; set; } // %width, %height
|
||||
public string WindowText { get; set; } // %t
|
||||
public string ProcessName { get; set; } // %pn
|
||||
|
@ -181,6 +182,8 @@ public string Parse(string pattern)
|
|||
sb.Replace(ReplCodeMenuEntry.unix.ToPrefixString(), DateTime.UtcNow.ToUnix().ToString());
|
||||
|
||||
if (sb.ToString().Contains(ReplCodeMenuEntry.i.ToPrefixString())
|
||||
|| sb.ToString().Contains(ReplCodeMenuEntry.ib.ToPrefixString())
|
||||
|| sb.ToString().Contains(ReplCodeMenuEntry.ib.ToPrefixString().Replace('b', 'B'))
|
||||
|| sb.ToString().Contains(ReplCodeMenuEntry.iAa.ToPrefixString())
|
||||
|| sb.ToString().Contains(ReplCodeMenuEntry.iAa.ToPrefixString().Replace("Aa", "aA"))
|
||||
|| sb.ToString().Contains(ReplCodeMenuEntry.ia.ToPrefixString())
|
||||
|
@ -190,6 +193,22 @@ public string Parse(string pattern)
|
|||
{
|
||||
AutoIncrementNumber++;
|
||||
|
||||
// Base
|
||||
try
|
||||
{
|
||||
foreach (Tuple<string, int[]> entry in ListEntryWithValues(sb.ToString(), ReplCodeMenuEntry.ib.ToPrefixString(), 2))
|
||||
{
|
||||
sb.Replace(entry.Item1, Helpers.AddZeroes(AutoIncrementNumber.ToBase(entry.Item2[0], Helpers.AlphanumericInverse), entry.Item2[1]));
|
||||
}
|
||||
foreach (Tuple<string, int[]> entry in ListEntryWithValues(sb.ToString(), ReplCodeMenuEntry.ib.ToPrefixString().Replace('b', 'B'), 2))
|
||||
{
|
||||
sb.Replace(entry.Item1, Helpers.AddZeroes(AutoIncrementNumber.ToBase(entry.Item2[0], Helpers.Alphanumeric), entry.Item2[1]));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
// Alphanumeric Dual Case (Base 62)
|
||||
foreach (Tuple<string, int> entry in ListEntryWithValue(sb.ToString(), ReplCodeMenuEntry.iAa.ToPrefixString()))
|
||||
{
|
||||
|
@ -301,15 +320,41 @@ public string Parse(string pattern)
|
|||
return result;
|
||||
}
|
||||
|
||||
private IEnumerable<Tuple<string, string[]>> ListEntryWithArguments(string text, string entry, int elements)
|
||||
{
|
||||
foreach (Tuple<string, string> o in text.ForEachBetween(entry + "{", "}"))
|
||||
{
|
||||
string[] s = o.Item2.Split(',');
|
||||
if (elements > s.Length)
|
||||
{
|
||||
Array.Resize(ref s, elements);
|
||||
}
|
||||
yield return new Tuple<string, string[]>(o.Item1, s);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<Tuple<string, int[]>> ListEntryWithValues(string text, string entry, int elements)
|
||||
{
|
||||
foreach (Tuple<string, string[]> o in ListEntryWithArguments(text, entry, elements))
|
||||
{
|
||||
int[] a = new int[o.Item2.Length];
|
||||
for (int i = o.Item2.Length - 1; i >= 0; --i)
|
||||
{
|
||||
int n = 0;
|
||||
if (int.TryParse(o.Item2[i], out n))
|
||||
{
|
||||
a[i] = n;
|
||||
}
|
||||
}
|
||||
yield return new Tuple<string, int[]>(o.Item1, a);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<Tuple<string, int>> ListEntryWithValue(string text, string entry)
|
||||
{
|
||||
foreach (Tuple<string, string> s in text.ForEachBetween(entry + "{", "}"))
|
||||
foreach (Tuple<string, int[]> o in ListEntryWithValues(text, entry, 1))
|
||||
{
|
||||
int n = 0;
|
||||
if (int.TryParse(s.Item2, out n))
|
||||
{
|
||||
yield return new Tuple<string, int>(s.Item1, n);
|
||||
}
|
||||
yield return new Tuple<string, int>(o.Item1, o.Item2[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1762,6 +1762,15 @@ internal static string ReplCodeMenuEntry_iAa_Auto_increment_alphanumeric_all {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Auto increment by base {n} using alphanumeric (1 < n < 63).
|
||||
/// </summary>
|
||||
internal static string ReplCodeMenuEntry_ib_Auto_increment_base_alphanumeric {
|
||||
get {
|
||||
return ResourceManager.GetString("ReplCodeMenuEntry_ib_Auto_increment_base_alphanumeric", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Auto increment hexadecimal. 0 pad left using {n}.
|
||||
/// </summary>
|
||||
|
|
|
@ -796,6 +796,9 @@ Would you like to download and install it?</value>
|
|||
<data name="ReplCodeMenuEntry_iAa_Auto_increment_alphanumeric_all" xml:space="preserve">
|
||||
<value>Auto increment alphanumeric case-insensitive. 0 pad left using {n}</value>
|
||||
</data>
|
||||
<data name="ReplCodeMenuEntry_ib_Auto_increment_base_alphanumeric" xml:space="preserve">
|
||||
<value>Auto increment by base {n} using alphanumeric (1 < n < 63)</value>
|
||||
</data>
|
||||
<data name="ReplCodeMenuEntry_guid_Random_guid" xml:space="preserve">
|
||||
<value>Random GUID</value>
|
||||
</data>
|
||||
|
|
Loading…
Reference in a new issue