mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Rework range check
- Loops through all entries - Bumped amount of cols up to 8 for future proofing - Use Ordinal search - Actually parse ranges and check if the RowId is allowed
This commit is contained in:
parent
3f037e5d20
commit
d8555f207e
1 changed files with 56 additions and 31 deletions
|
|
@ -1630,37 +1630,56 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator
|
||||||
|
|
||||||
var isNoun = false;
|
var isNoun = false;
|
||||||
|
|
||||||
Span<int> cols = stackalloc int[2];
|
var colIndex = 0;
|
||||||
|
Span<int> cols = stackalloc int[8];
|
||||||
cols.Clear();
|
cols.Clear();
|
||||||
|
var isInRange = false;
|
||||||
|
|
||||||
if (ranges.StartsWith("noun"))
|
while (!string.IsNullOrWhiteSpace(ranges))
|
||||||
{
|
{
|
||||||
isNoun = true;
|
// find the end of the current entry
|
||||||
}
|
var entryEnd = ranges.IndexOf(',');
|
||||||
else if (ranges.StartsWith("col"))
|
if (entryEnd == -1)
|
||||||
{
|
entryEnd = ranges.Length;
|
||||||
var i = 0;
|
|
||||||
while (i < cols.Length && ranges.StartsWith("col-", StringComparison.Ordinal))
|
if (ranges.StartsWith("noun", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
// find the end of the current "col-#" token
|
isNoun = true;
|
||||||
var colRangeEnd = ranges.IndexOf(',');
|
|
||||||
if (colRangeEnd == -1)
|
|
||||||
colRangeEnd = ranges.Length;
|
|
||||||
|
|
||||||
// parse the column index
|
|
||||||
cols[i++] = int.Parse(ranges.AsSpan(4, colRangeEnd - 4));
|
|
||||||
|
|
||||||
// if it's the end of the string, we're done
|
|
||||||
if (colRangeEnd == ranges.Length)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// move to the next entry
|
|
||||||
ranges = ranges[(colRangeEnd + 1)..].TrimStart();
|
|
||||||
}
|
}
|
||||||
|
else if (ranges.StartsWith("col", StringComparison.Ordinal) && colIndex < cols.Length)
|
||||||
|
{
|
||||||
|
cols[colIndex++] = int.Parse(ranges.AsSpan(4, entryEnd - 4));
|
||||||
|
}
|
||||||
|
else if (ranges.StartsWith("tail", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
// currently not supported, since there are no known uses
|
||||||
|
context.Builder.Append(payload);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var dash = ranges.IndexOf('-');
|
||||||
|
if (dash == -1)
|
||||||
|
{
|
||||||
|
isInRange |= int.Parse(ranges.AsSpan(0, entryEnd)) == rowId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isInRange |= rowId >= int.Parse(ranges.AsSpan(0, dash))
|
||||||
|
&& rowId <= int.Parse(ranges.AsSpan(dash + 1, entryEnd - dash - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if it's the end of the string, we're done
|
||||||
|
if (entryEnd == ranges.Length)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// else, move to the next entry
|
||||||
|
ranges = ranges[(entryEnd + 1)..].TrimStart();
|
||||||
}
|
}
|
||||||
else if (ranges.StartsWith("tail"))
|
|
||||||
|
if (!isInRange)
|
||||||
{
|
{
|
||||||
// couldn't find any, so we don't handle them :p
|
|
||||||
context.Builder.Append(payload);
|
context.Builder.Append(payload);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -1678,15 +1697,21 @@ internal class SeStringEvaluator : IServiceType, ISeStringEvaluator
|
||||||
}
|
}
|
||||||
else if (this.dataManager.GetExcelSheet<RawRow>(context.Language, sheetName).TryGetRow(rowId, out var row))
|
else if (this.dataManager.GetExcelSheet<RawRow>(context.Language, sheetName).TryGetRow(rowId, out var row))
|
||||||
{
|
{
|
||||||
// the game uses a priority system for columns here.
|
if (colIndex == 0)
|
||||||
// if the first column is empty (for example MainCommand.Alias), then the next one is used (MainCommand.Command)
|
|
||||||
for (var i = 0; i < cols.Length; i++)
|
|
||||||
{
|
{
|
||||||
var text = row.ReadStringColumn(cols[i]);
|
context.Builder.Append(row.ReadStringColumn(0));
|
||||||
if (!text.IsEmpty)
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var i = 0; i < colIndex; i++)
|
||||||
{
|
{
|
||||||
context.Builder.Append(text);
|
var text = row.ReadStringColumn(cols[i]);
|
||||||
break;
|
if (!text.IsEmpty)
|
||||||
|
{
|
||||||
|
context.Builder.Append(text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue