Browse Source

[cs] fix String.lastIndexOf for latest spec

Dan Korostelev 6 years ago
parent
commit
4dee0d7a47
1 changed files with 8 additions and 0 deletions
  1. 8 0
      std/cs/internal/StringExt.hx

+ 8 - 0
std/cs/internal/StringExt.hx

@@ -62,6 +62,14 @@ private typedef NativeString = cs.system.String;
 		//TestBaseTypes.hx@133 fix
 		//TestBaseTypes.hx@133 fix
 		if (startIndex != null)
 		if (startIndex != null)
 		{
 		{
+			// if the number of letters between start index and the length of the string
+			// is less than the length of a searched substring - shift start index to the
+			// left by the difference to avoid OOB access later and save some work
+			var d = me.Length - sIndex - str.Length;
+			if (d < 0) {
+				sIndex += d;
+			}
+
 			var i = sIndex + 1;
 			var i = sIndex + 1;
 			while (i --> 0)
 			while (i --> 0)
 			{
 			{