Browse Source

[std] fix String.lastIndexOf documentation

Also fix the related test + eval implementation.
Simon Krajewski 6 years ago
parent
commit
b81ca807c6
3 changed files with 5 additions and 4 deletions
  1. 1 1
      src/macro/eval/evalStdLib.ml
  2. 2 2
      std/String.hx
  3. 2 1
      tests/unit/src/unitstd/String.unit.hx

+ 1 - 1
src/macro/eval/evalStdLib.ml

@@ -2085,7 +2085,7 @@ module StdString = struct
 				vint (max 0 (min i this.slength))
 			end else begin
 				let i = default_int startIndex (this.slength - str.slength) in
-				let i = if i < 0 then raise Not_found else if i >= this.slength then this.slength - 1 else i in
+				let i = if i < 0 then raise Not_found else if i >= this.slength - str.slength then this.slength - str.slength else i in
 				let b = get_offset this i in
 				let offset,_,_ = find_substring this str true i b in
 				vint offset

+ 2 - 2
std/String.hx

@@ -95,8 +95,8 @@ extern class String {
 		String.
 
 		If `startIndex` is given, the search is performed within the substring
-		of `this` String from 0 to `startIndex`. Otherwise the search is
-		performed within `this` String. In either case, the returned position
+		of `this` String from 0 to `startIndex + str.length`. Otherwise the search
+		is performed within `this` String. In either case, the returned position
 		is relative to the beginning of `this` String.
 
 		If `str` cannot be found, -1 is returned.

+ 2 - 1
tests/unit/src/unitstd/String.unit.hx

@@ -83,7 +83,8 @@ s.lastIndexOf("foo") == 6;
 s.lastIndexOf("foofoo") == 3;
 s.lastIndexOf("f") == 6;
 s.lastIndexOf("barb") == 9;
-s.lastIndexOf("barb", 12) == -1;
+s.lastIndexOf("barb", 12) == 9;
+s.lastIndexOf("barb", 13) == 9;
 s.lastIndexOf("z") == -1;
 //s.lastIndexOf(null) == -1;
 //s.lastIndexOf(null, 1) == -1;