Skip to content

Commit f26454a

Browse files
Merge pull request #1506 from caberos/issue1505
new method to fix the table disconfigurate when the text data is very…
2 parents 9321d72 + d50b30c commit f26454a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

SoftLayer/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,24 @@ def trim_to(string, length=80, tail="..."):
406406
return string[:length] + tail
407407
else:
408408
return string
409+
410+
411+
def format_comment(comment, max_line_length=60):
412+
"""Return a string that is length long, added a next line and keep the table format.
413+
414+
:param string comment: String you want to add next line
415+
:param int max_line_length: max length for the string
416+
"""
417+
comment_length = 0
418+
words = comment.split(" ")
419+
formatted_comment = ""
420+
for word in words:
421+
if comment_length + (len(word) + 1) <= max_line_length:
422+
formatted_comment = formatted_comment + word + " "
423+
424+
comment_length = comment_length + len(word) + 1
425+
else:
426+
formatted_comment = formatted_comment + "\n" + word + " "
427+
428+
comment_length = len(word) + 1
429+
return formatted_comment

0 commit comments

Comments
 (0)