From 4ec65d9fcad0651eb1ef1474770918bd0e7e2820 Mon Sep 17 00:00:00 2001 From: Abe White Date: Mon, 30 Sep 2024 11:47:06 -0500 Subject: [PATCH] String API fixes --- README.md | 2 ++ Sources/SkipLib/Skip/Collections.kt | 2 ++ Sources/SkipLib/Skip/String.kt | 10 +++++++--- Sources/SkipLib/String.swift | 2 -- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 20e7ef1..02ecdcd 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,8 @@ Support levels:
  • init(_: String)
  • var isNewline: Bool
  • var isWhitespace: Bool
  • +
  • var isUppercase: Bool
  • +
  • var isLowercase: Bool
  • func lowercased() -> String
  • func uppercased() -> String
  • diff --git a/Sources/SkipLib/Skip/Collections.kt b/Sources/SkipLib/Skip/Collections.kt index d5df107..f61d9ee 100644 --- a/Sources/SkipLib/Skip/Collections.kt +++ b/Sources/SkipLib/Skip/Collections.kt @@ -775,6 +775,8 @@ val IntRange.upperBound: Int get() = if (endInclusive == Int.MAX_VALUE) Int.MAX_VALUE else endInclusive + 1 val IntRange.lowerBound: Int get() = start +val IntRange.isEmpty: Boolean + get() = isEmpty() // IntRange.isEmpty, IntRange.contains can be used as-is diff --git a/Sources/SkipLib/Skip/String.kt b/Sources/SkipLib/Skip/String.kt index f16f851..3a44824 100644 --- a/Sources/SkipLib/Skip/String.kt +++ b/Sources/SkipLib/Skip/String.kt @@ -39,8 +39,8 @@ fun String(repeating: String, count: Int): String { // Swift.String API fun String.lowercased(): String = lowercase() fun String.uppercased(): String = uppercase() -fun Substring.lowercased(): Substring = Substring(stringValue.lowercased(), startIndex) -fun Substring.uppercased(): Substring = Substring(stringValue.uppercase(), startIndex) +fun Substring.lowercased(): String = stringValue.lowercased() +fun Substring.uppercased(): String = stringValue.uppercase() fun String.hasPrefix(prefix: String): Boolean = startsWith(prefix) fun String.hasPrefix(prefix: Substring): Boolean = startsWith(prefix.stringValue) @@ -58,7 +58,7 @@ fun Substring.contains(string: String): Boolean = stringValue.contains(string) fun Substring.contains(string: Substring): Boolean = stringValue.contains(string) // String.plus(Any?) used as-is -operator fun Substring.plus(string: Any): Substring = Substring(string.toString(), startIndex) +operator fun Substring.plus(string: Any): String = stringValue + string // MARK: - Sequence @@ -511,6 +511,10 @@ val Char.isNewline: Boolean else -> false } +val Char.isUppercase: Boolean + get() = isUpperCase() +val Char.isLowercase: Boolean + get() = isLowerCase() fun Char.uppercased(): String = toString().uppercased() fun Char.lowercased(): String = toString().lowercased() diff --git a/Sources/SkipLib/String.swift b/Sources/SkipLib/String.swift index d641dac..3341ad4 100644 --- a/Sources/SkipLib/String.swift +++ b/Sources/SkipLib/String.swift @@ -189,12 +189,10 @@ public struct Character { fatalError() } - @available(*, unavailable) public var isUppercase: Bool { fatalError() } - @available(*, unavailable) public var isLowercase: Bool { fatalError() }