Линтеры побеждены
parent
3f8a699aa4
commit
e2fd1e06ff
|
@ -1,6 +1,5 @@
|
||||||
module github.com/tiburon-777/HW_OTUS/hw02_unpack_string
|
module github.com/tiburon-777/HW_OTUS/hw02_unpack_string
|
||||||
|
|
||||||
|
|
||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require github.com/stretchr/testify v1.5.0
|
require github.com/stretchr/testify v1.5.0
|
|
@ -18,18 +18,12 @@ func Unpack(str string) (string, error) {
|
||||||
switch {
|
switch {
|
||||||
// Ловим паттерн [\][letter][digit]
|
// Ловим паттерн [\][letter][digit]
|
||||||
case string(temp[i]) == slash && i < len(temp)-2 && unicode.IsLetter(temp[i+1]) && unicode.IsDigit(temp[i+2]):
|
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]))
|
c, _ := strconv.Atoi(string(temp[i+2]))
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
b.WriteString(strings.Repeat(slash+string(temp[i+1]), c))
|
b.WriteString(strings.Repeat(slash+string(temp[i+1]), c))
|
||||||
i += 2
|
i += 2
|
||||||
// Ловим паттерн [\][digit или \][digit]
|
// Ловим паттерн [\][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]):
|
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]))
|
c, _ := strconv.Atoi(string(temp[i+2]))
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
b.WriteString(strings.Repeat(string(temp[i+1]), c))
|
b.WriteString(strings.Repeat(string(temp[i+1]), c))
|
||||||
i += 2
|
i += 2
|
||||||
// Ловим паттерн [\][digit или \]
|
// Ловим паттерн [\][digit или \]
|
||||||
|
@ -37,10 +31,7 @@ func Unpack(str string) (string, error) {
|
||||||
b.WriteRune(temp[i+1])
|
b.WriteRune(temp[i+1])
|
||||||
i++
|
i++
|
||||||
case unicode.IsLetter(temp[i]) && i < len(temp)-1 && unicode.IsDigit(temp[i+1]):
|
case unicode.IsLetter(temp[i]) && i < len(temp)-1 && unicode.IsDigit(temp[i+1]):
|
||||||
c, err := strconv.Atoi(string(temp[i+1]))
|
c, _ := strconv.Atoi(string(temp[i+1]))
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
b.WriteString(strings.Repeat(string(temp[i]), c))
|
b.WriteString(strings.Repeat(string(temp[i]), c))
|
||||||
i++
|
i++
|
||||||
// Ловим паттерн [letter]...
|
// Ловим паттерн [letter]...
|
||||||
|
|
Loading…
Reference in New Issue