ParseDescription takes a single string containing newline characters and splits it into a multiline description. All empty lines will be skipped. Returns an empty string if the input string is empty.
(doc string)
| 74 | // |
| 75 | // Returns an empty string if the input string is empty. |
| 76 | func ParseDescription(doc string) string { |
| 77 | var lines []string |
| 78 | if len(doc) != 0 { |
| 79 | // Split the input string by newline characters. |
| 80 | for _, line := range strings.Split(doc, "\n") { |
| 81 | l := strings.TrimRightFunc(line, unicode.IsSpace) |
| 82 | if len(l) == 0 { |
| 83 | continue |
| 84 | } |
| 85 | lines = append(lines, l) |
| 86 | } |
| 87 | } |
| 88 | // Return an empty slice if the input is empty. |
| 89 | return MultilineDescription(lines...) |
| 90 | } |
| 91 | |
| 92 | // ParseDescriptions splits a documentation string into multiple multi-line description |
| 93 | // sections, using blank lines as delimiters. |