forked from brianvoe/gofakeit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
word_helper.go
45 lines (38 loc) · 913 Bytes
/
word_helper.go
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
package gofakeit
import (
"strings"
)
// This will look at a few things to determine what kind of article to use for the word
func getArticle(word string) string {
// If nothing is passed return empty
if word == "" {
return ""
}
word = strings.ToLower(word)
letters := strings.Split(word, "")
firstLetter := ""
secondLetter := ""
if len(letters) > 0 {
firstLetter = letters[0]
}
if len(letters) > 1 {
secondLetter = letters[1]
}
// If the word starts with a, e, i, o, use an article
if firstLetter == "a" || firstLetter == "e" || firstLetter == "i" || firstLetter == "o" {
return "an"
}
// If the word starts with a u and n or l, use an article
if firstLetter == "u" {
if secondLetter == "n" || secondLetter == "l" {
return "an"
}
}
// If the word starts with a vowel, use an article
if firstLetter == "h" {
if secondLetter == "i" {
return "an"
}
}
return "a"
}