Skip to content

Instantly share code, notes, and snippets.

@fallsimply
Created February 20, 2021 03:52
Show Gist options
  • Save fallsimply/5d24f4bb119ce733c4ac1ee47393c088 to your computer and use it in GitHub Desktop.
Save fallsimply/5d24f4bb119ce733c4ac1ee47393c088 to your computer and use it in GitHub Desktop.

Sample Custom Parser

func customLineParse(line string) (tokens []string) {
	var str strings.Builder
	line = strings.TrimPrefix(line, "|")
	for _, char := range line {
		switch char {
		case '|':
			token := strings.TrimSpace(str.String())
			tokens = append(tokens, token)
			str.Reset()
		default:
			str.WriteRune(char)
		}
	}
	return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment