]> gitweb.factorcode.org Git - factor.git/commitdiff
add quoting vocab
authorsheeple <sheeple@oberon.local>
Sun, 22 Feb 2009 06:42:21 +0000 (00:42 -0600)
committersheeple <sheeple@oberon.local>
Sun, 22 Feb 2009 06:42:21 +0000 (00:42 -0600)
basis/quoting/authors.txt [new file with mode: 0644]
basis/quoting/quoting-docs.factor [new file with mode: 0644]
basis/quoting/quoting-tests.factor [new file with mode: 0644]
basis/quoting/quoting.factor [new file with mode: 0644]

diff --git a/basis/quoting/authors.txt b/basis/quoting/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/quoting/quoting-docs.factor b/basis/quoting/quoting-docs.factor
new file mode 100644 (file)
index 0000000..5fb68db
--- /dev/null
@@ -0,0 +1,32 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax strings ;
+IN: quoting
+
+HELP: quote?
+{ $values
+     { "ch" "a character" }
+     { "?" "a boolean" }
+}
+{ $description "Returns true if the character is a single or double quote." } ;
+
+HELP: quoted?
+{ $values
+     { "str" string }
+     { "?" "a boolean" }
+}
+{ $description "Returns true if a string is surrounded by matching single or double quotes as the first and last characters." } ;
+
+HELP: unquote
+{ $values
+     { "str" string }
+     { "newstr" string }
+}
+{ $description "Removes a pair of matching single or double quotes from a string." } ;
+
+ARTICLE: "quoting" "Quotation marks"
+"The " { $vocab-link "quoting" } " vocabulary is for removing quotes from a string." $nl
+"Removing quotes:"
+{ $subsection unquote } ;
+
+ABOUT: "quoting"
diff --git a/basis/quoting/quoting-tests.factor b/basis/quoting/quoting-tests.factor
new file mode 100644 (file)
index 0000000..0cc28a1
--- /dev/null
@@ -0,0 +1,10 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test quoting ;
+IN: quoting.tests
+
+
+[ "abc" ] [ "'abc'" unquote ] unit-test
+[ "abc" ] [ "\"abc\"" unquote ] unit-test
+[ "'abc" ] [ "'abc" unquote ] unit-test
+[ "abc'" ] [ "abc'" unquote ] unit-test
diff --git a/basis/quoting/quoting.factor b/basis/quoting/quoting.factor
new file mode 100644 (file)
index 0000000..9e25037
--- /dev/null
@@ -0,0 +1,16 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: combinators.short-circuit kernel math sequences strings ;
+IN: quoting
+
+: quote? ( ch -- ? ) "'\"" member? ;
+
+: quoted? ( str -- ? )
+    {
+        [ length 1 > ]
+        [ first quote? ]
+        [ [ first ] [ peek ] bi = ]
+    } 1&& ;
+
+: unquote ( str -- newstr )
+    dup quoted? [ but-last-slice rest-slice >string ] when ;