diff --git a/PKHeX/PKM/PK6.cs b/PKHeX/PKM/PK6.cs
index 3acb8e06c..c886f988c 100644
--- a/PKHeX/PKM/PK6.cs
+++ b/PKHeX/PKM/PK6.cs
@@ -209,21 +209,12 @@ namespace PKHeX
#region Block B
public override string Nickname
{
- get
- {
- return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x40, 24))
- .Replace("\uE08F", "\u2640") // nidoran
- .Replace("\uE08E", "\u2642") // nidoran
- .Replace("\u2019", "\u0027"); // farfetch'd
- }
+ get { return PKX.SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x40, 24))); }
set
{
if (value.Length > 12)
value = value.Substring(0, 12); // Hard cap
- string TempNick = value // Replace Special Characters and add Terminator
- .Replace("\u2640", "\uE08F") // nidoran
- .Replace("\u2642", "\uE08E") // nidoran
- .Replace("\u0027", "\u2019") // farfetch'd
+ string TempNick = PKX.UnSanitizeString(value)
.PadRight(value.Length + 1, '\0'); // Null Terminator
Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0x40);
}
@@ -292,21 +283,12 @@ namespace PKHeX
#region Block C
public override string HT_Name
{
- get
- {
- return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x78, 24))
- .Replace("\uE08F", "\u2640") // nidoran
- .Replace("\uE08E", "\u2642") // nidoran
- .Replace("\u2019", "\u0027"); // farfetch'd
- }
+ get { return PKX.SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x78, 24))); }
set
{
if (value.Length > 12)
value = value.Substring(0, 12); // Hard cap
- string TempNick = value // Replace Special Characters and add Terminator
- .Replace("\u2640", "\uE08F") // nidoran
- .Replace("\u2642", "\uE08E") // nidoran
- .Replace("\u0027", "\u2019") // farfetch'd
+ string TempNick = PKX.UnSanitizeString(value)
.PadRight(value.Length + 1, '\0'); // Null Terminator
Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0x78);
}
@@ -344,21 +326,12 @@ namespace PKHeX
#region Block D
public override string OT_Name
{
- get
- {
- return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0xB0, 24))
- .Replace("\uE08F", "\u2640") // Nidoran ♂
- .Replace("\uE08E", "\u2642") // Nidoran ♀
- .Replace("\u2019", "\u0027"); // farfetch'd
- }
+ get { return PKX.SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0xB0, 24))); }
set
{
if (value.Length > 12)
value = value.Substring(0, 12); // Hard cap
- string TempNick = value // Replace Special Characters and add Terminator
- .Replace("\u2640", "\uE08F") // Nidoran ♂
- .Replace("\u2642", "\uE08E") // Nidoran ♀
- .Replace("\u0027", "\u2019") // Farfetch'd
+ string TempNick = PKX.UnSanitizeString(value)
.PadRight(value.Length + 1, '\0'); // Null Terminator
Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0xB0);
}
diff --git a/PKHeX/PKM/PK7.cs b/PKHeX/PKM/PK7.cs
index edebeebd5..aa3b5ae27 100644
--- a/PKHeX/PKM/PK7.cs
+++ b/PKHeX/PKM/PK7.cs
@@ -217,21 +217,12 @@ namespace PKHeX
#region Block B
public override string Nickname
{
- get
- {
- return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x40, 24))
- .Replace("\uE08F", "\u2640") // nidoran
- .Replace("\uE08E", "\u2642") // nidoran
- .Replace("\u2019", "\u0027"); // farfetch'd
- }
+ get { return PKX.SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x40, 24))); }
set
{
if (value.Length > 12)
value = value.Substring(0, 12); // Hard cap
- string TempNick = value // Replace Special Characters and add Terminator
- .Replace("\u2640", "\uE08F") // nidoran
- .Replace("\u2642", "\uE08E") // nidoran
- .Replace("\u0027", "\u2019") // farfetch'd
+ string TempNick = PKX.UnSanitizeString(value)
.PadRight(value.Length + 1, '\0'); // Null Terminator
Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0x40);
}
@@ -300,21 +291,12 @@ namespace PKHeX
#region Block C
public override string HT_Name
{
- get
- {
- return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x78, 24))
- .Replace("\uE08F", "\u2640") // nidoran
- .Replace("\uE08E", "\u2642") // nidoran
- .Replace("\u2019", "\u0027"); // farfetch'd
- }
+ get { return PKX.SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x78, 24))); }
set
{
if (value.Length > 12)
value = value.Substring(0, 12); // Hard cap
- string TempNick = value // Replace Special Characters and add Terminator
- .Replace("\u2640", "\uE08F") // nidoran
- .Replace("\u2642", "\uE08E") // nidoran
- .Replace("\u0027", "\u2019") // farfetch'd
+ string TempNick = PKX.UnSanitizeString(value)
.PadRight(value.Length + 1, '\0'); // Null Terminator
Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0x78);
}
@@ -352,21 +334,12 @@ namespace PKHeX
#region Block D
public override string OT_Name
{
- get
- {
- return Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0xB0, 24))
- .Replace("\uE08F", "\u2640") // Nidoran ♂
- .Replace("\uE08E", "\u2642") // Nidoran ♀
- .Replace("\u2019", "\u0027"); // farfetch'd
- }
+ get { return PKX.SanitizeString(Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0xB0, 24))); }
set
{
if (value.Length > 12)
value = value.Substring(0, 12); // Hard cap
- string TempNick = value // Replace Special Characters and add Terminator
- .Replace("\u2640", "\uE08F") // Nidoran ♂
- .Replace("\u2642", "\uE08E") // Nidoran ♀
- .Replace("\u0027", "\u2019") // Farfetch'd
+ string TempNick = PKX.UnSanitizeString(value)
.PadRight(value.Length + 1, '\0'); // Null Terminator
Encoding.Unicode.GetBytes(TempNick).CopyTo(Data, 0xB0);
}
diff --git a/PKHeX/PKM/PKX.cs b/PKHeX/PKM/PKX.cs
index 006ee84ad..26d8e293e 100644
--- a/PKHeX/PKM/PKX.cs
+++ b/PKHeX/PKM/PKX.cs
@@ -1122,6 +1122,46 @@ namespace PKHeX
{ 1, 0, 1, 1, 1, 1 }, // Dragon
{ 1, 1, 1, 1, 1, 1 }, // Dark
};
+
+ ///
+ /// Converts full width to single width
+ ///
+ /// Input string to sanitize.
+ ///
+ public static string SanitizeString(string str)
+ {
+ if (str.Length == 0)
+ return str;
+ var s = str.Replace("\u2019", "\u0027"); // farfetch'd
+ s = s.Replace("\uE08F", "\u2640"); // ♀
+ s = s.Replace("\uE08E", "\u2642"); // ♂
+ return s;
+ }
+ ///
+ /// Converts full width to half width when appropriate
+ ///
+ /// Input string to set.
+ ///
+ ///
+ ///
+ public static string UnSanitizeString(string str, int species = -1, bool nicknamed = true)
+ {
+ var s = str.Replace("\u0027", "\u2019"); // farfetch'd
+
+ bool foreign = true;
+ if ((species == 029 || species == 032) && !nicknamed)
+ foreign = str[0] != 'N';
+ else if (nicknamed)
+ foreign = str.Select(c => c >> 12).Any(c => c != 0 && c != 0xE);
+
+ if (foreign)
+ return s;
+
+ // Convert back to half width
+ s = s.Replace("\u2640", "\uE08F"); // ♀
+ s = s.Replace("\u2642", "\uE08E"); // ♂
+ return s;
+ }
public static string TrimFromFFFF(string input)
{