Created
May 1, 2012 03:56
-
-
Save namuol/2564838 to your computer and use it in GitHub Desktop.
Simple algorithm to split a line of text based on a desired line width. For fixed-width fonts only.
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
split_to_lines = (str, max_width) -> | |
lines = [] | |
words = str.split(' ') | |
current_line = '' | |
for word in words | |
if current_line.length + word.length > max_width | |
lines.push current_line | |
current_line = word + ' ' | |
else | |
current_line += word + ' ' | |
lines.push current_line | |
return lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment