From e2fd1e06ffd85aa0080ffa342f2e3e6c24b1e710 Mon Sep 17 00:00:00 2001 From: Andrey Ivanov Date: Sun, 7 Jun 2020 19:54:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=8B=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B1=D0=B5=D0=B6=D0=B4=D0=B5=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hw02_unpack_string/go.mod | 1 - hw02_unpack_string/unpack.go | 15 +++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/hw02_unpack_string/go.mod b/hw02_unpack_string/go.mod index 5588f22..01a3879 100644 --- a/hw02_unpack_string/go.mod +++ b/hw02_unpack_string/go.mod @@ -1,6 +1,5 @@ module github.com/tiburon-777/HW_OTUS/hw02_unpack_string - go 1.14 require github.com/stretchr/testify v1.5.0 \ No newline at end of file diff --git a/hw02_unpack_string/unpack.go b/hw02_unpack_string/unpack.go index f7da01d..e5f00cb 100644 --- a/hw02_unpack_string/unpack.go +++ b/hw02_unpack_string/unpack.go @@ -18,18 +18,12 @@ func Unpack(str string) (string, error) { switch { // Ловим паттерн [\][letter][digit] case string(temp[i]) == slash && i < len(temp)-2 && unicode.IsLetter(temp[i+1]) && unicode.IsDigit(temp[i+2]): - c, err := strconv.Atoi(string(temp[i+2])) - if err != nil { - return "", err - } + c, _ := strconv.Atoi(string(temp[i+2])) b.WriteString(strings.Repeat(slash+string(temp[i+1]), c)) i += 2 // Ловим паттерн [\][digit или \][digit] case string(temp[i]) == slash && i < len(temp)-2 && (unicode.IsDigit(temp[i+1]) || string(temp[i+1]) == slash) && unicode.IsDigit(temp[i+2]): - c, err := strconv.Atoi(string(temp[i+2])) - if err != nil { - return "", err - } + c, _ := strconv.Atoi(string(temp[i+2])) b.WriteString(strings.Repeat(string(temp[i+1]), c)) i += 2 // Ловим паттерн [\][digit или \] @@ -37,10 +31,7 @@ func Unpack(str string) (string, error) { b.WriteRune(temp[i+1]) i++ case unicode.IsLetter(temp[i]) && i < len(temp)-1 && unicode.IsDigit(temp[i+1]): - c, err := strconv.Atoi(string(temp[i+1])) - if err != nil { - return "", err - } + c, _ := strconv.Atoi(string(temp[i+1])) b.WriteString(strings.Repeat(string(temp[i]), c)) i++ // Ловим паттерн [letter]...