mirror of
https://github.com/janet-lang/janet
synced 2025-11-05 01:53:01 +00:00
Revert inclusion of dedent.
Dedent has been moved to spork as misc function. There are two many different, incompatible ways to 'dedent' as string, and it seems rather specific to add to the core like it is.
This commit is contained in:
@@ -1332,27 +1332,6 @@
|
||||
(if (not= i len) (array/push ret (slicer ind i)))
|
||||
ret)
|
||||
|
||||
(defn dedent
|
||||
"Remove indentation after concatenating the arguments. Works by removing
|
||||
leading whitespace, and then removing that same pattern of whitepsace after
|
||||
new lines."
|
||||
[& xs]
|
||||
(def x (string ;xs))
|
||||
(def first-letter (find-index (fn [c] (and (not= c (chr "\n"))
|
||||
(not= c (chr " "))
|
||||
(not= c (chr "\t"))
|
||||
(not= c (chr "\r")))) x))
|
||||
(if (not first-letter) (break ""))
|
||||
(def leading-whitespace (string/slice x 0 first-letter))
|
||||
(def indent (last (string/split "\n" leading-whitespace)))
|
||||
(if (and indent (not= indent ""))
|
||||
(let [y (string/replace-all (string "\n" indent) "\n" (string/replace indent "" x))]
|
||||
# Remove trailing newline to mimic long string newline omission.
|
||||
(if (= (chr "\n") (last y))
|
||||
(slice y 0 -2)
|
||||
y))
|
||||
x))
|
||||
|
||||
###
|
||||
###
|
||||
### IO Helpers
|
||||
|
||||
Reference in New Issue
Block a user