From baf65d886fc516df4df820b448d4a262f9c5efc7 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Wed, 17 Aug 2022 10:34:14 +0200 Subject: [PATCH] Add more String extensions --- .../Extensions/String+Extensions.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/WebsiteGenerator/Extensions/String+Extensions.swift b/WebsiteGenerator/Extensions/String+Extensions.swift index f5fba0c..54d59e9 100644 --- a/WebsiteGenerator/Extensions/String+Extensions.swift +++ b/WebsiteGenerator/Extensions/String+Extensions.swift @@ -36,4 +36,20 @@ extension String { let parts = components(separatedBy: separator) return parts.dropLast().joined(separator: separator) + content + separator + parts.last! } + + func dropAfterFirst(_ separator: T) -> String where T: StringProtocol { + components(separatedBy: separator).first! + } + + func between(_ start: String, and end: String) -> String { + dropBeforeFirst(start).dropAfterFirst(end) + } +} + +extension Substring { + + func between(_ start: String, and end: String) -> String { + components(separatedBy: start).last! + .components(separatedBy: end).first! + } }