This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixcase.go
57 lines (50 loc) · 2.18 KB
/
fixcase.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
46
47
48
49
50
51
52
53
54
55
56
57
package forester
import (
"github.com/k0swe/adif-json-protobuf/go"
"strings"
)
func fixCase(qso *adifpb.Qso) {
qso.Mode = fixToUpper(qso.Mode)
qso.Band = fixToLower(qso.Band)
qso.BandRx = fixToLower(qso.BandRx)
qso.ContactedStation.Address = fixToTitle(qso.ContactedStation.Address)
qso.ContactedStation.StationCall = fixToUpper(qso.ContactedStation.StationCall)
qso.ContactedStation.Continent = fixToUpper(qso.ContactedStation.Continent)
qso.ContactedStation.OpCall = fixToUpper(qso.ContactedStation.OpCall)
qso.ContactedStation.Country = fixToTitle(qso.ContactedStation.Country)
qso.ContactedStation.Email = strings.TrimSpace(qso.ContactedStation.Email)
qso.ContactedStation.OwnerCall = fixToUpper(qso.ContactedStation.OwnerCall)
qso.ContactedStation.GridSquare = fixToUpper(qso.ContactedStation.GridSquare)
qso.ContactedStation.OpName = fixToTitle(qso.ContactedStation.OpName)
qso.ContactedStation.City = fixToTitle(qso.ContactedStation.City)
if len(qso.ContactedStation.State) < 3 {
// probably an abbreviation
qso.ContactedStation.State = fixToUpper(qso.ContactedStation.State)
} else {
// probably a proper name
qso.ContactedStation.State = fixToTitle(qso.ContactedStation.State)
}
qso.LoggingStation.City = fixToTitle(qso.LoggingStation.City)
qso.LoggingStation.Country = fixToTitle(qso.LoggingStation.Country)
qso.LoggingStation.GridSquare = fixToUpper(qso.LoggingStation.GridSquare)
qso.LoggingStation.OpName = fixToTitle(qso.LoggingStation.OpName)
if len(qso.LoggingStation.State) < 3 {
// probably an abbreviation
qso.LoggingStation.State = fixToUpper(qso.LoggingStation.State)
} else {
// probably a proper name
qso.LoggingStation.State = fixToTitle(qso.LoggingStation.State)
}
qso.LoggingStation.OpCall = fixToUpper(qso.LoggingStation.OpCall)
qso.LoggingStation.OwnerCall = fixToUpper(qso.LoggingStation.OwnerCall)
qso.LoggingStation.StationCall = fixToUpper(qso.LoggingStation.StationCall)
}
func fixToLower(str string) string {
return strings.TrimSpace(strings.ToLower(str))
}
func fixToUpper(str string) string {
return strings.TrimSpace(strings.ToUpper(str))
}
func fixToTitle(str string) string {
return strings.TrimSpace(strings.Title(strings.ToLower(str)))
}