Skip to content

Commit

Permalink
Merge pull request #3 from yasmanets/bugfix/check_empty_values
Browse files Browse the repository at this point in the history
should check empty valueas
  • Loading branch information
yasmanets authored Jul 24, 2022
2 parents de60d78 + 439cc73 commit 0bc31b9
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ fun VCard.getDataFromVCF(vcf: String): VCard {

if (line.contains("EMAIL")) {
val values = line.split(":")
if (values[1].isEmpty()) {
continue
}

this.setEmail(values[1])
continue
}
Expand All @@ -67,6 +71,10 @@ fun VCard.getDataFromVCF(vcf: String): VCard {
val values = line.split(";")
val phone = values[1].split(":")[1]

if (phone.isEmpty()) {
continue
}

var type = VCard.TYPE.WORK
if (values[1].contains(VCard.TYPE.HOME.value)) {
type = VCard.TYPE.HOME
Expand All @@ -77,24 +85,36 @@ fun VCard.getDataFromVCF(vcf: String): VCard {

if (line.contains("TITLE")) {
val title = line.split(":")[1]
if (title.isEmpty()) {
continue
}
this.setTitle(title)
continue
}

if (line.contains("ROLE")) {
val role = line.split(":")[1]
if (role.isEmpty()) {
continue
}
this.setRole(role)
continue
}

if (line.contains("ORG")) {
val organization = line.split(":")[1]
if (organization.isEmpty()) {
continue
}
this.setOrganization(organization)
continue
}

if (line.contains("URL") && line.contains("TYPE=WORK")) {
val organizationUrl = line.slice(line.indexOf(":", 0) + 1 until line.length)
if (organizationUrl.isEmpty()) {
continue
}
this.setOrganizationUrl(organizationUrl)
continue
}
Expand All @@ -104,6 +124,10 @@ fun VCard.getDataFromVCF(vcf: String): VCard {
val firstValues = values[0].split(";")
val addressValues = values[1].split(";").filter { it.isNotEmpty() }

if (addressValues.isEmpty()) {
continue
}

val type = if (firstValues[firstValues.size - 1] == VCard.TYPE.WORK.value) VCard.TYPE.WORK else VCard.TYPE.HOME
val address = Address()
address.setStreet(addressValues[0])
Expand All @@ -117,12 +141,18 @@ fun VCard.getDataFromVCF(vcf: String): VCard {

if (line.contains("URL")) {
val url = line.slice(line.indexOf(":", 0) + 1 until line.length)
if (url.isEmpty()) {
continue
}
urls.add(url)
continue
}

if (line.contains("ABLABEL")) {
val values = line.split(":")
if (values.isEmpty()) {
continue
}
labels.add(values[1])
continue
}
Expand Down

0 comments on commit 0bc31b9

Please sign in to comment.