Skip to content

Commit

Permalink
Print short unknown type data if all characters are ascii printable
Browse files Browse the repository at this point in the history
  • Loading branch information
myrsloik authored and WolframRhodium committed Apr 4, 2024
1 parent 2bff1e5 commit 15c6828
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/avisynth/avisynth_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ static void VS_CC fakeAvisynthFunctionWrapper(const VSMap *in, VSMap *out, void
avisynthFilterFree,
(preFetchClips.empty() || prefetchInfo.from > prefetchInfo.to) ? fmFrameState : fmParallelRequests,
deps.data(),
preFetchClips.size(),
static_cast<int>(preFetchClips.size()),
filterData.release(),
core);

Expand Down
9 changes: 8 additions & 1 deletion src/vspipe/vsjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
#include "vsjson.h"
#include "clocale"

static bool isAsciiPrintable(const std::string &s) {
for (const auto c : s)
if (c < 0x20 || c > 0x7E)
return false;
return true;
}

static std::string doubleToString(double v) {
std::string result = std::to_string(v);
char point = *localeconv()->decimal_point;
Expand Down Expand Up @@ -90,7 +97,7 @@ std::string convertVSMapToJSON(const VSMap *map, const VSAPI *vsapi) {
for (int j = 0; j < numElems; j++) {
int typeHint = vsapi->mapGetDataTypeHint(map, key, j, nullptr);
jsonStr += (j ? ", " : "");
if (typeHint == dtUtf8)
if (typeHint == dtUtf8 || (typeHint == dtUnknown && vsapi->mapGetDataSize(map, key, j, nullptr) < 200 && isAsciiPrintable(std::string(vsapi->mapGetData(map, key, j, nullptr), vsapi->mapGetDataSize(map, key, j, nullptr)))))
jsonStr += escapeJSONString(vsapi->mapGetData(map, key, j, nullptr));
else
jsonStr += "\"[binary data size: " + std::to_string(vsapi->mapGetDataSize(map, key, j, nullptr)) + "]\"";
Expand Down

0 comments on commit 15c6828

Please sign in to comment.