mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Replace non-alphanumeric, non-underscore characters in filewrapper
PiperOrigin-RevId: 246320238 Change-Id: I08454dc19b6227e4ce2c1b7677b916706e7be5a5
This commit is contained in:
parent
64cfb949f4
commit
7753cded13
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
// Simple utility to wrap a binary file in a C++ source file.
|
// Simple utility to wrap a binary file in a C++ source file.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -216,9 +217,10 @@ int main(int argc, char* argv[]) {
|
||||||
{ // Write header file first.
|
{ // Write header file first.
|
||||||
File out_h(*arg++, "wb");
|
File out_h(*arg++, "wb");
|
||||||
--argc;
|
--argc;
|
||||||
std::string header_guard = absl::StrReplaceAll(
|
std::string header_guard = absl::StrFormat("%s_%s_H_", package, toc_ident);
|
||||||
absl::AsciiStrToUpper(absl::StrFormat("%s_%s_H_", package, toc_ident)),
|
std::replace_if(
|
||||||
{{"/", "_"}});
|
header_guard.begin(), header_guard.end(),
|
||||||
|
[](char c) { return !absl::ascii_isalnum(c); }, '_');
|
||||||
absl::FPrintF(out_h.get(), kHFileHeaderFmt, package, toc_ident,
|
absl::FPrintF(out_h.get(), kHFileHeaderFmt, package, toc_ident,
|
||||||
header_guard);
|
header_guard);
|
||||||
if (have_ns) {
|
if (have_ns) {
|
||||||
|
@ -248,8 +250,10 @@ int main(int argc, char* argv[]) {
|
||||||
File in(in_filename, "rb");
|
File in(in_filename, "rb");
|
||||||
|
|
||||||
std::string basename = sandbox2::file_util::fileops::Basename(in_filename);
|
std::string basename = sandbox2::file_util::fileops::Basename(in_filename);
|
||||||
std::string ident = absl::StrCat(
|
std::string ident = absl::StrCat("k", basename);
|
||||||
"k", absl::StrReplaceAll(basename, {{".", "_"}, {"-", "_"}}));
|
std::replace_if(
|
||||||
|
ident.begin(), ident.end(),
|
||||||
|
[](char c) { return !absl::ascii_isalnum(c); }, '_');
|
||||||
absl::FPrintF(out_cc.get(), kCcDataBeginFmt, ident);
|
absl::FPrintF(out_cc.get(), kCcDataBeginFmt, ident);
|
||||||
// Remember identifiers, they are needed in the kToc array.
|
// Remember identifiers, they are needed in the kToc array.
|
||||||
toc_entries.emplace_back(std::move(basename), std::move(ident));
|
toc_entries.emplace_back(std::move(basename), std::move(ident));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user