Skip to content

Commit cf295f6

Browse files
committed
refactor(CocoaPods): Improve name / version parsing
Introduce a simpler parsing function that currently does not change functionality, but which will be enhanced in a following change to cover additional cases. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent cb2c560 commit cf295f6

File tree

1 file changed

+6
-5
lines changed
  • plugins/package-managers/cocoapods/src/main/kotlin

1 file changed

+6
-5
lines changed

plugins/package-managers/cocoapods/src/main/kotlin/CocoaPods.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ private const val LOCKFILE_FILENAME = "Podfile.lock"
229229

230230
private const val SCOPE_NAME = "dependencies"
231231

232-
private val NAME_AND_VERSION_REGEX = "(\\S+)\\s+(.*)".toRegex()
232+
private fun parseNameAndVersion(entry: String): Pair<String, String?> {
233+
val info = entry.split(' ', limit = 2)
234+
return info[0] to info.getOrNull(1)?.removeSurrounding("(", ")")
235+
}
233236

234237
private fun getPackageReferences(podfileLock: File): Set<PackageReference> {
235238
val versionForName = mutableMapOf<String, String>()
@@ -245,10 +248,8 @@ private fun getPackageReferences(podfileLock: File): Set<PackageReference> {
245248
else -> node.textValue()
246249
}
247250

248-
val (name, version) = NAME_AND_VERSION_REGEX.find(entry)!!.groups.let {
249-
it[1]!!.value to it[2]!!.value.removeSurrounding("(", ")")
250-
}
251-
versionForName[name] = version
251+
val (name, version) = parseNameAndVersion(entry)
252+
versionForName[name] = checkNotNull(version)
252253

253254
val dependencies = node[entry]?.map { it.textValue().substringBefore(" ") }.orEmpty()
254255
dependenciesForName.getOrPut(name) { mutableSetOf() } += dependencies

0 commit comments

Comments
 (0)