Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Jul 31, 2023
1 parent ce5678f commit e75968e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
37 changes: 2 additions & 35 deletions Jint/Native/RegExp/RegExpPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,11 +942,7 @@ private static JsValue RegExpBuiltinExec(JsRegExp R, string s)

var e = match.Index + match.Length;

// .NET regexes doesn't returns code point indices
//if (fullUnicode)
//{
// e = GetStringIndex(s, e);
//}
// NOTE: Even in Unicode mode, we don't need to translate indices as .NET regexes always return code unit indices.

if (global || sticky)
{
Expand All @@ -956,35 +952,6 @@ private static JsValue RegExpBuiltinExec(JsRegExp R, string s)
return CreateReturnValueArray(R.Engine, matcher, match, s, fullUnicode, hasIndices);
}

/// <summary>
/// https://tc39.es/ecma262/#sec-getstringindex
/// </summary>
//private static int GetStringIndex(string s, int codePointIndex)
//{
// if (s.Length == 0)
// {
// return 0;
// }

// var len = s.Length;
// var codeUnitCount = 0;
// var codePointCount = 0;

// while (codeUnitCount < len)
// {
// if (codePointCount == codePointIndex)
// {
// return codeUnitCount;
// }

// var isSurrogatePair = char.IsSurrogatePair(s, codeUnitCount);
// codeUnitCount += isSurrogatePair ? 2 : 1;
// codePointCount += 1;
// }

// return len;
//}

private static JsArray CreateReturnValueArray(
Engine engine,
Regex regex,
Expand Down Expand Up @@ -1113,7 +1080,7 @@ private static JsValue GetMatchIndexPair(Engine engine, string s, JsNumber[] mat
{
try
{
var bytes = Shims.BytesFromHexString(groupNameFromNumber.AsSpan(encodedGroupNamePrefix.Length));
var bytes = groupNameFromNumber.AsSpan(encodedGroupNamePrefix.Length).BytesFromHexString();
groupNameFromNumber = Encoding.UTF8.GetString(bytes);
}
catch { /* intentional no-op */ }
Expand Down
2 changes: 1 addition & 1 deletion Jint/Shims.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Jint;

internal static class Shims
{
public static byte[] BytesFromHexString(ReadOnlySpan<char> value)
public static byte[] BytesFromHexString(this ReadOnlySpan<char> value)
{
#if NET6_0_OR_GREATER
return Convert.FromHexString(value);
Expand Down

0 comments on commit e75968e

Please sign in to comment.