func returnLastInstance()

in helpers/windows/pdh/pdh_query_windows.go [298:326]


func returnLastInstance(match string) string {
	var openedParanth int
	var innerMatch string
	var matches []string
	runeMatch := []rune(match)
	for i := 0; i < len(runeMatch); i++ {
		char := string(runeMatch[i])

		// check if string ends between parentheses
		if char == ")" {
			openedParanth -= 1
		}
		if openedParanth > 0 {
			innerMatch += char
		}
		if openedParanth == 0 && innerMatch != "" {
			matches = append(matches, innerMatch)
			innerMatch = ""
		}
		// check if string starts between parentheses
		if char == "(" {
			openedParanth += 1
		}
	}
	if len(matches) > 0 {
		return matches[len(matches)-1]
	}
	return match
}