about summary refs log tree commit homepage
path: root/lib/dtas/xs.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dtas/xs.rb')
-rw-r--r--lib/dtas/xs.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/dtas/xs.rb b/lib/dtas/xs.rb
new file mode 100644
index 0000000..968865d
--- /dev/null
+++ b/lib/dtas/xs.rb
@@ -0,0 +1,14 @@
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require_relative '../dtas'
+require 'shellwords'
+
+# We always escape binary strings because paths on POSIX filesystems are
+# encoding agnostic.  Shellwords.split does give UTF-8 strings, but nothing
+# cares at that point if the encoding isn't valid (and it's right to not care,
+# again, filesystems can use any byte value in names except '\0'.
+module DTAS::XS # :nodoc:
+  def xs(ary)
+    Shellwords.join(ary.map { |s| s.b })
+  end
+end