Created
July 5, 2018 22:36
-
-
Save nedzadarek/e5ab2390ae76896c3806d3bbd3deb3c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s: {^/ 2^/ 2^/ 3} | |
heredoc2: function [str [ string!] ][ | |
str: remove copy str | |
number-of-spaces-in-line: spaces: 0 ; initialize in order not to leak by parse | |
lines: split str "^/" | |
indentation: 99999999 | |
foreach line lines [ | |
parse line [copy spaces any space (number-of-spaces-in-line: length? spaces) to end] | |
if indentation > number-of-spaces-in-line [ | |
indentation: number-of-spaces-in-line | |
] | |
] | |
new-str: copy "" | |
foreach line lines [ | |
append new-str remove/part line indentation | |
append new-str "^/" | |
] | |
new-str | |
] | |
heredoc1: function [str [string! ] ] [ | |
spaces copy "" | |
str: remove copy str | |
indentation: 0 | |
lines: split str "^/" | |
chars: charset [#"0" - #"9" #"a" - #"z"] | |
parse str [copy spaces to chars to end] | |
indentation: length? spaces | |
new-str: copy "" | |
foreach line lines [ | |
append new-str remove/part line indentation | |
append new-str "^/" | |
] | |
new-str | |
] | |
print s | |
print heredoc1 s | |
print heredoc2 s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment