66 lines
2.6 KiB
C#
66 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace CodeGenerator {
|
|
public static class StrExt {
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static string ParseFName(this string str) {
|
|
str = str.Replace("*", "");
|
|
return str;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static string ParseFType(this string str) {
|
|
return str switch {
|
|
"char" => typeof(char).AssemblyQualifiedName,
|
|
"short" => typeof(short).AssemblyQualifiedName,
|
|
"int" => typeof(int).AssemblyQualifiedName,
|
|
"float" => typeof(float).AssemblyQualifiedName,
|
|
"double" => typeof(double).AssemblyQualifiedName,
|
|
"string" => typeof(string).AssemblyQualifiedName,
|
|
"void" => typeof(object).AssemblyQualifiedName,
|
|
"ushort" => typeof(ushort).AssemblyQualifiedName,
|
|
"uchar" => typeof(byte).AssemblyQualifiedName,
|
|
"int64_t" => typeof(long).AssemblyQualifiedName,
|
|
"int8_t" => typeof(sbyte).AssemblyQualifiedName,
|
|
"uint64_t" => typeof(ulong).AssemblyQualifiedName,
|
|
_ => str
|
|
};
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static int? ParseFSize(this string str) {
|
|
return str switch {
|
|
"char" => sizeof(sbyte),
|
|
"short" => sizeof(short),
|
|
"int" => sizeof(int),
|
|
"float" => sizeof(float),
|
|
"double" => sizeof(double),
|
|
"ushort" => sizeof(ushort),
|
|
"uchar" => sizeof(byte),
|
|
"int64_t" => sizeof(long),
|
|
"int8_t" => sizeof(sbyte),
|
|
"uint64_t" => sizeof(ulong),
|
|
_ => null
|
|
};
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static List<int> GetArrayDimensions(this string name) {
|
|
var dimensions = new List<int>();
|
|
int startIndex = 0;
|
|
// Get all array dimensions
|
|
while ((startIndex = name.IndexOf('[', startIndex)) != -1) {
|
|
int endIndex = name.IndexOf(']', startIndex);
|
|
string sizeStr = name.Substring(startIndex + 1, endIndex - startIndex - 1);
|
|
if (int.TryParse(sizeStr, out int size)) {
|
|
dimensions.Add(size);
|
|
}
|
|
startIndex = endIndex + 1;
|
|
}
|
|
|
|
return dimensions;
|
|
}
|
|
|
|
}
|
|
} |