Last active
March 28, 2017 14:57
-
-
Save primiano/7bd2c53f8c3637c53c39f1f10a8750fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ g++ -o test test.cc --std=c++11 && ./test | |
<blink_gc> | |
<allocated_objects> | |
<net> | |
<url_request_context> | |
<app_request, extensions, isolated_media> | |
<0x?> | |
<http_cache> | |
<http_network_session> | |
<sdch_manager> | |
$ cat test.cc | |
#include <initializer_list> | |
#include <vector> | |
#include <string> | |
#include <string.h> | |
struct WhitelistNode { | |
using AnyKey = std::initializer_list<const char*>; | |
explicit WhitelistNode(AnyKey keys) : WhitelistNode(keys, {}) {} | |
explicit WhitelistNode(const char *key) : WhitelistNode(key, {}) {} | |
WhitelistNode(const char *key, std::initializer_list<WhitelistNode> children) | |
: WhitelistNode({key}, children) {} | |
WhitelistNode(AnyKey keys, std::initializer_list<WhitelistNode> children) | |
: keys{keys}, children(children) {} | |
bool match(const char *piece) const { | |
return false;// TODO implement this; | |
} | |
std::vector<const char*> keys; | |
std::vector<WhitelistNode> children; | |
}; | |
using Whitelist = std::vector<WhitelistNode>; | |
const Whitelist& GetWhitelist() { | |
using WL = WhitelistNode; | |
static Whitelist whitelist{ | |
WL("blink_gc", { | |
WL("allocated_objects") | |
}), | |
WL("net", { | |
WL("url_request_context", { | |
WL(WL::AnyKey{"app_request", "extensions", "isolated_media"}, { | |
WL("0x?", { | |
WL("http_cache"), | |
WL("http_network_session"), | |
WL("sdch_manager") | |
}) | |
}) | |
}) | |
}) | |
}; | |
return whitelist; | |
}; | |
void Dump(const Whitelist& list, std::string pfx) { | |
for (const auto& entry : list) { | |
printf("%s<", pfx.c_str()); | |
for (const char* key : entry.keys) | |
printf("%s%s", key, key != entry.keys.back() ? ", " : ""); | |
printf(">\n"); | |
Dump(entry.children, pfx + " "); | |
} | |
}; | |
int main() { | |
Dump(GetWhitelist(), ""); | |
} | |
WL("http_cache"), | |
WL("http_network_session"), | |
WL("sdch_manager") | |
}) | |
}) | |
}) | |
}) | |
}; | |
return whitelist; | |
}; | |
void Dump(const Whitelist& list, std::string pfx) { | |
for (const auto& entry : list) { | |
printf("%s<", pfx.c_str()); | |
for (const char* key : entry.keys) | |
printf("%s%s", key, key != entry.keys.back() ? ", " : ""); | |
printf(">\n"); | |
Dump(entry.children, pfx + " "); | |
} | |
}; | |
int main() { | |
Dump(GetWhitelist(), ""); | |
} | |
return false;// TODO implement this; | |
} | |
std::vector<const char*> keys; | |
Whitelist children; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment