Skip to content

Commit

Permalink
Merge pull request #5 from skiptools/strings
Browse files Browse the repository at this point in the history
String API fixes
  • Loading branch information
aabewhite authored Sep 30, 2024
2 parents dc7cf3a + 4ec65d9 commit 00422a0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ Support levels:
<li><code>init(_: String)</code></li>
<li><code>var isNewline: Bool</code></li>
<li><code>var isWhitespace: Bool</code></li>
<li><code>var isUppercase: Bool</code></li>
<li><code>var isLowercase: Bool</code></li>
<li><code>func lowercased() -> String</code></li>
<li><code>func uppercased() -> String</code></li>
</ul>
Expand Down
2 changes: 2 additions & 0 deletions Sources/SkipLib/Skip/Collections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions Sources/SkipLib/Skip/String.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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()

Expand Down
2 changes: 0 additions & 2 deletions Sources/SkipLib/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,10 @@ public struct Character {
fatalError()
}

@available(*, unavailable)
public var isUppercase: Bool {
fatalError()
}

@available(*, unavailable)
public var isLowercase: Bool {
fatalError()
}
Expand Down

0 comments on commit 00422a0

Please sign in to comment.