summaryrefslogtreecommitdiff
path: root/namespace.py
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-10-02 00:15:42 +0200
committerAki <please@ignore.pl>2022-10-02 00:15:42 +0200
commit6a69a91303f7834f86978306c9c4c93ee23ae0d4 (patch)
tree2f341dca9fb85d64232da5c43ce79e8e4d6cf82b /namespace.py
downloadnamespace-master.zip
namespace-master.tar.gz
namespace-master.tar.bz2
Implemented utility to quickly make namespaces in visHEAD1.0.0master
Diffstat (limited to 'namespace.py')
-rwxr-xr-xnamespace.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/namespace.py b/namespace.py
new file mode 100755
index 0000000..d7d3165
--- /dev/null
+++ b/namespace.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+"""
+Wraps standard input with C++ namespaces and writes it to standard output. Rather niche tool unless you rely too much
+on pipes in your code editor.
+"""
+
+import argparse
+import sys
+
+
+def split(path):
+ """Splits namespace path into parts."""
+ return path.replace("::", "/").replace(":", "/").split("/")
+
+
+def wrap(in_, out, namespaces):
+ """Wraps input with C++ namespaces and writes it to output handle."""
+ for ns in namespaces:
+ out.write("namespace {}\n{}\n".format(ns, "{"))
+ out.write("\n\n")
+ for x in in_:
+ out.write(x)
+ out.write("\n\n")
+ for ns in reversed(namespaces):
+ out.write("{} // namespace {}\n".format("}", ns))
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("namespaces")
+ args = parser.parse_args()
+ wrap(sys.stdin, sys.stdout, split(args.namespaces))
+
+
+if __name__ == '__main__':
+ main()