Use Windows line feeds in generated files on Windows.
GitOrigin-RevId: 53010ee7d1a3b88bedc3c0a5fd6914d31bb33c09
This commit is contained in:
parent
91365f20b5
commit
642f5ed81a
@ -209,7 +209,17 @@ void gen_json_converter_file(const tl::simple::Schema &schema, const std::string
|
|||||||
|
|
||||||
CHECK(!sb.is_error());
|
CHECK(!sb.is_error());
|
||||||
buf.resize(sb.as_cslice().size());
|
buf.resize(sb.as_cslice().size());
|
||||||
|
#if TD_WINDOWS
|
||||||
|
string new_file_content;
|
||||||
|
for (auto c : buf) {
|
||||||
|
if (c == '\n') {
|
||||||
|
new_file_content += '\r';
|
||||||
|
}
|
||||||
|
new_file_content += c;
|
||||||
|
}
|
||||||
|
#else
|
||||||
auto new_file_content = std::move(buf);
|
auto new_file_content = std::move(buf);
|
||||||
|
#endif
|
||||||
if (new_file_content != old_file_content.as_slice()) {
|
if (new_file_content != old_file_content.as_slice()) {
|
||||||
write_file(file_name, new_file_content).ensure();
|
write_file(file_name, new_file_content).ensure();
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,19 @@ void tl_string_outputer::append(const std::string &str) {
|
|||||||
result += str;
|
result += str;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &tl_string_outputer::get_result() const {
|
std::string tl_string_outputer::get_result() const {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
std::string fixed_result;
|
||||||
|
for (std::size_t i = 0; i < result.size(); i++) {
|
||||||
|
if (result[i] == '\n') {
|
||||||
|
fixed_result += '\r';
|
||||||
|
}
|
||||||
|
fixed_result += result[i];
|
||||||
|
}
|
||||||
|
return fixed_result;
|
||||||
|
#else
|
||||||
return result;
|
return result;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tl
|
} // namespace tl
|
||||||
|
@ -19,7 +19,7 @@ class tl_string_outputer : public tl_outputer {
|
|||||||
public:
|
public:
|
||||||
virtual void append(const std::string &str);
|
virtual void append(const std::string &str);
|
||||||
|
|
||||||
const std::string &get_result() const;
|
std::string get_result() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tl
|
} // namespace tl
|
||||||
|
Loading…
Reference in New Issue
Block a user