From 2569f525526b1118c60ac3d93a44a9f58fe5f6f9 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Wed, 20 Nov 2024 01:04:31 -0500 Subject: [PATCH] Wrote toString function for MatchIndex --- matching.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/matching.go b/matching.go index 27313f5..9941059 100644 --- a/matching.go +++ b/matching.go @@ -1,6 +1,9 @@ package main -import "sort" +import ( + "fmt" + "sort" +) // a MatchIndex represents a match/group. It contains the start index and end index of the match type MatchIndex struct { @@ -8,10 +11,10 @@ type MatchIndex struct { endIdx int } -// A Match represents multiple matchIndices. Specifically, it maps an integer (representing the capturing group) -// to the matchIndex of that group. -// Group 0 corresponds to the entire match. -type Match map[int]MatchIndex +// Converts the MatchIndex into a string representation: +func (idx MatchIndex) toString() string { + return fmt.Sprintf("%d\t%d", idx.startIdx, idx.endIdx) +} // takeZeroState takes the 0-state (if such a transition exists) for all states in the // given slice. It returns the resulting states. If any of the resulting states is a 0-state,