Created
June 10, 2024 13:18
-
-
Save ppazos/4f1bf79a89d92ef896d13b8a32120813 to your computer and use it in GitHub Desktop.
Generates a paragraph text from a long line, limiting line size and number of words per line
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
def s = "An EHR_STATUS resource needs to be always created and committed in the new EHR. This resource MAY be also supplied by the client as the request body. If not supplied, a default EHR_STATUS will be used by the service with following attributes" | |
def ss = s.split(" ") | |
println ss | |
def wlimit = 4 | |
def climit = 23 | |
def out = '' | |
def line = '' | |
def words_in_line = 0 | |
for (int i=0; i<ss.size(); i++) | |
{ | |
if (line.size() + ss[i].size() > climit) | |
{ | |
out += line + "\n" | |
line = ss[i] + ' ' | |
words_in_line = 1 | |
} | |
else | |
{ | |
if ((words_in_line + 1) % wlimit == 0) | |
{ | |
out += line + ss[i] + "\n" | |
line = '' | |
words_in_line = 0 | |
} | |
else | |
{ | |
line += ss[i] +' ' | |
words_in_line++ | |
} | |
} | |
} | |
println out |
Author
ppazos
commented
Jun 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment