File: common.go

package info (click to toggle)
golang-github-akosmarton-papipes 0.0~git20201027.3c63b49-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 88 kB
  • sloc: makefile: 4
file content (58 lines) | stat: -rw-r--r-- 990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package papipes

import (
	"errors"
	"os/exec"
	"strings"
)

func getModulesList() ([]string, error) {
	cmd := exec.Command("pactl", "list", "short", "modules")
	out, err := cmd.CombinedOutput()
	if err != nil {
		return nil, errors.New(string(out))
	}
	return strings.Split(string(out), "\n"), nil
}

func parseArguments(s string, quote rune) map[string]string {
	res := make(map[string]string)
	var key, value string
	var inKey, inValue, inQuoute bool
	inKey = true
	for _, r := range s {
		switch r {
		case '=':
			if inQuoute {
				value += string(r)
			} else {
				inValue = true
				inKey = false
			}
		case quote:
			if inQuoute {
				inQuoute = false
			} else {
				inQuoute = true
			}
		case ' ':
			if inQuoute {
				value += string(r)
			} else {
				inValue = false
				inKey = true
				res[key] = value
				key = ""
				value = ""
			}
		default:
			if inKey {
				key += string(r)
			} else if inValue {
				value += string(r)
			}
		}
	}
	res[key] = value
	return res
}