mirror of
https://github.com/mudler/LocalAI.git
synced 2024-06-07 19:40:48 +00:00
acd829a7a0
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
14 lines
318 B
Go
14 lines
318 B
Go
package utils
|
|
|
|
import "regexp"
|
|
|
|
var matchNewlines = regexp.MustCompile(`[\r\n]`)
|
|
|
|
const doubleQuote = `"[^"\\]*(?:\\[\s\S][^"\\]*)*"`
|
|
|
|
func EscapeNewLines(s string) string {
|
|
return regexp.MustCompile(doubleQuote).ReplaceAllStringFunc(s, func(s string) string {
|
|
return matchNewlines.ReplaceAllString(s, "\\n")
|
|
})
|
|
}
|