]> gitweb.factorcode.org Git - factor.git/commitdiff
splitting: slightly faster linebreak? and docs
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 19 Sep 2023 15:37:55 +0000 (08:37 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 19 Sep 2023 15:37:55 +0000 (08:37 -0700)
core/splitting/splitting-docs.factor
core/splitting/splitting.factor

index f291372f7a6a4ce90248fbf39d3a37772508b2e0..545f023dafa6189501f7bd97cdd345b3abd11c2b 100644 (file)
@@ -97,6 +97,21 @@ HELP: ?tail-slice
 HELP: split-lines
 { $values { "seq" sequence } { "seq'" { $sequence string } } }
 { $description "Splits a string along line breaks." }
+{ $notes "These are considered line breaks:"
+    { $table
+        { { $snippet "\\n" } "Line Feed" }
+        { { $snippet "\\r" } "Carriage Return" }
+        { { $snippet "\\r\\n" } "Carriage Return + Line Feed" }
+        { { $snippet "\\v" } "Line Tabulation" }
+        { { $snippet "\\f" } "Form Feed" }
+        { { $snippet "\\x1c" } "File Separator" }
+        { { $snippet "\\x1d" } "Group Separator" }
+        { { $snippet "\\x1e" } "Record Separator" }
+        { { $snippet "\\x85" } "Next Line (C1 Control Code)" }
+        { { $snippet "\\u002028" } "Line Separator" }
+        { { $snippet "\\u002029" } "Paragraph Separator" }
+    }
+}
 { $examples
     { $example "USING: prettyprint splitting ;" "\"Hello\\r\\nworld\\n\" split-lines ." "{ \"Hello\" \"world\" }" }
 } ;
index 6447ceb3fc09574af6013f54eb10ac0be1c2ef91..8bcb00cfe7a218dcabb97a51522910195e21da1d 100644 (file)
@@ -98,8 +98,12 @@ PRIVATE>
 
 : linebreak? ( ch -- ? )
     { fixnum } declare
-    dup CHAR: \n CHAR: \r between? [ drop t ] [         ! LINE FEED, CARRIAGE RETURN, LINE TABULATION, FORM FEED
-        dup CHAR: \x1c CHAR: \x1e between? [ drop t ] [ ! FILE, GROUP, RECORD SEPARATOR
+    dup CHAR: \x1f < [
+        dup CHAR: \n CHAR: \r between? [ drop t ] [     ! LINE FEED, CARRIAGE RETURN, LINE TABULATION, FORM FEED
+            CHAR: \x1c CHAR: \x1e between?              ! FILE, GROUP, RECORD SEPARATOR
+        ] if
+    ] [
+        dup CHAR: \x85 < [ drop f ] [
             dup CHAR: \x85 = [ drop t ] [               ! NEXT LINE (C1 CONTROL CODE)
                 CHAR: \u002028 CHAR: \u002029 between?  ! LINE, PARAGRAPH SEPARATOR
             ] if