Skip to content

Commit

Permalink
Merge pull request #12 from MohamedRejeb/kover
Browse files Browse the repository at this point in the history
Add Kover
  • Loading branch information
MohamedRejeb authored Jun 15, 2023
2 parents c5e56b6 + 4247949 commit 250bed2
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 64 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Ksoup is a lightweight Kotlin Multiplatform library for parsing HTML, extracting HTML tags, attributes, and text, and encoding and decoding HTML entities.

[![Kotlin](https://img.shields.io/badge/kotlin-1.8.20-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-1.8.22-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![MohamedRejeb](https://raw.githubusercontent.com/MohamedRejeb/MohamedRejeb/main/badges/mohamedrejeb.svg)](https://github.com/MohamedRejeb)
[![Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)
[![BuildPassing](https://shields.io/badge/build-passing-brightgreen)](https://github.com/MohamedRejeb/ksoup/actions)
Expand All @@ -27,7 +27,7 @@ Ksoup is a lightweight Kotlin Multiplatform library for parsing HTML, extracting
Add the dependency below to your **module**'s `build.gradle.kts` or `build.gradle` file:

```kotlin
val version = "0.1.2"
val version = "0.1.3"

// For parsing HTML
implementation("com.mohamedrejeb.ksoup:ksoup-html:$version")
Expand Down
16 changes: 5 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
buildscript {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}

dependencies {
classpath(libs.bundles.plugins)
}
plugins {
alias(libs.plugins.multiplatform).apply(false)
alias(libs.plugins.kotlinx.kover).apply(false)
}

allprojects {
Expand All @@ -17,10 +10,11 @@ allprojects {
}

group = "com.mohamedrejeb.ksoup"
version = "0.1.2"
version = "0.1.3"

apply(plugin = "maven-publish")
apply(plugin = "signing")
apply(plugin = "org.jetbrains.kotlinx.kover")

extensions.configure<PublishingExtension> {
repositories {
Expand Down
8 changes: 7 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
[versions]
plugin-kotlin = "1.8.20"
plugin-kotlin = "1.8.22"
kotlin = "1.8.22"
kotlinx-kover = "0.7.1"

[libraries]
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "plugin-kotlin" }

[plugins]
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinx-kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kotlinx-kover" }

[bundles]
plugins = [
"plugin-kotlin",
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 6 additions & 6 deletions ksoup-entites/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ kotlin {
iosSimulatorArm64()
tvosX64()
tvosArm64()
// tvosSimulatorArm64()
tvosSimulatorArm64()
watchosX64()
watchosArm64()
// watchosSimulatorArm64()
watchosSimulatorArm64()
linuxX64()
macosX64()
macosArm64()
Expand All @@ -47,10 +47,10 @@ kotlin {
val iosSimulatorArm64Main by getting
val tvosX64Main by getting
val tvosArm64Main by getting
// val tvosSimulatorArm64Main by getting
val tvosSimulatorArm64Main by getting
val watchosX64Main by getting
val watchosArm64Main by getting
// val watchosSimulatorArm64Main by getting
val watchosSimulatorArm64Main by getting
val linuxX64Main by getting
val macosX64Main by getting
val macosArm64Main by getting
Expand All @@ -67,11 +67,11 @@ kotlin {
tvosMain.dependsOn(nativeMain)
tvosX64Main.dependsOn(tvosMain)
tvosArm64Main.dependsOn(tvosMain)
// tvosSimulatorArm64Main.dependsOn(tvosMain)
tvosSimulatorArm64Main.dependsOn(tvosMain)
watchosMain.dependsOn(nativeMain)
watchosX64Main.dependsOn(watchosMain)
watchosArm64Main.dependsOn(watchosMain)
// watchosSimulatorArm64Main.dependsOn(watchosMain)
watchosSimulatorArm64Main.dependsOn(watchosMain)
linuxMain.dependsOn(nativeMain)
linuxX64Main.dependsOn(linuxMain)
macosMain.dependsOn(nativeMain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public object KsoupEntities {
* `&quot;bread&quot; &amp;amp; &quot;butter&quot;`.
*
* Supports all known HTML 4.0 entities, including funky accents.
* Support that the commonly used apostrophe encode character (&amp;apos;)
* Support for the commonly used apostrophe encode character (&amp;apos;)
*
* @param input the `String` to encode
* @return a new encoded `String`
Expand Down Expand Up @@ -199,7 +199,7 @@ public object KsoupEntities {
* `&quot;bread&quot; &amp;amp; &quot;butter&quot;`.
*
* Supports all known HTML 4.0 entities, including funky accents.
* Support that the commonly used apostrophe encode character (&amp;apos;)
* Support for the commonly used apostrophe encode character (&amp;apos;)
*
* @param input the `String` to encode
* @return a new encoded `String`
Expand All @@ -219,7 +219,7 @@ public object KsoupEntities {
* `&quot;bread&quot; &amp;amp; &quot;butter&quot;`.
*
* Supports all known HTML 4.0 entities, including funky accents.
* Support that the commonly used apostrophe encode character (&amp;apos;)
* Support for the commonly used apostrophe encode character (&amp;apos;)
*
* @param input String that is being translated
* @param offset Int representing the current point of translation
Expand All @@ -246,14 +246,6 @@ public object KsoupEntities {
*
* XML 1.1 can represent certain control characters, but it cannot represent
* the null byte or unpaired Unicode surrogate code points, even after escaping.
* `encodeXml11` will remove characters that do not fit in the following
* ranges:
*
* `[#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]`
*
* `encodeXml11` will encode characters in the following ranges:
*
* `[#x1-#x8] | [#xB-#xC] | [#xE-#x1F] | [#x7F-#x84] | [#x86-#x9F]`
*
* The returned string can be inserted into a valid XML 1.1 document. Do not
* use it for XML 1.0 documents.
Expand All @@ -269,7 +261,7 @@ public object KsoupEntities {
/**
* Decodes a string containing entity encodes to a string
* containing the actual Unicode characters corresponding to the
* encodes. Supports HTML 4.0 entities.
* encoding. Supports HTML 4.0 entities.
*
* Example:
*
Expand Down Expand Up @@ -299,7 +291,8 @@ public object KsoupEntities {
/**
* Decodes a string containing entity encodes to a string
* containing the actual Unicode characters corresponding to the
* encodes. Supports HTML 4.0 entities.
* encoding.
* Supports HTML 4.0 entities.
*
* Example:
*
Expand Down Expand Up @@ -328,7 +321,8 @@ public object KsoupEntities {
/**
* Decodes a string containing entity encodes to a string
* containing the actual Unicode characters corresponding to the
* encodes. Supports HTML 4.0 entities.
* encoding.
* Supports HTML 4.0 entities.
*
* Example:
*
Expand Down Expand Up @@ -357,7 +351,7 @@ public object KsoupEntities {
/**
* Decodes a string containing XML entity encodes to a string
* containing the actual Unicode characters corresponding to the
* encodes.
* encoding.
*
*
* Supports only the five basic XML entities (gt, lt, quot, amp, apos).
Expand All @@ -369,7 +363,6 @@ public object KsoupEntities {
*
* @param input the `String` to decode
* @return a new decoded `String`
* @see [encodeXml10]
* @see [encodeXml]
*/
public fun decodeXml(input: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class LookupTranslator(lookupMap: Map<String, String>) : StringTranslat
var currentShortest = Int.MAX_VALUE
var currentLongest = 0
for ((key, value) in lookupMap) {
this.lookupMap[key.toString()] = value.toString()
this.lookupMap[key] = value
prefixSet.add(key[0].code.toUShort())
val sz = key.length
if (sz < currentShortest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal abstract class StringTranslator {
}
continue
}
// contract with translators is that they have to understand code points
// contract with translators is that they have to understand code points,
// and they just took care of a surrogate pair
for (pt in 0 until consumed) {
pos++
Expand All @@ -74,11 +74,4 @@ internal abstract class StringTranslator {
val newArray = arrayOf(this, *translators)
return AggregateTranslator(*newArray)
}

// companion object {
// /**
// * Array containing the hexadecimal alphabet.
// */
// val HEX_DIGITS = charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
// }
}
12 changes: 6 additions & 6 deletions ksoup-html/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ kotlin {
iosSimulatorArm64()
tvosX64()
tvosArm64()
// tvosSimulatorArm64()
tvosSimulatorArm64()
watchosX64()
watchosArm64()
// watchosSimulatorArm64()
watchosSimulatorArm64()
linuxX64()
macosX64()
macosArm64()
Expand Down Expand Up @@ -48,10 +48,10 @@ kotlin {
val iosSimulatorArm64Main by getting
val tvosX64Main by getting
val tvosArm64Main by getting
// val tvosSimulatorArm64Main by getting
val tvosSimulatorArm64Main by getting
val watchosX64Main by getting
val watchosArm64Main by getting
// val watchosSimulatorArm64Main by getting
val watchosSimulatorArm64Main by getting
val linuxX64Main by getting
val macosX64Main by getting
val macosArm64Main by getting
Expand All @@ -68,11 +68,11 @@ kotlin {
tvosMain.dependsOn(nativeMain)
tvosX64Main.dependsOn(tvosMain)
tvosArm64Main.dependsOn(tvosMain)
// tvosSimulatorArm64Main.dependsOn(tvosMain)
tvosSimulatorArm64Main.dependsOn(tvosMain)
watchosMain.dependsOn(nativeMain)
watchosX64Main.dependsOn(watchosMain)
watchosArm64Main.dependsOn(watchosMain)
// watchosSimulatorArm64Main.dependsOn(watchosMain)
watchosSimulatorArm64Main.dependsOn(watchosMain)
linuxMain.dependsOn(nativeMain)
linuxX64Main.dependsOn(linuxMain)
macosMain.dependsOn(nativeMain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlOptions
import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlParser

/**
* KsoupTokenizer is a HTML Tokenizer which is able to receive HTML string, breaks it up into individual tokens, and return those token with the [Callbacks]
* KsoupTokenizer is an HTML Tokenizer which is able to receive HTML string,
* breaks it up into individual tokens, and return those tokens with the [Callbacks]
*
* @param options KsoupHtmlOptions
*
Expand All @@ -27,15 +28,19 @@ internal class KsoupTokenizer(
private var index = 0
/** The start of the last entity. */
private var entityStart = 0
/** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
/**
* Some behavior, e.g., When decoding entities, is done while we are in another state.
* This keeps track of the other state type.
*/
private var baseState = State.Text
/** For special parsing behavior inside of script and style tags. */
/** For special parsing behavior inside script and style tags. */
private var isSpecial = false
/** Indicates whether the tokenizer has been paused. */
public var running: Boolean = true
/** The offset of the current buffer. */
private var offset = 0

@OptIn(ExperimentalUnsignedTypes::class)
fun reset() {
this.state = State.Text
this.buffer = ""
Expand Down Expand Up @@ -147,7 +152,7 @@ internal class KsoupTokenizer(
this.startEntity()
}
} else if (this.fastForwardTo(CharCodes.Lt.code)) {
// Outside of <title> tags, we can fast-forward.
// Outside <title> tags, we can fast-forward.
this.sequenceIndex = 1
}
} else {
Expand All @@ -168,7 +173,7 @@ internal class KsoupTokenizer(
} else {
this.sequenceIndex = 0
this.state = State.InDeclaration
this.stateInDeclaration(c) // Reconsume the character
this.stateInDeclaration(c) // Re-Consume the character
}
}

Expand Down Expand Up @@ -262,7 +267,7 @@ internal class KsoupTokenizer(
if (c == CharCodes.ExclamationMark.code) {
state = State.BeforeDeclaration
sectionStart = index + 1
} else if (c == CharCodes.Questionmark.code) {
} else if (c == CharCodes.QuestionMark.code) {
state = State.InProcessingInstruction
sectionStart = index + 1
} else if (isTagStartChar(c)) {
Expand Down Expand Up @@ -389,7 +394,7 @@ internal class KsoupTokenizer(
} else if (!isWhitespace(c)) {
this.sectionStart = this.index
this.state = State.InAttributeValueNq
this.stateInAttributeValueNoQuotes(c) // Reconsume token
this.stateInAttributeValueNoQuotes(c) // Re-Consume token
}
}

Expand Down Expand Up @@ -480,7 +485,7 @@ internal class KsoupTokenizer(
}
} else if (c != currentSequence[sequenceIndex].toInt()) {
state = State.InTagName
stateInTagName(c) // Reconsume the character
stateInTagName(c) // Re-Consume the character
}
}
}
Expand Down Expand Up @@ -534,7 +539,7 @@ internal class KsoupTokenizer(
* Remove data that has already been consumed from the buffer.
*/
private fun cleanup() {
// If we are inside of text or attributes, emit what we already have.
// If we are inside text or attributes, emit what we already have.
if (this.running && this.sectionStart != this.index) {
if (
this.state == State.Text ||
Expand Down Expand Up @@ -712,7 +717,7 @@ internal class KsoupTokenizer(
Lt(0x3c), // "<"
Eq(0x3d), // "="
Gt(0x3e), // ">"
Questionmark(0x3f), // "?"
QuestionMark(0x3f), // "?"
UpperA(0x41), // "A"
LowerA(0x61), // "a"
UpperF(0x46), // "F"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class KsoupHtmlParserTest {
var comment = ""
val handler = KsoupHtmlHandler
.Builder()
.onOpenTag { name, attributes, isImplied ->
.onOpenTag { name, _, _ ->
openTagsList.add(name)
unclosedTagList.add(name)
}
Expand All @@ -34,7 +34,7 @@ class KsoupHtmlParserTest {

string += text
}
.onCloseTag { name, isImplied ->
.onCloseTag { name, _ ->
assertEquals(
unclosedTagList.removeLast(),
name
Expand Down

0 comments on commit 250bed2

Please sign in to comment.