Skip to content

Commit a29aadd

Browse files
author
Daniel Lemire
committed
adding documentation.
1 parent 48e9db6 commit a29aadd

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

src/UTF8.cs

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,40 @@ namespace SimdUnicode
1010
public static class UTF8
1111
{
1212

13+
// Returns &inputBuffer[inputLength] if the input buffer is valid.
14+
/// <summary>
15+
/// Given an input buffer <paramref name="pInputBuffer"/> of byte length <paramref name="inputLength"/>,
16+
/// returns a pointer to where the first invalid data appears in <paramref name="pInputBuffer"/>.
17+
/// The parameter <paramref name="Utf16CodeUnitCountAdjustment"/> is set according to the content of the valid UTF-8 characters encountered, counting -1 for each 2-byte character, -2 for each 3-byte character, and -3 for each 4-byte character.
18+
/// The parameter <paramref name="ScalarCodeUnitCountAdjustment"/> is set according to the content of the valid UTF-8 characters encountered, counting -1 for each 4-byte character.
19+
/// </summary>
20+
/// <remarks>
21+
/// Returns a pointer to the end of <paramref name="pInputBuffer"/> if the buffer is well-formed.
22+
/// </remarks>
23+
public unsafe static byte* GetPointerToFirstInvalidByte(byte* pInputBuffer, int inputLength, out int Utf16CodeUnitCountAdjustment, out int ScalarCodeUnitCountAdjustment)
24+
{
25+
26+
if (AdvSimd.Arm64.IsSupported)
27+
{
28+
return GetPointerToFirstInvalidByteArm64(pInputBuffer, inputLength, out Utf16CodeUnitCountAdjustment, out ScalarCodeUnitCountAdjustment);
29+
}
30+
if (Avx2.IsSupported)
31+
{
32+
return GetPointerToFirstInvalidByteAvx2(pInputBuffer, inputLength, out Utf16CodeUnitCountAdjustment, out ScalarCodeUnitCountAdjustment);
33+
}
34+
/*if (Vector512.IsHardwareAccelerated && Avx512Vbmi2.IsSupported)
35+
{
36+
return GetPointerToFirstInvalidByteAvx512(pInputBuffer, inputLength);
37+
}*/
38+
// if (Ssse3.IsSupported)
39+
// {
40+
// return GetPointerToFirstInvalidByteSse(pInputBuffer, inputLength);
41+
// }
42+
// return GetPointerToFirstInvalidByteScalar(pInputBuffer, inputLength);
43+
44+
return GetPointerToFirstInvalidByteScalar(pInputBuffer, inputLength, out Utf16CodeUnitCountAdjustment, out ScalarCodeUnitCountAdjustment);
45+
46+
}
1347
// prevents double counting in case there is a toolong error on the edge
1448
public static (int utfAdjust, int scalarAdjust) GetFinalScalarUtfAdjustments(byte headerByte)
1549
{
@@ -885,30 +919,6 @@ public unsafe static (int utfadjust, int scalaradjust) calculateErrorPathadjust(
885919
scalarCountAdjustment = TempScalarCountAdjustment + TailScalarCodeUnitCountAdjustment;
886920
return pInputBuffer + inputLength;
887921
}
888-
public unsafe static byte* GetPointerToFirstInvalidByte(byte* pInputBuffer, int inputLength, out int Utf16CodeUnitCountAdjustment, out int ScalarCodeUnitCountAdjustment)
889-
{
890-
891-
if (AdvSimd.Arm64.IsSupported)
892-
{
893-
return GetPointerToFirstInvalidByteArm64(pInputBuffer, inputLength, out Utf16CodeUnitCountAdjustment, out ScalarCodeUnitCountAdjustment);
894-
}
895-
if (Avx2.IsSupported)
896-
{
897-
return GetPointerToFirstInvalidByteAvx2(pInputBuffer, inputLength, out Utf16CodeUnitCountAdjustment, out ScalarCodeUnitCountAdjustment);
898-
}
899-
/*if (Vector512.IsHardwareAccelerated && Avx512Vbmi2.IsSupported)
900-
{
901-
return GetPointerToFirstInvalidByteAvx512(pInputBuffer, inputLength);
902-
}*/
903-
// if (Ssse3.IsSupported)
904-
// {
905-
// return GetPointerToFirstInvalidByteSse(pInputBuffer, inputLength);
906-
// }
907-
// return GetPointerToFirstInvalidByteScalar(pInputBuffer, inputLength);
908-
909-
return GetPointerToFirstInvalidByteScalar(pInputBuffer, inputLength, out Utf16CodeUnitCountAdjustment, out ScalarCodeUnitCountAdjustment);
910-
911-
}
912922

913923
}
914924
}

0 commit comments

Comments
 (0)