(in, prefix string)
| 938 | } |
| 939 | |
| 940 | func stringToGoCommentWithPrefix(in, prefix string) string { |
| 941 | if len(in) == 0 || len(strings.TrimSpace(in)) == 0 { // ignore empty comment |
| 942 | return "" |
| 943 | } |
| 944 | |
| 945 | // Normalize newlines from Windows/Mac to Linux |
| 946 | in = strings.ReplaceAll(in, "\r\n", "\n") |
| 947 | in = strings.ReplaceAll(in, "\r", "\n") |
| 948 | |
| 949 | // Add comment to each line |
| 950 | var lines []string |
| 951 | for i, line := range strings.Split(in, "\n") { |
| 952 | s := "//" |
| 953 | if i == 0 && len(prefix) > 0 { |
| 954 | s += " " + prefix |
| 955 | } |
| 956 | lines = append(lines, fmt.Sprintf("%s %s", s, line)) |
| 957 | } |
| 958 | in = strings.Join(lines, "\n") |
| 959 | |
| 960 | // in case we have a multiline string which ends with \n, we would generate |
| 961 | // empty-line-comments, like `// `. Therefore remove this line comment. |
| 962 | in = strings.TrimSuffix(in, "\n// ") |
| 963 | return in |
| 964 | } |
| 965 | |
| 966 | // EscapePathElements breaks apart a path, and looks at each element. If it's |
| 967 | // not a path parameter, eg, {param}, it will URL-escape the element. |
no outgoing calls
no test coverage detected