Skip to content

Commit

Permalink
lots of better names and types for repeatedly used map and slice types
Browse files Browse the repository at this point in the history
  • Loading branch information
mleku committed Jan 2, 2024
1 parent ee9e9c4 commit 70ee356
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 311 deletions.
29 changes: 13 additions & 16 deletions cmd/publicatr/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ const (
)

var (
urlRe = regexp.MustCompile(urlPattern)
mentionRe = regexp.MustCompile(mentionPattern)
emojiRe = regexp.MustCompile(emojiPattern)
urlRegexp = regexp.MustCompile(urlPattern)
mentionRegexp = regexp.MustCompile(mentionPattern)
emojiRegexp = regexp.MustCompile(emojiPattern)
)

type entry struct {
type matchLocation struct {
start int64
end int64
text string
}

func extractLinks(text string) []entry {
var result []entry
matches := urlRe.FindAllStringSubmatchIndex(text, -1)
func extractLinks(text string) (result []matchLocation) {
matches := urlRegexp.FindAllStringSubmatchIndex(text, -1)
for _, m := range matches {
result = append(result, entry{
result = append(result, matchLocation{
text: text[m[0]:m[1]],
start: int64(len([]rune(text[0:m[0]]))),
end: int64(len([]rune(text[0:m[1]])))},
Expand All @@ -36,11 +35,10 @@ func extractLinks(text string) []entry {
return result
}

func extractMentions(text string) []entry {
var result []entry
matches := mentionRe.FindAllStringSubmatchIndex(text, -1)
func extractMentions(text string) (result []matchLocation) {
matches := mentionRegexp.FindAllStringSubmatchIndex(text, -1)
for _, m := range matches {
result = append(result, entry{
result = append(result, matchLocation{
text: strings.TrimPrefix(text[m[0]:m[1]], "@"),
start: int64(len([]rune(text[0:m[0]]))),
end: int64(len([]rune(text[0:m[1]])))},
Expand All @@ -49,11 +47,10 @@ func extractMentions(text string) []entry {
return result
}

func extractEmojis(text string) []entry {
var result []entry
matches := emojiRe.FindAllStringSubmatchIndex(text, -1)
func extractEmojis(text string) (result []matchLocation) {
matches := emojiRegexp.FindAllStringSubmatchIndex(text, -1)
for _, m := range matches {
result = append(result, entry{
result = append(result, matchLocation{
text: text[m[0]:m[1]],
start: int64(len([]rune(text[0:m[0]]))),
end: int64(len([]rune(text[0:m[1]])))},
Expand Down
Loading

0 comments on commit 70ee356

Please sign in to comment.