51 lines
1.1 KiB
Haxe
51 lines
1.1 KiB
Haxe
package lib.exporter;
|
|
|
|
import lua.TableTools;
|
|
import lua.NativeStringTools;
|
|
|
|
class Request {
|
|
public final id:String;
|
|
public final field:String;
|
|
public final index:Null<Int>;
|
|
public final operation:Operation;
|
|
|
|
public function new(id:String, field:String, index:Null<Int>, operation:Operation) {
|
|
this.id = id;
|
|
this.field = field;
|
|
this.index = index;
|
|
this.operation = operation;
|
|
}
|
|
|
|
/**
|
|
Example:
|
|
"myfield[2]@myid"
|
|
"myfield@myid"
|
|
**/
|
|
public static function fromString(locator:String):Request {
|
|
if (StringTools.contains(locator, "[")) {
|
|
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)%[([%d]+)%]@(%a+)")());
|
|
|
|
var field = f[1];
|
|
var index = Std.parseInt(f[2]);
|
|
var id = f[3];
|
|
|
|
return new Request(id, field, index, Get);
|
|
} else {
|
|
var f = TableTools.pack(NativeStringTools.gmatch(locator, "(%a+)@(%a+)")());
|
|
|
|
var field = f[1];
|
|
var id = f[2];
|
|
|
|
return new Request(id, field, null, Get);
|
|
}
|
|
}
|
|
|
|
public function toString() {
|
|
if (index == null) {
|
|
return field + "@" + id;
|
|
} else {
|
|
return field + "[" + index + "]@" + id;
|
|
}
|
|
}
|
|
}
|