HW2 is completed

pull/2/head
Andrey Ivanov 2020-06-10 15:01:14 +03:00
parent dfb22256a1
commit 3af00fd66b
2 changed files with 5 additions and 6 deletions

View File

@ -9,7 +9,7 @@ import (
var ErrInvalidString = errors.New("invalid string")
const slash = `\`
const slash = '\\'
func Unpack(str string) (string, error) {
var b strings.Builder
@ -17,17 +17,17 @@ func Unpack(str string) (string, error) {
for i := 0; i < len(temp); i++ {
switch {
// Ловим паттерн [\][letter][digit]
case string(temp[i]) == slash && i < len(temp)-2 && unicode.IsLetter(temp[i+1]) && unicode.IsDigit(temp[i+2]):
case temp[i] == slash && i < len(temp)-2 && unicode.IsLetter(temp[i+1]) && unicode.IsDigit(temp[i+2]):
c, _ := strconv.Atoi(string(temp[i+2]))
b.WriteString(strings.Repeat(slash+string(temp[i+1]), c))
b.WriteString(strings.Repeat(string(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]):
case temp[i] == slash && i < len(temp)-2 && (unicode.IsDigit(temp[i+1]) || temp[i+1] == slash) && unicode.IsDigit(temp[i+2]):
c, _ := strconv.Atoi(string(temp[i+2]))
b.WriteString(strings.Repeat(string(temp[i+1]), c))
i += 2
// Ловим паттерн [\][digit или \]
case string(temp[i]) == slash && i < len(temp)-1 && (unicode.IsDigit(temp[i+1]) || string(temp[i+1]) == slash):
case temp[i] == slash && i < len(temp)-1 && (unicode.IsDigit(temp[i+1]) || temp[i+1] == slash):
b.WriteRune(temp[i+1])
i++
case unicode.IsLetter(temp[i]) && i < len(temp)-1 && unicode.IsDigit(temp[i+1]):

View File

@ -76,7 +76,6 @@ func TestUnpack(t *testing.T) {
}
func TestUnpackWithEscape(t *testing.T) {
//t.Skip() // Remove if task with asterisk completed
for _, tst := range [...]test{
{