Skip to content

Commit 9622901

Browse files
committed
Haxe 4.1 compat
1 parent 0769756 commit 9622901

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Includes the following validators:
1717

1818
## Minimum Requirements
1919

20-
- Haxe 4.2
20+
- Haxe 4.1
2121
- OpenFL 9.2
2222

2323
## Installation

src/feathers/validators/DateValidator.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ class DateValidator extends Validator {
858858
if (_yearSource == value)
859859
return _yearSource;
860860

861-
if (value is String) {
861+
if ((value is String)) {
862862
var message:String = ValidatorStringUtil.substitute(YS_ATTRIBUTE_ERROR, value);
863863
throw new Error(message);
864864
}

src/feathers/validators/utils/ValidatorStringUtil.hx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,22 @@ class ValidatorStringUtil {
6565
@return New string with all of the `{n}` tokens
6666
replaced with the respective arguments specified.
6767
**/
68-
public static function substitute(str:String, ...rest):String {
68+
public static function substitute(str:String, #if (haxe_ver >= 4.2)...rest #else ?value1:String, ?value2:String, ?value3:String #end):String {
6969
if (str == null) {
7070
return '';
7171
}
72-
72+
#if (haxe_ver < 4.2)
73+
var rest:Array<String> = [];
74+
if (value1 != null) {
75+
rest.push(value1);
76+
if (value2 != null) {
77+
rest.push(value2);
78+
if (value3 != null) {
79+
rest.push(value3);
80+
}
81+
}
82+
}
83+
#end
7384
// Replace all of the parameters in the msg string.
7485
var len:UInt = rest.length;
7586
var args:Array<String>;
@@ -79,11 +90,9 @@ class ValidatorStringUtil {
7990
} else {
8091
args = rest;
8192
}
82-
8393
for (i in 0...len) {
8494
str = new EReg("\\{" + i + "\\}", "g").replace(str, args[i]);
8595
}
86-
8796
return str;
8897
}
8998
}

0 commit comments

Comments
 (0)