aboutsummaryrefslogtreecommitdiffhomepage
path: root/wcstringutil.h
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-09-21 19:18:56 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-09-21 19:27:26 -0700
commit8f8c4cdd176fda4d93a2d1d4b0ae6321d5706e5f (patch)
tree68c2f6d4eb2bbd7a4b975b7901cc0db95f83b740 /wcstringutil.h
parentf889ad0fda9bf8d1f354cad37d508e0c4205af48 (diff)
Implement new `read --null` flag
The `--null` flag to `read` makes it split incoming lines on NUL instead of newlines. This is intended for processing the output of a command that uses NUL separators (such as `find -print0`). Fixes #1694.
Diffstat (limited to 'wcstringutil.h')
-rw-r--r--wcstringutil.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/wcstringutil.h b/wcstringutil.h
new file mode 100644
index 00000000..73ca7ac6
--- /dev/null
+++ b/wcstringutil.h
@@ -0,0 +1,29 @@
+/** \file wcstringutil.h
+
+Helper functions for working with wcstring
+*/
+
+#ifndef FISH_WCSTRINGUTIL_H
+#define FISH_WCSTRINGUTIL_H
+
+#include <utility>
+#include "common.h"
+
+/**
+ typedef that represents a range in a wcstring.
+ The first element is the location, the second is the count.
+*/
+typedef std::pair<wcstring::size_type, wcstring::size_type> wcstring_range;
+
+/**
+ wcstring equivalent of wcstok(). Supports NUL.
+ For convenience and wcstok() compatibility, the first character of each
+ token separator is replaced with NUL.
+ Returns a pair of (pos, count).
+ Returns (npos, npos) when it's done.
+ Returns (pos, npos) when the token is already known to be the final token.
+ Note that the final token may not necessarily return (pos, npos).
+*/
+wcstring_range wcstring_tok(wcstring& str, const wcstring &needle, wcstring_range last = wcstring_range(0,0));
+
+#endif