RLEdecode takes a run-length encoded string and returns the original string
(data string)
| 35 | |
| 36 | // RLEdecode takes a run-length encoded string and returns the original string |
| 37 | func RLEdecode(data string) string { |
| 38 | var result string |
| 39 | regex := regexp.MustCompile(`(\d+)(\w)`) |
| 40 | |
| 41 | for _, match := range regex.FindAllStringSubmatch(data, -1) { |
| 42 | num, _ := strconv.Atoi(match[1]) |
| 43 | result += strings.Repeat(match[2], num) |
| 44 | } |
| 45 | |
| 46 | return result |
| 47 | } |
| 48 | |
| 49 | // RLEncodebytes takes a byte slice and returns its run-length encoding as a byte slice |
| 50 | func RLEncodebytes(data []byte) []byte { |
no outgoing calls