aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Horizon/Sdk/Ngc/Detail/MatchState.cs
blob: 2a701e05bfc49797c2af19503365c5c9601e4d86 (plain) (blame)
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
using System;

namespace Ryujinx.Horizon.Sdk.Ngc.Detail
{
    readonly ref struct MatchState
    {
        public readonly Span<byte> OriginalText;
        public readonly Span<byte> ConvertedText;
        public readonly ReadOnlySpan<sbyte> DeltaTable;
        public readonly ref int MaskedCount;
        public readonly MaskMode MaskMode;
        public readonly Sbv NoSeparatorMap;
        public readonly AhoCorasick DelimitedWordsTrie;

        public MatchState(
            Span<byte> originalText,
            Span<byte> convertedText,
            ReadOnlySpan<sbyte> deltaTable,
            ref int maskedCount,
            MaskMode maskMode,
            Sbv noSeparatorMap = null,
            AhoCorasick delimitedWordsTrie = null)
        {
            OriginalText = originalText;
            ConvertedText = convertedText;
            DeltaTable = deltaTable;
            MaskedCount = ref maskedCount;
            MaskMode = maskMode;
            NoSeparatorMap = noSeparatorMap;
            DelimitedWordsTrie = delimitedWordsTrie;
        }

        public readonly (int, int) GetOriginalRange(int convertedStartOffest, int convertedEndOffset)
        {
            int originalStartOffset = 0;
            int originalEndOffset = 0;

            for (int index = 0; index < convertedEndOffset; index++)
            {
                int byteLength = Math.Abs(DeltaTable[index]);

                originalStartOffset += index < convertedStartOffest ? byteLength : 0;
                originalEndOffset += byteLength;
            }

            return (originalStartOffset, originalEndOffset);
        }
    }
}