~psic4t/qcard

3168b9573e0d40c99b6980ce2dff8d327f690148 — psic4t 6 months ago 45d09ac
support NICKNAME
5 files changed, 17 insertions(+), 1 deletions(-)

M README.md
M defines.go
M helpers.go
M main.go
M parse.go
M README.md => README.md +1 -0
@@ 75,6 75,7 @@ Here's a list of all attributes:
* **B:** Birthday
* **T:** Title
* **R:** Role
* **K:** Nickname
* **n:** Note

### Add new contact

M defines.go => defines.go +1 -0
@@ 66,6 66,7 @@ type contactStruct struct {
	addressHome  string
	addressWork  string
	birthday     string
	nickname     string
	note         string
}


M helpers.go => helpers.go +3 -0
@@ 176,6 176,9 @@ func (e contactStruct) fancyOutput() {
		if e.birthday != "" {
			fmt.Println(`  B: ` + e.birthday)
		}
		if e.nickname != "" {
			fmt.Println(`  B: ` + e.nickname)
		}
		if e.name != "" {
			fmt.Println(`  N: ` + e.name)
		}

M main.go => main.go +5 -1
@@ 122,6 122,7 @@ func createContact(abNo int, contactData string) {
	var organisation string
	var title string
	var role string
	var nickname string

	newUUID := genUUID()



@@ 161,6 162,8 @@ func createContact(abNo int, contactData string) {
				title = "\nTITLE:" + attr[1]
			case " R":
				role = "\nROLE:" + attr[1]
			case " K":
				role = "\nNICKNAME:" + attr[1]
			}
		}
	}


@@ 181,7 184,8 @@ UID:` + newUUID +
		organisation +
		note +
		title +
		role + `
		role +
		nickname + `
FN:` + fullName + `
N:` + name + `
REV:` + curTime.UTC().Format(IcsFormat) + `

M parse.go => parse.go +7 -0
@@ 98,6 98,12 @@ func parseContactRole(contactData *string) string {
	return trimField(result, "(?i)ROLE:")
}

func parseContactNickname(contactData *string) string {
	re, _ := regexp.Compile(`(?i)NICKNAME:.*?\n`)
	result := re.FindString(*contactData)
	return trimField(result, "(?i)NICKNAME:")
}

func parseMain(contactData *string, contactsSlice *[]contactStruct, href, color string) {
	//fmt.Println(parseContactName(contactData))
	fullName := parseContactFullName(contactData)


@@ 119,6 125,7 @@ func parseMain(contactData *string, contactsSlice *[]contactStruct, href, color 
			addressHome:  parseContactAddressHome(contactData),
			addressWork:  parseContactAddressWork(contactData),
			birthday:     parseContactBirthday(contactData),
			nickname:     parseContactNickname(contactData),
			note:         parseContactNote(contactData),
		}
		*contactsSlice = append(*contactsSlice, data)