Skip to content

Commit 121548c

Browse files
committed
Fixed Namespace Length
1 parent 5013e86 commit 121548c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

FanScript/Compiler/Namespace.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ public Namespace(ReadOnlySpan<char> value)
2323
/// Only use with validated values!
2424
/// </summary>
2525
/// <param name="value"></param>
26-
private Namespace(string value)
26+
private Namespace(string value, int length)
2727
{
2828
Value = value;
29+
Length = length;
2930
}
3031

3132
public Namespace Slice(int index)
@@ -45,11 +46,16 @@ public Namespace Slice(int index, int length)
4546

4647
val = val.Slice(startIndex + 1);
4748

48-
int endIndex = val.IndexOf('/', length - 1);
49+
int endIndex;
50+
if (length == 1)
51+
endIndex = val.Length;
52+
else
53+
endIndex = val.IndexOf('/', length - 1);
54+
4955
if (endIndex == -1)
5056
throw new ArgumentOutOfRangeException(nameof(index));
5157

52-
return new Namespace(new string(val.Slice(0, endIndex)));
58+
return new Namespace(new string(val.Slice(0, endIndex)), length);
5359
}
5460

5561
public Namespace CapitalizeFirst()
@@ -59,13 +65,13 @@ public Namespace CapitalizeFirst()
5965
for (int i = 0; i < split.Length; i++)
6066
split[i] = split[i].ToUpperFirst();
6167

62-
return new Namespace(string.Join('/', split));
68+
return new Namespace(string.Join('/', split), Length);
6369
}
6470

6571
public static Namespace operator +(Namespace a, string b)
66-
=> new Namespace(a.Value + "/" + b.ToLowerInvariant());
72+
=> new Namespace(a.Value + "/" + b.ToLowerInvariant(), a.Length + 1 + b.AsSpan().Count('/'));
6773
public static Namespace operator +(Namespace a, Namespace b)
68-
=> new Namespace(a.Value + "/" + b);
74+
=> new Namespace(a.Value + "/" + b, a.Length + b.Length);
6975

7076
public static bool operator ==(Namespace a, Namespace b)
7177
=> a.Value == b.Value;

0 commit comments

Comments
 (0)