Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 2aca001

Browse files
committed
Refactor first name and last name extraction logic
1 parent a243e08 commit 2aca001

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

example/src/test/java/org/wordpress/android/fluxc/model/customer/WCCustomerMapperTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,6 @@ class WCCustomerMapperTest {
451451
val result = mapper.mapToModel(site, customerDTO)
452452

453453
// THEN
454-
assertEquals("and a very long last name", result.lastName)
454+
assertEquals("and a very long last name", result.lastName)
455455
}
456456
}

plugins/woocommerce/src/main/kotlin/org/wordpress/android/fluxc/model/customer/WCCustomerMapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ class WCCustomerMapper @Inject constructor() {
119119

120120
// Please refer WCCustomerMapperTest file which serves as documentation of how this function behaves.
121121
private fun String?.firstNameFromName(): String =
122-
this?.trim()?.replace("\\s+".toRegex(), " ")?.substringBefore(" ") ?: ""
122+
this?.trim()?.substringBefore(' ')?.trim().orEmpty()
123123

124124
private fun String?.lastNameFromName(): String =
125-
this?.trim()?.replace("\\s+".toRegex(), " ")?.substringAfter(" ", "") ?: ""
125+
this?.trim()?.substringAfter(' ', "")?.trim().orEmpty()
126126
}

0 commit comments

Comments
 (0)