From 095a8daab2a32f184dc5c053a1e2bad644ac3af8 Mon Sep 17 00:00:00 2001 From: linbergil Date: Sun, 5 Nov 2023 16:20:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B2=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81?= =?UTF-8?q?=20number,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D0=BB=D0=B5=D1=88=20=D0=B2=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D1=83=D1=89=D0=B5=D0=B9=20=D0=B8=D1=82=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unpack.go | 8 ++++++-- unpack_test.go | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/unpack.go b/unpack.go index 503a516..c7d18d0 100644 --- a/unpack.go +++ b/unpack.go @@ -45,7 +45,8 @@ func Unpack(str string) (string, error) { if unicode.IsDigit(char) { currentState = number numOfRepeat, _ = strconv.Atoi(string(char)) - repStr, err := repeatRune(runeArray[i-1], numOfRepeat) + n := strconv.Itoa(numOfRepeat) + repStr, err := repeatRune(runeArray[i-len(n)], numOfRepeat) if err != nil { // Если функция repeatRune возвращает ошибку, удаляем последний символ из результата. res := result.String() @@ -60,7 +61,9 @@ func Unpack(str string) (string, error) { currentState = start } case number: - if unicode.IsDigit(char) { + if char == '\\' { + currentState = escape + } else if unicode.IsDigit(char) { var n = strconv.Itoa(numOfRepeat) + string(char) numOfRepeat, _ = strconv.Atoi(n) repStr, err := repeatRune(runeArray[i-len(n)], numOfRepeat) @@ -71,6 +74,7 @@ func Unpack(str string) (string, error) { result.WriteString(res[0 : len(res)-1]) } result.WriteString(repStr) + } else { result.WriteRune(char) currentState = start diff --git a/unpack_test.go b/unpack_test.go index 5ecf2de..3544492 100644 --- a/unpack_test.go +++ b/unpack_test.go @@ -26,6 +26,8 @@ func TestUnpack(t *testing.T) { {input: `qwe\45`, expected: `qwe44444`}, {input: `qwe\\5`, expected: `qwe\\\\\`}, {input: `qwe\\\3`, expected: `qwe\3`}, + {input: `qwe2\1`, expected: `qwee1`}, + {input: `qwe2\\`, expected: `qwee\`}, } for _, tc := range tests {