mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Correct the article in generated documents
For example: "a Ingress" > "an Ingress"
This commit is contained in:
@@ -17,8 +17,10 @@ limitations under the License.
|
||||
package strings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// Splits a fully qualified name and returns its namespace and name.
|
||||
@@ -45,3 +47,30 @@ func ShortenString(str string, n int) string {
|
||||
return str[:n]
|
||||
}
|
||||
}
|
||||
|
||||
// GetArticleForNoun returns the article needed for the given noun.
|
||||
func GetArticleForNoun(noun string, padding string) string {
|
||||
if noun[len(noun)-2:] != "ss" && noun[len(noun)-1:] == "s" {
|
||||
// Plurals don't have an article.
|
||||
// Don't catch words like class
|
||||
return fmt.Sprintf("%v", padding)
|
||||
}
|
||||
|
||||
article := "a"
|
||||
if isVowel(rune(noun[0])) {
|
||||
article = "an"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%s%s", padding, article, padding)
|
||||
}
|
||||
|
||||
// isVowel returns true if the rune is a vowel (case insensitive).
|
||||
func isVowel(c rune) bool {
|
||||
vowels := []rune{'a', 'e', 'i', 'o', 'u'}
|
||||
for _, value := range vowels {
|
||||
if value == unicode.ToLower(c) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user