forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIVersion.cs
More file actions
67 lines (56 loc) · 1.96 KB
/
Copy pathIVersion.cs
File metadata and controls
67 lines (56 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
namespace UnityEditor.Scripting.ScriptCompilation
{
internal interface IVersionTypeTraits
{
bool IsAllowedFirstCharacter(char c, bool strict = false);
bool IsAllowedLastCharacter(char c, bool strict = false);
bool IsAllowedCharacter(char c);
}
internal static class VersionTypeTraitsUtils
{
public static bool IsCharDigit(char c)
{
return (c >= '0' && c <= '9');
}
public static bool IsCharLetter(char c)
{
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z';
}
}
internal interface IVersion<TVersion> : IEquatable<TVersion>, IComparable<TVersion>, IComparable where TVersion : struct
{
bool IsInitialized { get; }
TVersion Parse(string version, bool strict = false);
IVersionTypeTraits GetVersionTypeTraits();
}
internal static class VersionUtils
{
public static string ConsumeVersionComponentFromString(string value, ref int cursor, Func<char, bool> isEnd)
{
int length = 0;
for (int i = cursor; i < value.Length; i++)
{
if (isEnd(value[i]))
break;
length++;
}
int newIndex = cursor;
cursor += length;
return value.Substring(newIndex, length);
}
public static bool TryConsumeIntVersionComponentFromString(string value, ref int cursor, Func<char, bool> isEnd, out int result, bool zeroIfEmpty = false)
{
var part = ConsumeVersionComponentFromString(value, ref cursor, isEnd);
if (zeroIfEmpty && part.Length == 0)
{
result = 0;
return true;
}
return int.TryParse(part, out result);
}
}
}