Laxley Grandfather Clock puzzle artwork done.
This commit is contained in:
@@ -1,7 +1,99 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BriarQueen.Framework.Extensions
|
||||
{
|
||||
public class StringExtensions
|
||||
public static class StringExtensions
|
||||
{
|
||||
|
||||
private static readonly string[] Prefixes =
|
||||
{
|
||||
"ENV_",
|
||||
"PUZ_",
|
||||
"SUB_",
|
||||
"UI_",
|
||||
"SFX_",
|
||||
"BGM_",
|
||||
"BOOK_",
|
||||
"CLUE_",
|
||||
"PHOTO_"
|
||||
};
|
||||
|
||||
private static readonly IReadOnlyDictionary<string, string> Overrides =
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
{ "Pumphouse", "Pump House" },
|
||||
{ "Lockbox", "Lockbox" },
|
||||
{ "Codex", "Codex" },
|
||||
{ "UIFX", "UI FX" },
|
||||
{ "SFX", "SFX" },
|
||||
{ "BGM", "BGM" }
|
||||
};
|
||||
|
||||
public static string Prettify(this string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return string.Empty;
|
||||
|
||||
value = StripPrefix(value);
|
||||
value = value.Replace("_", " ");
|
||||
value = AddSpacing(value);
|
||||
value = Regex.Replace(value, @"\s+", " ").Trim();
|
||||
|
||||
if (value.Length == 0)
|
||||
return string.Empty;
|
||||
|
||||
var words = value.Split(' ');
|
||||
var sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < words.Length; i++)
|
||||
{
|
||||
var word = words[i];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(word))
|
||||
continue;
|
||||
|
||||
string formatted = FormatWord(word);
|
||||
|
||||
sb.Append(formatted);
|
||||
|
||||
if (i < words.Length - 1)
|
||||
sb.Append(' ');
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static string StripPrefix(string value)
|
||||
{
|
||||
foreach (var prefix in Prefixes)
|
||||
{
|
||||
if (value.StartsWith(prefix))
|
||||
return value.Substring(prefix.Length);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static string AddSpacing(string value)
|
||||
{
|
||||
value = Regex.Replace(value, "([a-z0-9])([A-Z])", "$1 $2");
|
||||
value = Regex.Replace(value, "([A-Z]+)([A-Z][a-z])", "$1 $2");
|
||||
value = Regex.Replace(value, "([a-zA-Z])([0-9])", "$1 $2");
|
||||
value = Regex.Replace(value, "([0-9])([a-zA-Z])", "$1 $2");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static string FormatWord(string word)
|
||||
{
|
||||
if (Overrides.TryGetValue(word, out var overrideValue))
|
||||
return overrideValue;
|
||||
|
||||
if (word.Length > 1 && word.ToUpperInvariant() == word)
|
||||
return word;
|
||||
|
||||
return char.ToUpperInvariant(word[0]) + word.Substring(1).ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user