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]...