Skip to content

Commit

Permalink
Merge pull request #142 from Revolyssup/addfunc
Browse files Browse the repository at this point in the history
Fix title and export function
  • Loading branch information
leecalcote authored Jan 8, 2022
2 parents 871204c + fd91449 commit 99c1ef0
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions utils/manifests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func getSchema(crd string, fp string, binPath string, cfg Config) (string, error
inputFormat = "json"
}

crdname := strings.ToLower(crd)
var (
out bytes.Buffer
er bytes.Buffer
Expand Down Expand Up @@ -119,7 +118,7 @@ func getSchema(crd string, fp string, binPath string, cfg Config) (string, error
if len(schema) == 0 {
return "", nil
}
(schema)[0]["title"] = formatToReadableString(crdname)
(schema)[0]["title"] = FormatToReadableString(crd)
var output []byte
output, err := json.MarshalIndent(schema[0], "", " ")
if err != nil {
Expand Down Expand Up @@ -283,7 +282,7 @@ func deleteFile(path string) error {

//While going from Capital letter to small, insert a whitespace before the capital letter.
//While going from small letter to capital, insert a whitespace after the small letter
func formatToReadableString(input string) string {
func FormatToReadableString(input string) string {
if len(input) == 0 {
return ""
}
Expand All @@ -293,25 +292,34 @@ func formatToReadableString(input string) string {
break
}
switch switchedCasing(input[i], input[i+1]) {
case 0:
case samegroup:
finalWord += string(input[i])
case 1:
case smallToBig:
finalWord += string(input[i]) + " "
case -1:
case bigToSmall:
finalWord += " " + string(input[i])
}
}
return strings.Join(strings.Fields(strings.TrimSpace(finalWord+input[len(input)-1:])), " ")
}

const (
samegroup = 0
smallToBig = 1
bigToSmall = -1
)

//switchedCasting returns 0 if a and b are both small, or both Capital letter.
//returns 1 when a is small, but b is capital
//returns -1 otherwise
func switchedCasing(a byte, b byte) int {
aisSmall := int(a) >= 97 && int(a) <= 122
bisSmall := int(b) >= 97 && int(b) <= 122
if aisSmall && !bisSmall {
return 1
return smallToBig
}
if bisSmall && !aisSmall {
return -1
return bigToSmall
}
return 0
return samegroup
}

0 comments on commit 99c1ef0

Please sign in to comment.