package de.geeksfactory.opacclient.utils

import org.json.JSONObject
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.nodes.TextNode
import org.jsoup.select.Elements

val String.html: Document
    get() = Jsoup.parse(this)

val String.jsonObject: JSONObject
    get() = JSONObject(this)

operator fun Element.get(name: String): String = this.attr(name)

val Element.text: String
    get() = this.text()

val Elements.text: String
    get() = this.text()

val TextNode.text: String
    get() = this.text()
package de.geeksfactory.opacclient.utils

import org.json.JSONArray
import org.json.JSONObject
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.nodes.TextNode
import org.jsoup.select.Elements

val String.html: Document
    get() = Jsoup.parse(this)

val String.jsonObject: JSONObject
    get() = JSONObject(this)

operator fun Element.get(name: String): String = this.attr(name)

val Element.text: String
    get() = this.text()

val Elements.text: String
    get() = this.text()

val TextNode.text: String
    get() = this.text()

// JSONArray extension functions
inline fun <reified T, R> JSONArray.map(transform: (T) -> R): List<R> =
        (0..length()).map { i -> transform(get(i) as T) }

inline fun <reified T> JSONArray.forEach(function: (T) -> Unit) =
        (0..length()).forEach { i -> function(get(i) as T) }

Add some Kotlin extension functions to simplify handling of JSONArrays
Add some Kotlin extension functions to simplify handling of JSONArrays

opacapp/opacclient,opacapp/opacclient,opacapp/opacclient,opacapp/opacclient,raphaelm/opacclient,opacapp/opacclient,raphaelm/opacclient,raphaelm/opacclient