Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions Microsoft.Toolkit.Uwp.UI/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ public static Vector2 ToVector2(this string text)
if (text.Length > 0)
{
// The format <x> or <x, y> is supported
if (text.Length >= 2 &&
text[0] == '>' &&
text[text.Length - 1] == '>')
{
text = text.Substring(1, text.Length - 2);
}
text = Unbracket(text);

// Skip allocations when only a component is used
if (text.IndexOf(',') == -1)
Expand Down Expand Up @@ -78,12 +73,7 @@ public static Vector3 ToVector3(this string text)
{
if (text.Length > 0)
{
if (text.Length >= 2 &&
text[0] == '>' &&
text[text.Length - 1] == '>')
{
text = text.Substring(1, text.Length - 2);
}
text = Unbracket(text);

if (text.IndexOf(',') == -1)
{
Expand Down Expand Up @@ -127,12 +117,7 @@ public static Vector4 ToVector4(this string text)
{
if (text.Length > 0)
{
if (text.Length >= 2 &&
text[0] == '>' &&
text[text.Length - 1] == '>')
{
text = text.Substring(1, text.Length - 2);
}
text = Unbracket(text);

if (text.IndexOf(',') == -1)
{
Expand Down Expand Up @@ -176,12 +161,7 @@ public static Quaternion ToQuaternion(this string text)
{
if (text.Length > 0)
{
if (text.Length >= 2 &&
text[0] == '>' &&
text[text.Length - 1] == '>')
{
text = text.Substring(1, text.Length - 2);
}
text = Unbracket(text);

string[] values = text.Split(',');

Expand All @@ -201,5 +181,17 @@ public static Quaternion ToQuaternion(this string text)

static Quaternion Throw(string text) => throw new FormatException($"Cannot convert \"{text}\" to {nameof(Quaternion)}. Use the format \"float, float, float, float\"");
}

private static string Unbracket(string text)
{
if (text.Length >= 2 &&
text[0] == '<' &&
text[text.Length - 1] == '>')
{
text = text.Substring(1, text.Length - 2);
}

return text;
}
}
}