diff --git a/README.md b/README.md index 13c7b0d..5a08788 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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") diff --git a/build.gradle.kts b/build.gradle.kts index f602eba..e1fbaad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { @@ -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 { repositories { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9a960df..03805dc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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", diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ef62641..8f5ef1a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 \ No newline at end of file diff --git a/ksoup-entites/build.gradle.kts b/ksoup-entites/build.gradle.kts index b756f9a..50387b5 100644 --- a/ksoup-entites/build.gradle.kts +++ b/ksoup-entites/build.gradle.kts @@ -17,10 +17,10 @@ kotlin { iosSimulatorArm64() tvosX64() tvosArm64() -// tvosSimulatorArm64() + tvosSimulatorArm64() watchosX64() watchosArm64() -// watchosSimulatorArm64() + watchosSimulatorArm64() linuxX64() macosX64() macosArm64() @@ -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 @@ -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) diff --git a/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/KsoupEntities.kt b/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/KsoupEntities.kt index a44d447..4c8f84a 100644 --- a/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/KsoupEntities.kt +++ b/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/KsoupEntities.kt @@ -153,7 +153,7 @@ public object KsoupEntities { * `"bread" &amp; "butter"`. * * Supports all known HTML 4.0 entities, including funky accents. - * Support that the commonly used apostrophe encode character (&apos;) + * Support for the commonly used apostrophe encode character (&apos;) * * @param input the `String` to encode * @return a new encoded `String` @@ -199,7 +199,7 @@ public object KsoupEntities { * `"bread" &amp; "butter"`. * * Supports all known HTML 4.0 entities, including funky accents. - * Support that the commonly used apostrophe encode character (&apos;) + * Support for the commonly used apostrophe encode character (&apos;) * * @param input the `String` to encode * @return a new encoded `String` @@ -219,7 +219,7 @@ public object KsoupEntities { * `"bread" &amp; "butter"`. * * Supports all known HTML 4.0 entities, including funky accents. - * Support that the commonly used apostrophe encode character (&apos;) + * Support for the commonly used apostrophe encode character (&apos;) * * @param input String that is being translated * @param offset Int representing the current point of translation @@ -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. @@ -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: * @@ -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: * @@ -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: * @@ -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). @@ -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 { diff --git a/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/LookupTranslator.kt b/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/LookupTranslator.kt index b3226d7..520169c 100644 --- a/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/LookupTranslator.kt +++ b/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/LookupTranslator.kt @@ -23,7 +23,7 @@ internal class LookupTranslator(lookupMap: Map) : 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) { diff --git a/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/StringTranslator.kt b/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/StringTranslator.kt index 66984be..20fc619 100644 --- a/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/StringTranslator.kt +++ b/ksoup-entites/src/commonMain/kotlin/com/mohamedrejeb/ksoup/entities/StringTranslator.kt @@ -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++ @@ -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') -// } } \ No newline at end of file diff --git a/ksoup-html/build.gradle.kts b/ksoup-html/build.gradle.kts index cd3863d..005c0d1 100644 --- a/ksoup-html/build.gradle.kts +++ b/ksoup-html/build.gradle.kts @@ -17,10 +17,10 @@ kotlin { iosSimulatorArm64() tvosX64() tvosArm64() -// tvosSimulatorArm64() + tvosSimulatorArm64() watchosX64() watchosArm64() -// watchosSimulatorArm64() + watchosSimulatorArm64() linuxX64() macosX64() macosArm64() @@ -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 @@ -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) diff --git a/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/tokenizer/KsoupTokenizer.kt b/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/tokenizer/KsoupTokenizer.kt index 8c8f2ff..fd7c0ae 100644 --- a/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/tokenizer/KsoupTokenizer.kt +++ b/ksoup-html/src/commonMain/kotlin/com/mohamedrejeb/ksoup/html/tokenizer/KsoupTokenizer.kt @@ -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 * @@ -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 = "" @@ -147,7 +152,7 @@ internal class KsoupTokenizer( this.startEntity() } } else if (this.fastForwardTo(CharCodes.Lt.code)) { - // Outside of tags, we can fast-forward. + // Outside <title> tags, we can fast-forward. this.sequenceIndex = 1 } } else { @@ -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 } } @@ -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)) { @@ -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 } } @@ -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 } } } @@ -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 || @@ -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" diff --git a/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/KsoupHtmlParserTest.kt b/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/KsoupHtmlParserTest.kt index a113ef7..91849d1 100644 --- a/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/KsoupHtmlParserTest.kt +++ b/ksoup-html/src/commonTest/kotlin/com/mohamedrejeb/ksoup/html/KsoupHtmlParserTest.kt @@ -21,7 +21,7 @@ class KsoupHtmlParserTest { var comment = "" val handler = KsoupHtmlHandler .Builder() - .onOpenTag { name, attributes, isImplied -> + .onOpenTag { name, _, _ -> openTagsList.add(name) unclosedTagList.add(name) } @@ -34,7 +34,7 @@ class KsoupHtmlParserTest { string += text } - .onCloseTag { name, isImplied -> + .onCloseTag { name, _ -> assertEquals( unclosedTagList.removeLast(), name