Procházet zdrojové kódy

fix StringTools.fastCodeAt documentation (closes #2950)

Simon Krajewski před 11 roky
rodič
revize
7c26b57297
2 změnil soubory, kde provedl 12 přidání a 4 odebrání
  1. 8 4
      std/StringTools.hx
  2. 4 0
      tests/unit/unitstd/StringTools.unit.hx

+ 8 - 4
std/StringTools.hx

@@ -346,11 +346,15 @@ class StringTools {
 	}
 
 	/**
-		Returns the character code at position `index` of String `s`.
+		Returns the character code at position `index` of String `s`, or an
+		end-of-file indicator at if `position` equals `s.length`.
 
-		This method is faster than String.charCodeAt() on most platforms.
-		However, unlike String.charCodeAt(), the result is unspecified if
-		`index` is negative or exceeds `s.length`.
+		This method is faster than String.charCodeAt() on some platforms, but
+		the result is unspecified if `index` is negative or greater than
+		`s.length`.
+
+		End of file status can be checked by calling `StringTools.isEof` with
+		the returned value as argument.
 
 		This operation is not guaranteed to work if `s` contains the \0
 		character.

+ 4 - 0
tests/unit/unitstd/StringTools.unit.hx

@@ -122,6 +122,10 @@ var str = "abc";
 StringTools.fastCodeAt(str, 0) == "a".code;
 StringTools.fastCodeAt(str, 1) == "b".code;
 StringTools.fastCodeAt(str, 2) == "c".code;
+StringTools.isEof(StringTools.fastCodeAt(str, 0)) == false;
+StringTools.isEof(StringTools.fastCodeAt(str, 1)) == false;
+StringTools.isEof(StringTools.fastCodeAt(str, 2)) == false;
+StringTools.isEof(StringTools.fastCodeAt(str, 3)) == true;
 StringTools.fastCodeAt(String.fromCharCode(128), 0) == 128;
 StringTools.fastCodeAt(String.fromCharCode(255), 0) == 255;
 StringTools.isEof(StringTools.fastCodeAt(str, 2)) == false;