Skip to content

Commit 52cb1bf

Browse files
committed
apply the same fix for other methods
1 parent 4da9ed2 commit 52cb1bf

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/StringExtensions.cs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ public static Vector2 ToVector2(this string text)
2929
if (text.Length > 0)
3030
{
3131
// The format <x> or <x, y> is supported
32-
if (text.Length >= 2 &&
33-
text[0] == '>' &&
34-
text[text.Length - 1] == '>')
35-
{
36-
text = text.Substring(1, text.Length - 2);
37-
}
32+
text = Unbracket(text);
3833

3934
// Skip allocations when only a component is used
4035
if (text.IndexOf(',') == -1)
@@ -78,12 +73,7 @@ public static Vector3 ToVector3(this string text)
7873
{
7974
if (text.Length > 0)
8075
{
81-
if (text.Length >= 2 &&
82-
text[0] == '<' &&
83-
text[text.Length - 1] == '>')
84-
{
85-
text = text.Substring(1, text.Length - 2);
86-
}
76+
text = Unbracket(text);
8777

8878
if (text.IndexOf(',') == -1)
8979
{
@@ -127,12 +117,7 @@ public static Vector4 ToVector4(this string text)
127117
{
128118
if (text.Length > 0)
129119
{
130-
if (text.Length >= 2 &&
131-
text[0] == '>' &&
132-
text[text.Length - 1] == '>')
133-
{
134-
text = text.Substring(1, text.Length - 2);
135-
}
120+
text = Unbracket(text);
136121

137122
if (text.IndexOf(',') == -1)
138123
{
@@ -176,12 +161,7 @@ public static Quaternion ToQuaternion(this string text)
176161
{
177162
if (text.Length > 0)
178163
{
179-
if (text.Length >= 2 &&
180-
text[0] == '>' &&
181-
text[text.Length - 1] == '>')
182-
{
183-
text = text.Substring(1, text.Length - 2);
184-
}
164+
text = Unbracket(text);
185165

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

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

202182
static Quaternion Throw(string text) => throw new FormatException($"Cannot convert \"{text}\" to {nameof(Quaternion)}. Use the format \"float, float, float, float\"");
203183
}
184+
185+
private static string Unbracket(string text)
186+
{
187+
if (text.Length >= 2 &&
188+
text[0] == '<' &&
189+
text[text.Length - 1] == '>')
190+
{
191+
text = text.Substring(1, text.Length - 2);
192+
}
193+
194+
return text;
195+
}
204196
}
205197
}

0 commit comments

Comments
 (0)