aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/shlex.hh
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-03-14 17:44:43 -0700
committerRebecca Turner <rbt@sent.as>2024-03-26 16:44:04 -0700
commitaee3d639b5096349413021537ae842c8c33ef6cf (patch)
treeee8557f970f5c477116bd1b77a8b9cacce59d03a /src/libutil/shlex.hh
parentda22dbc33397c9c6c5d115ce753d5cf11585291e (diff)
Move `shell_words` into its own file
Change-Id: I34c0ebfb6dcea49bf632d8880e04075335a132bf
Diffstat (limited to 'src/libutil/shlex.hh')
-rw-r--r--src/libutil/shlex.hh30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libutil/shlex.hh b/src/libutil/shlex.hh
new file mode 100644
index 000000000..4e7a48597
--- /dev/null
+++ b/src/libutil/shlex.hh
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <regex>
+#include <string>
+#include <vector>
+
+#include "error.hh"
+
+namespace nix {
+
+class ShlexError : public Error
+{
+public:
+ const std::string input;
+
+ ShlexError(const std::string input)
+ : Error("Failed to parse shell arguments (unterminated quote?): %1%", input)
+ , input(input)
+ {
+ }
+};
+
+/**
+ * Parse a string into shell arguments.
+ *
+ * Takes care of whitespace, quotes, and backslashes (at least a bit).
+ */
+std::vector<std::string> shell_split(const std::string & input);
+
+} // namespace nix