Skip to content

Commit

Permalink
🔨 Several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Jan 22, 2024
1 parent 20e0495 commit f6a4df4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/FoundationPlus/Extensions/Swift/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ public extension String {

/// The first word in the string.
var firstWord: String {
return components(separatedBy: " ").first ?? ""
return components(separatedBy: " ").first ?? self
}

/// The first word in the string.
var lastWord: String {
return components(separatedBy: " ").last ?? ""
return components(separatedBy: " ").last ?? self
}

/// Returns the string in possessive form; e.g. "Brenda" -> "Brenda's" or "Chris" -> "Chris'"
var possessive: String {
if last == "s" { return "'" } else { return "'s" }
}

// MARK: - Static Methods
Expand Down

0 comments on commit f6a4df4

Please sign in to comment.