@@ -9,22 +9,21 @@ namespace SimdUnicode
9
9
public static class UTF8
10
10
{
11
11
12
- public unsafe static byte * RewindAndValidateWithErrors ( int offset , byte * buf , int len , ref int utf16CodeUnitCountAdjustment , ref int scalarCountAdjustment )
12
+ public unsafe static byte * RewindAndValidateWithErrors ( int howFarBack , byte * buf , int len , ref int utf16CodeUnitCountAdjustment , ref int scalarCountAdjustment )
13
13
{
14
14
15
15
int TempUtf16CodeUnitCountAdjustment = 0 ;
16
16
int TempScalarCountAdjustment = 0 ;
17
17
18
- int howFarBack = offset ;
19
18
int extraLen = 0 ;
20
19
bool foundLeadingBytes = false ;
21
- for ( int i = 0 ; i <= howFarBack ; i ++ )
20
+
21
+ for ( int i = 0 ; i < howFarBack ; i ++ )
22
22
{
23
23
byte candidateByte = buf [ 0 - i ] ;
24
24
foundLeadingBytes = ( candidateByte & 0b11000000 ) != 0b10000000 ;
25
25
if ( foundLeadingBytes )
26
26
{
27
-
28
27
// adjustment to avoid double counting
29
28
if ( ( candidateByte & 0b11100000 ) == 0b11000000 ) // Start of a 2-byte sequence
30
29
{
@@ -39,7 +38,17 @@ public static class UTF8
39
38
TempUtf16CodeUnitCountAdjustment += 2 ;
40
39
TempScalarCountAdjustment += 1 ;
41
40
}
42
-
41
+ break ;
42
+ }
43
+ }
44
+
45
+
46
+ for ( int i = 0 ; i <= howFarBack ; i ++ )
47
+ {
48
+ byte candidateByte = buf [ 0 - i ] ;
49
+ foundLeadingBytes = ( candidateByte & 0b11000000 ) != 0b10000000 ;
50
+ if ( foundLeadingBytes )
51
+ {
43
52
buf -= i ;
44
53
extraLen = i ;
45
54
break ;
@@ -65,6 +74,9 @@ public static class UTF8
65
74
utf16CodeUnitCountAdjustment += TailUtf16CodeUnitCountAdjustment ;
66
75
scalarCountAdjustment += TailScalarCountAdjustment ;
67
76
77
+ Console . WriteLine ( "utf16count after rewint:" + utf16CodeUnitCountAdjustment ) ;
78
+ Console . WriteLine ( "scalarcount after rewint:" + scalarCountAdjustment ) ;
79
+
68
80
return invalidBytePointer ;
69
81
}
70
82
@@ -651,6 +663,8 @@ public unsafe static void AdjustForSkippedBytes(byte* pInputBuffer,// int skippe
651
663
652
664
utf16CodeUnitCountAdjustment = TempUtf16CodeUnitCountAdjustment + TailUtf16CodeUnitCountAdjustment ;
653
665
scalarCountAdjustment = TempScalarCountAdjustment + TailScalarCodeUnitCountAdjustment ;
666
+
667
+
654
668
655
669
return invalidBytePointer ;
656
670
0 commit comments