From 8dc7cdb1cdf7242aab1ae75369cbd1dfe6b0b129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Wed, 23 Aug 2023 09:43:43 +0200 Subject: [PATCH] Added ScriptEscape function --- script.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/script.go b/script.go index 616261a..6c0be95 100644 --- a/script.go +++ b/script.go @@ -1,5 +1,15 @@ package mikrotik -func Test() int { - return 137 +import ( + // Standard + "regexp" +) + +func ScriptEscape(source []byte) (escaped []byte) { + rxp2 := regexp.MustCompile("([\"\\\\$])") + source = rxp2.ReplaceAll(source, []byte("\\$1")) + + rxp := regexp.MustCompile("\\r?\\n") + escaped = rxp.ReplaceAll(source, []byte("\\r\\\r\n \\n")) + return }