|
| 1 | +#include-once |
| 2 | +;https://github.com/sebastianbergmann/exporter/blob/2.0/src/Exporter.php |
| 3 | + |
| 4 | +Func Au3ExporterExporter_Export($value, $indentation = 0) |
| 5 | + Return Au3ExporterExporter_RecursiveExport($value, $indentation) |
| 6 | +EndFunc |
| 7 | + |
| 8 | +Func Au3ExporterExporter_RecursiveExport(ByRef $value, $indentation, $processed = Null) |
| 9 | + If $value == Null Then Return "null" |
| 10 | + |
| 11 | + If $value == True Then Return "true" |
| 12 | + |
| 13 | + If $value == False Then Return "false" |
| 14 | + |
| 15 | + If IsFloat($value) And Int($value) == $value Then Return StringFormat("%s.0", $value) |
| 16 | + |
| 17 | + If IsPtr($value) Or IsHWnd($value) Then Return StringFormat("resource(%d) of type (%s)", $value, VarGetType($value)) |
| 18 | + |
| 19 | + if IsString($value) Then |
| 20 | + If StringRegExp("[^\x09-\x0d\x1b\x20-\xff]", $value) Then Return "Binary String: 0x" & $value ;https://github.com/sebastianbergmann/exporter/blob/2.0/src/Exporter.php#L235 |
| 21 | + |
| 22 | + Return "'" & StringRegExpReplace($value, "(\r\n|\n\r|\r)", @CRLF) & "'" |
| 23 | + EndIf |
| 24 | + |
| 25 | + Local $whitespace = StringRepeat(" ", 4 * $indentation) |
| 26 | + |
| 27 | +;~ If Not $processed Then $processed = new Context |
| 28 | + |
| 29 | + ;Local $key = $processed->contains($value) |
| 30 | + If IsArray($value) Then |
| 31 | + #cs |
| 32 | + If Not $key == False Then Return "Array &" & $key |
| 33 | +
|
| 34 | + Local $array = $value |
| 35 | + $key = $processed->add($value) |
| 36 | + $values = "" |
| 37 | +
|
| 38 | + If UBound($array) > 0 Then |
| 39 | + Local $k |
| 40 | + For $k=0 To UBound($array)-1 |
| 41 | + Local $v = $array[$k] |
| 42 | + $values &= StringFormat("%s %s => %s" & @CRLF, $whitespace, Au3ExporterExporter_RecursiveExport($k, $indentation), Au3ExporterExporter_RecursiveExport($value($k), $indentation + 1, $processed)) |
| 43 | + Next |
| 44 | + Local $values = "\n" & $values & $whitespace |
| 45 | + EndIf |
| 46 | + Return StringFormat("Array &%s (%s)", $key, $values) |
| 47 | + #ce |
| 48 | + EndIf |
| 49 | + |
| 50 | + If IsObj($value) Then |
| 51 | + #cs |
| 52 | + Local $class = get_class($value) |
| 53 | +
|
| 54 | + Local $hash = $processed->contains($value) |
| 55 | + If $hash Then Return StringFormat("%s Object &%s", $class, $hash) |
| 56 | +
|
| 57 | + $hash = $processed->add($value) |
| 58 | + $values = "" |
| 59 | + $array = $this->toArray($value) |
| 60 | +
|
| 61 | + If UBound($array) > 0 Then |
| 62 | + Local $k |
| 63 | + For $k=0 To UBound($array)-1 |
| 64 | + Local $v = $array[$k] |
| 65 | + $values &= StringFormat("%s %s => %s" & @CRLF, $whitespace, Au3ExporterExporter_RecursiveExport($k, $indentation), Au3ExporterExporter_RecursiveExport($v, $indentation + 1, $processed)) |
| 66 | + Next |
| 67 | + $values = @CRLF & $value & $whitespace |
| 68 | + EndIf |
| 69 | + Return StringFormat("%s Object &%s (%s)", $class, $hash, $values) |
| 70 | + #ce |
| 71 | + EndIf |
| 72 | + |
| 73 | + ;Return var_export($value) |
| 74 | + $return = String($value) |
| 75 | + Return $return?$return:VarGetType($value) |
| 76 | +EndFunc |
| 77 | + |
| 78 | +Func StringRepeat($sChar, $nCount); https://www.autoitscript.com/forum/topic/140190-stringrepeat-very-fast-using-memset/ |
| 79 | + $tBuffer = DLLStructCreate("char[" & $nCount & "]") |
| 80 | + DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DLLStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount) |
| 81 | + Return DLLStructGetData($tBuffer, 1) |
| 82 | +EndFunc |
0 commit comments