Skip to content

Commit

Permalink
Stable ..< operator for open-ended ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jul 11, 2023
1 parent 419a3ca commit 008fcae
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AccountPagerAdapter(
}

fun refreshContent() {
for (i in 0 until TAB_COUNT) {
for (i in 0..<TAB_COUNT) {
val fragment = getFragment(i)
if (fragment != null && fragment is RefreshableFragment) {
(fragment as RefreshableFragment).refreshContent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ class ComposeActivity :
if (contentInfo.clip.description.hasMimeType("image/*")) {
val split = contentInfo.partition { item: ClipData.Item -> item.uri != null }
split.first?.let { content ->
for (i in 0 until content.clip.itemCount) {
for (i in 0..<content.clip.itemCount) {
pickMedia(
content.clip.getItemAt(i).uri,
contentInfo.clip.description.label as String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class TimelineFragment :
private fun setupRecyclerView() {
binding.recyclerView.setAccessibilityDelegateCompat(
ListStatusAccessibilityDelegate(binding.recyclerView, this) { pos ->
if (pos in 0 until adapter.itemCount) {
if (pos in 0..<adapter.itemCount) {
adapter.peek(pos)
} else {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ViewEditsViewModel @Inject constructor(private val api: MastodonApi) : Vie
var previousContent =
loader.load(sortedEdits[1].content.replace("<br>", "<br/>"))

for (i in 1 until sortedEdits.size) {
for (i in 1..<sortedEdits.size) {
processor.diff(previousContent, currentContent, output)
sortedEdits[i - 1] = sortedEdits[i - 1].copy(
content = output.xml.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private fun padInt(buffer: StringBuilder, value: Int, length: Int) {
* Returns the index of the first character in the string that is not a digit, starting at offset.
*/
private fun indexOfNonDigit(string: String, offset: Int): Int {
for (i in offset until string.length) {
for (i in offset..<string.length) {
val c = string[i]
if (c < '0' || c > '9') return i
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object BlurHashDecoder {

private fun decode83(str: String, from: Int = 0, to: Int = str.length): Int {
var result = 0
for (i in from until to) {
for (i in from..<to) {
val index = charMap[str[i]] ?: -1
if (index != -1) {
result = result * 83 + index
Expand Down Expand Up @@ -90,13 +90,13 @@ object BlurHashDecoder {
colors: Array<FloatArray>
): Bitmap {
val imageArray = IntArray(width * height)
for (y in 0 until height) {
for (x in 0 until width) {
for (y in 0..<height) {
for (x in 0..<width) {
var r = 0f
var g = 0f
var b = 0f
for (j in 0 until numCompY) {
for (i in 0 until numCompX) {
for (j in 0..<numCompY) {
for (i in 0..<numCompX) {
val basis = (cos(PI * x * i / width) * cos(PI * y * j / height)).toFloat()
val color = colors[j * numCompX + i]
r += color[0] * basis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ListStatusAccessibilityDelegate(
R.id.action_open_media_4
)
val attachmentCount = min(actionable.attachments.size, MAX_MEDIA_ATTACHMENTS)
for (i in 0 until attachmentCount) {
for (i in 0..<attachmentCount) {
info.addAction(
AccessibilityActionCompat(
mediaActions[i],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private const val TAG: String = "LocaleUtils"

private fun LocaleListCompat.toList(): List<Locale> {
val list = mutableListOf<Locale>()
for (index in 0 until this.size()) {
for (index in 0..<this.size()) {
this[index]?.let { list.add(it) }
}
return list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun deserialize(data: String?): Set<Notification.Type> {
val ret = HashSet<Notification.Type>()
data?.let {
val array = JSONArray(data)
for (i in 0 until array.length()) {
for (i in 0..<array.length()) {
val item = array.getString(i)
val type = Notification.Type.byString(item)
if (type != Notification.Type.UNKNOWN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PickMediaFiles : ActivityResultContract<Boolean, List<Uri>>() {
return listOf(intentData)
} else if (clipData != null) {
val result: MutableList<Uri> = mutableListOf()
for (i in 0 until clipData.itemCount) {
for (i in 0..<clipData.itemCount) {
result.add(clipData.getItemAt(i).uri)
}
return result
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/keylesspalace/tusky/util/SpanUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ fun highlightSpans(text: Spannable, colour: Int) {
val length = text.length
var start = 0
var end = 0
while (end in 0 until length && start >= 0) {
while (end in 0..<length && start >= 0) {
// Search for url first because it can contain the other characters
val found = findPattern(string, end)
start = found.start
end = found.end
if (start in 0 until end) {
if (start in 0..<end) {
text.setSpan(getSpan(found.matchType, string, colour, start, end), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
start += finders[found.matchType]!!.searchPrefixWidth
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun replaceCrashingCharacters(content: CharSequence): CharSequence? {
var replacing = false
var builder: SpannableStringBuilder? = null
val length = content.length
for (index in 0 until length) {
for (index in 0..<length) {
val character = content[index]

// If there are more than one or two, switch to a map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class StatusViewHelper(private val itemView: View) {

val n = min(attachments.size, Status.MAX_MEDIA_ATTACHMENTS)

for (i in 0 until n) {
for (i in 0..<n) {
val attachment = attachments[i]
val previewUrl = attachment.previewUrl
val description = attachment.description
Expand Down Expand Up @@ -210,7 +210,7 @@ class StatusViewHelper(private val itemView: View) {
}

// Hide any of the placeholder previews beyond the ones set.
for (i in n until Status.MAX_MEDIA_ATTACHMENTS) {
for (i in n..<Status.MAX_MEDIA_ATTACHMENTS) {
mediaPreviews[i].visibility = View.GONE
}
}
Expand Down Expand Up @@ -313,7 +313,7 @@ class StatusViewHelper(private val itemView: View) {
private fun setupPollResult(poll: PollViewData, emojis: List<Emoji>, pollResults: List<TextView>, animateEmojis: Boolean) {
val options = poll.options

for (i in 0 until Status.MAX_POLL_OPTIONS) {
for (i in 0..<Status.MAX_POLL_OPTIONS) {
if (i < options.size) {
val percent = calculatePercent(options[i].votesCount, poll.votersCount, poll.votesCount)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private const val POSSIBLE_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
fun randomAlphanumericString(count: Int): String {
val chars = CharArray(count)
val random = Random()
for (i in 0 until count) {
for (i in 0..<count) {
chars[i] = POSSIBLE_CHARS[random.nextInt(POSSIBLE_CHARS.length)]
}
return String(chars)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class GraphView @JvmOverloads constructor(
val pointDistance = dataSpacing(primaryLineData)

// Vertical tick marks
for (i in 0 until primaryLineData.size + 1) {
for (i in 0..<primaryLineData.size + 1) {
drawLine(
i * pointDistance,
height.toFloat(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MediaPreviewLayout(context: Context, attrs: AttributeSet? = null) :

private fun attachImageViews() {
removeAllViews()
for (i in 0 until aspectRatios.size.coerceAtMost(imageViewCache.size)) {
for (i in 0..<aspectRatios.size.coerceAtMost(imageViewCache.size)) {
addView(imageViewCache[i])
}
}
Expand Down Expand Up @@ -185,7 +185,7 @@ class MediaPreviewLayout(context: Context, attrs: AttributeSet? = null) :
}

inline fun forEachIndexed(action: (Int, MediaPreviewImageView, TextView) -> Unit) {
for (index in 0 until childCount) {
for (index in 0..<childCount) {
val wrapper = getChildAt(index)
action(
index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class LocaleUtilsTest {
}

private fun getMockedInitialLanguages(configuredLanguages: Array<String?>): List<String> {
val appLanguages = LocaleListCompat.forLanguageTags(configuredLanguages.slice(2 until 4).joinToString(","))
val systemLanguages = LocaleListCompat.forLanguageTags(configuredLanguages.slice(4 until configuredLanguages.size).joinToString(","))
val appLanguages = LocaleListCompat.forLanguageTags(configuredLanguages.slice(2..<4).joinToString(","))
val systemLanguages = LocaleListCompat.forLanguageTags(configuredLanguages.slice(4..<configuredLanguages.size).joinToString(","))

Mockito.mockStatic(AppCompatDelegate::class.java).use { appCompatDelegate ->
appCompatDelegate.`when`<LocaleListCompat> { AppCompatDelegate.getApplicationLocales() }.thenReturn(appLanguages)
Expand Down

0 comments on commit 008fcae

Please sign in to comment.