Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ New DomainName type #340

Open
1 of 10 tasks
Tracked by #358 ...
LVMVRQUXL opened this issue Dec 14, 2023 · 0 comments
Open
1 of 10 tasks
Tracked by #358 ...

✨ New DomainName type #340

LVMVRQUXL opened this issue Dec 14, 2023 · 0 comments
Labels
common Item related to all platforms. feature New feature or request.

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented Dec 14, 2023

📝 Description

We would like to introduce an experimental type named DomainName, representing a domain name in the Internet, in the kotools.types.web package with the following minimum API:

interface DomainName {
    companion object {
        val regex: Regex // Should be inaccessible for Java sources due to the unavailability of 'kotlin.text.Regex' for this language.
        fun create(text: String): DomainName
        fun createOrNull(text: String): DomainName?
    }

    override fun equals(other: Any?): Boolean
    override fun hashCode(): Int
    override fun toString(): String
}

Data validation

Accordingly to the RFC-1035, a domain name should match the following regular expression: ^(?:[A-Za-z][A-Za-z\d-]{0,61}[A-Za-z\d]\.)*[A-Za-z][A-Za-z\d-]{0,61}[A-Za-z\d]$.

Here's the explanation associated to each symbol used in this regular expression:

  • ^ Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.
  • (?:) Non-capturing group. Groups multiple tokens together without creating a capture group.
  • [] Character set. Match any character in the set.
  • A-Z Range. Matches a character in the range "A" to "Z" (char code 65 to 90). Case sensitive.
  • a-z Range. Matches a character in the range "a" to "z" (char code 97 to 122). Case sensitive.
  • \d Digit. Matches any digit character (0-9).
  • - Character. Matches a "-" character (char code 45).
  • {0,61} Quantifier. Match between 0 and 61 of the preceding token.
  • \. Escaped character. Matches a "." character (char code 46).
  • $ End. Matches the end of the string, or the end of a line if the multiline flag (m) is enabled.

Here's an example of calling the create(String) function with a valid input from Kotlin code:

val domain: DomainName = DomainName.create("kotools.org")
println(domain) // types.kotools.org

Serialization and deserialization

The serialization and the deserialization processes of this type should behave like for the String type.

Here's an example of Kotlin code that encodes and decodes this type using the JavaScript Object Notation (JSON) format from kotlinx.serialization:

val domain: DomainName = DomainName.create("kotools.org")
val encoded: String = Json.encodeToString(domain)
println(encoded) // "kotools.org"
val decoded: DomainName = Json.decodeFromString(encoded)
println(decoded == domain) // true

🔗 Dependencies

This issue is blocked by the following items:

✅ Checklist

@LVMVRQUXL LVMVRQUXL added feature New feature or request. common Item related to all platforms. labels Dec 14, 2023
@LVMVRQUXL LVMVRQUXL mentioned this issue Dec 14, 2023
17 tasks
@LVMVRQUXL LVMVRQUXL added this to the 4.4.1 milestone Jan 7, 2024
@LVMVRQUXL LVMVRQUXL removed this from the 4.4.1 milestone Jan 25, 2024
@LVMVRQUXL LVMVRQUXL changed the title New WebDomain type New DomainName type in org.kotools.types.web package Jan 28, 2024
@LVMVRQUXL LVMVRQUXL added this to the 4.5.0 milestone Jan 28, 2024
@LVMVRQUXL LVMVRQUXL self-assigned this Jan 29, 2024
LVMVRQUXL added a commit that referenced this issue Jan 29, 2024
This new type represents a domain name in the Internet.

Refs: #340
LVMVRQUXL added a commit that referenced this issue Jan 29, 2024
LVMVRQUXL added a commit that referenced this issue Jan 29, 2024
@LVMVRQUXL LVMVRQUXL removed this from the 4.5.0 milestone Jan 29, 2024
@LVMVRQUXL LVMVRQUXL removed their assignment Jan 29, 2024
@LVMVRQUXL LVMVRQUXL changed the title New DomainName type in org.kotools.types.web package New DomainName type in kotools.types.web package Jan 31, 2024
@LVMVRQUXL LVMVRQUXL modified the milestones: 4.6.0, 4.5.0 Feb 2, 2024
@LVMVRQUXL LVMVRQUXL changed the title New DomainName type in kotools.types.web package New DomainName type Feb 8, 2024
@LVMVRQUXL LVMVRQUXL removed this from the 4.5.0 milestone Feb 8, 2024
@LVMVRQUXL LVMVRQUXL changed the title New DomainName type ✨ New DomainName type Feb 23, 2024
@LVMVRQUXL LVMVRQUXL modified the milestone: 4.5.0 ✨ Feb 29, 2024
@LVMVRQUXL LVMVRQUXL modified the milestone: 4.6.0 Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Item related to all platforms. feature New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant