Lartu / ldpl

COBOL-like programming language that compiles to C++. With serious dinosaurs with neckties and briefcases 🦕💼
https://www.ldpl-lang.org/
Apache License 2.0
158 stars 24 forks source link

SPLIT text statement #94

Closed xvxx closed 5 years ago

xvxx commented 5 years ago

This is much nicer than #93. This patch implements the SPLIT statement that was already listed as a TODO in the source. It lets you easily just split a string or file into a vector and loop over that, and avoids all the caching nonsense.

DATA:
words is text vector
PROCEDURE:
SPLIT "hi there" BY " " IN words
DISPLAY words:1 crlf

output:

there

If you want to get all the characters, you can split by "":

SPLIT "hi there" BY "" IN letters
DISPLAY letters:1 crlf

output:

i

And of course, the whole point - it works with utf8:

split "🐈 say meow, 🐕 say woof" by "" in letters
display letters:0 crlf
display letters:6 letters:7 letters:8 letters:9 crlf
display letters:12 crlf

output:

🐈
meow
🐕
Lartu commented 5 years ago

I love this, awesome!! Thank you very very much for this wonderful contribution! Also, the idea of using "" to get all the letters is great, I hadn't thought of that! Thank you!

Lartu commented 5 years ago

Merged! Please @dvkt go ahead and document this new funcion in the GitBook and - if possible - go ahead and regenerate the man page for LDPL (instructions for doing that are in the /man folder).

xvxx commented 5 years ago

Done! https://docs.ldpl-lang.org/text-statements/split-by-in

Lartu commented 5 years ago

Awesome! I see you also documented INCR and DECR, thank you very much! This is so great, haha, thank you!