1
Fork 0
mirror of https://github.com/xivdev/EXDSchema.git synced 2025-06-06 16:17:46 +00:00
EXDSchema/SchemaConverter/Util.cs
2023-09-18 19:55:35 -04:00

62 lines
No EOL
1.6 KiB
C#

using Lumina.Data.Structs.Excel;
namespace SchemaConverter;
public static class Util
{
public static string FirstCharToUpper(this string input) =>
input switch
{
null => throw new ArgumentNullException(nameof(input)),
"" => throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input)),
_ => string.Concat(input[0].ToString().ToUpper(), input.AsSpan(1))
};
public static string StripDefinitionName(string str)
{
if( string.IsNullOrWhiteSpace(str))
return null;
str = str
.Replace("<", "")
.Replace(">", "")
.Replace("{", "")
.Replace("}", "")
.Replace("(", "")
.Replace(")", "")
.Replace("/", "")
.Replace("[", "")
.Replace("]", "")
.Replace(" ", "")
.Replace("'", "")
.Replace("-", "")
.Replace("%", "Pct");
if(char.IsDigit(str[0]))
{
var index = str[0] - '0';
var words = new[] {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
str = $"{words[index]}{str[1..]}";
}
return str;
}
public static int GetBitOffset(int offset, ExcelColumnDataType dataType)
{
var bitOffset = offset * 8;
return dataType switch
{
ExcelColumnDataType.PackedBool0 => bitOffset + 0,
ExcelColumnDataType.PackedBool1 => bitOffset + 1,
ExcelColumnDataType.PackedBool2 => bitOffset + 2,
ExcelColumnDataType.PackedBool3 => bitOffset + 3,
ExcelColumnDataType.PackedBool4 => bitOffset + 4,
ExcelColumnDataType.PackedBool5 => bitOffset + 5,
ExcelColumnDataType.PackedBool6 => bitOffset + 6,
ExcelColumnDataType.PackedBool7 => bitOffset + 7,
_ => bitOffset,
};
}
}