mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-16 06:35:24 +00:00
Avoid exporting one single backslash in JSON data strings
This commit is contained in:
parent
5e46ed6571
commit
33b42d195b
@ -20,6 +20,7 @@
|
|||||||
#include "base/convert_to.h"
|
#include "base/convert_to.h"
|
||||||
#include "base/fstream_path.h"
|
#include "base/fstream_path.h"
|
||||||
#include "base/path.h"
|
#include "base/path.h"
|
||||||
|
#include "base/replace_string.h"
|
||||||
#include "base/shared_ptr.h"
|
#include "base/shared_ptr.h"
|
||||||
#include "base/string.h"
|
#include "base/string.h"
|
||||||
#include "base/unique_ptr.h"
|
#include "base/unique_ptr.h"
|
||||||
@ -42,6 +43,17 @@
|
|||||||
|
|
||||||
using namespace doc;
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
std::string escape_path_for_json(const std::string& path)
|
||||||
|
{
|
||||||
|
std::string res = path;
|
||||||
|
base::replace_string(res, "\\", "\\\\");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
class SampleBounds {
|
class SampleBounds {
|
||||||
@ -528,10 +540,10 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os,
|
|||||||
gfx::Rect frameBounds = sample.inTextureBounds();
|
gfx::Rect frameBounds = sample.inTextureBounds();
|
||||||
|
|
||||||
if (filename_as_key)
|
if (filename_as_key)
|
||||||
os << " \"" << sample.filename() << "\": {\n";
|
os << " \"" << escape_path_for_json(sample.filename()) << "\": {\n";
|
||||||
else if (filename_as_attr)
|
else if (filename_as_attr)
|
||||||
os << " {\n"
|
os << " {\n"
|
||||||
<< " \"filename\": \"" << sample.filename() << "\",\n";
|
<< " \"filename\": \"" << escape_path_for_json(sample.filename()) << "\",\n";
|
||||||
|
|
||||||
os << " \"frame\": { "
|
os << " \"frame\": { "
|
||||||
<< "\"x\": " << frameBounds.x << ", "
|
<< "\"x\": " << frameBounds.x << ", "
|
||||||
@ -562,7 +574,7 @@ void DocumentExporter::createDataFile(const Samples& samples, std::ostream& os,
|
|||||||
<< " \"app\": \"" << WEBSITE << "\",\n"
|
<< " \"app\": \"" << WEBSITE << "\",\n"
|
||||||
<< " \"version\": \"" << VERSION << "\",\n";
|
<< " \"version\": \"" << VERSION << "\",\n";
|
||||||
if (!m_textureFilename.empty())
|
if (!m_textureFilename.empty())
|
||||||
os << " \"image\": \"" << m_textureFilename.c_str() << "\",\n";
|
os << " \"image\": \"" << escape_path_for_json(m_textureFilename).c_str() << "\",\n";
|
||||||
os << " \"format\": \"" << (textureImage->pixelFormat() == IMAGE_RGB ? "RGBA8888": "I8") << "\",\n"
|
os << " \"format\": \"" << (textureImage->pixelFormat() == IMAGE_RGB ? "RGBA8888": "I8") << "\",\n"
|
||||||
<< " \"size\": { "
|
<< " \"size\": { "
|
||||||
<< "\"w\": " << textureImage->width() << ", "
|
<< "\"w\": " << textureImage->width() << ", "
|
||||||
|
Loading…
Reference in New Issue
Block a user