Prelude.substr allow negative indices
This commit is contained in:
@@ -111,6 +111,7 @@ class Kiss {
|
|||||||
"zipThrow" => Symbol("Prelude.zipThrow"),
|
"zipThrow" => Symbol("Prelude.zipThrow"),
|
||||||
"joinPath" => Symbol("Prelude.joinPath"),
|
"joinPath" => Symbol("Prelude.joinPath"),
|
||||||
"readDirectory" => Symbol("Prelude.readDirectory"),
|
"readDirectory" => Symbol("Prelude.readDirectory"),
|
||||||
|
"substr" => Symbol("Prelude.substr")
|
||||||
],
|
],
|
||||||
fieldList: [],
|
fieldList: [],
|
||||||
fieldDict: new Map(),
|
fieldDict: new Map(),
|
||||||
|
@@ -632,6 +632,16 @@ class Prelude {
|
|||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
public static function substr(str:String, startIdx:Int, ?endIdx:Int) {
|
||||||
|
function negIdx(idx) {
|
||||||
|
return if (idx < 0) str.length + idx else idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endIdx == null) endIdx = str.length;
|
||||||
|
|
||||||
|
return str.substr(negIdx(startIdx), negIdx(endIdx));
|
||||||
|
}
|
||||||
|
|
||||||
public static var newLine = "\n";
|
public static var newLine = "\n";
|
||||||
public static var backSlash = "\\";
|
public static var backSlash = "\\";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user