Skip to content

Commit

Permalink
Avoid warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Oct 3, 2024
1 parent e5ff507 commit 18bce41
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
29 changes: 15 additions & 14 deletions src/url/nettlesome.Authority.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package nettlesome

import scala.compiletime.*

import gossamer.*
import rudiments.*
import vacuous.*
Expand All @@ -25,7 +27,6 @@ import denominative.*
import anticipation.*
import contextual.*
import spectacular.*
import serpentine.*

object Authority:
given Authority is Showable = auth =>
Expand All @@ -34,35 +35,35 @@ object Authority:
def parse(value: Text): Authority raises HostnameError raises UrlError =
import UrlError.Expectation.*

safely(value.where(_ == '@')) match
case Unset => value.where(_ == ':') match
case Unset =>
Authority(Hostname.parse(value))

case colon: Ordinal =>
safely(value.where(_ == '@')).asMatchable match
case Zerary(arobase) => safely(value.where(_ == ':', arobase + 1)).asMatchable match
case Zerary(colon) =>
safely(value.after(colon).s.toInt).match
case port: Int if port >= 0 && port <= 65535 => port

case port: Int =>
raise(UrlError(value, colon + 1, PortRange), 0)

case Unset =>
case _ =>
raise(UrlError(value, colon + 1, Number), 0)
.pipe(Authority(Hostname.parse(value.before(colon)), Unset, _))
.pipe(Authority(Hostname.parse(value.slice((arobase + 1) ~ (colon - 1))), value.keep(arobase.n0), _))

case arobase: Ordinal => safely(value.where(_ == ':', arobase + 1)) match
case Unset =>
case _ =>
Authority(Hostname.parse(value.after(arobase)), value.before(arobase))

case colon: Ordinal =>
case _ => value.where(_ == ':').asMatchable match
case Zerary(colon) =>
safely(value.after(colon).s.toInt).match
case port: Int if port >= 0 && port <= 65535 => port

case port: Int =>
raise(UrlError(value, colon + 1, PortRange), 0)

case Unset =>
case _ =>
raise(UrlError(value, colon + 1, Number), 0)
.pipe(Authority(Hostname.parse(value.slice((arobase + 1) ~ (colon - 1))), value.keep(arobase.n0), _))
.pipe(Authority(Hostname.parse(value.before(colon)), Unset, _))

case _ =>
Authority(Hostname.parse(value))

case class Authority(host: Hostname, userInfo: Optional[Text] = Unset, port: Optional[Int] = Unset)
42 changes: 23 additions & 19 deletions src/url/nettlesome.Url.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package nettlesome

import scala.compiletime.*

import serpentine.*
import gossamer.*
import rudiments.*
Expand Down Expand Up @@ -125,11 +127,8 @@ object Url:
: Url[SchemeType] =
import UrlError.Expectation.*

safely(value.where(_ == ':')) match
case Unset =>
abort(UrlError(value, Ult.of(value), Colon))

case colon: Ordinal =>
safely(value.where(_ == ':')).asMatchable match
case Zerary(colon) =>
val text = value.before(colon)
val scheme = Scheme(text)

Expand All @@ -139,23 +138,28 @@ object Url:
(authEnd, Authority.parse(value.slice((colon + 3) ~ authEnd.previous)))
else (colon + 1, Unset)

safely(value.where(_ == '?', pathStart)) match
case Unset => safely(value.where(_ == '#', pathStart)) match
case Unset =>
Url(scheme, auth, value.from(pathStart), Unset, Unset)

case hash: Ordinal =>
Url(scheme, auth, value.slice(pathStart ~ hash.previous), Unset, value.after(hash))

case qmark: Ordinal =>
safely(value.where(_ == '#', qmark + 1)) match
case Unset =>
Url(scheme, auth, value.slice(pathStart ~ qmark.previous), value.after(qmark), Unset)

case hash: Ordinal =>
safely(value.where(_ == '?', pathStart)).asMatchable match
case Zerary(qmark) =>
safely(value.where(_ == '#', qmark + 1)).asMatchable match
case Zerary(hash) =>
Url
(scheme,
auth,
value.slice(pathStart ~ qmark.previous),
value.slice((qmark + 1) ~ hash.previous),
value.after(hash))

case _ =>
Url
(scheme, auth, value.slice(pathStart ~ qmark.previous), value.after(qmark), Unset)

case _ => safely(value.where(_ == '#', pathStart)).asMatchable match
case Zerary(hash) =>
Url(scheme, auth, value.slice(pathStart ~ hash.previous), Unset, value.after(hash))

case _ =>
Url(scheme, auth, value.from(pathStart), Unset, Unset)

case _ =>
abort(UrlError(value, Ult.of(value), Colon))

2 changes: 1 addition & 1 deletion src/url/nettlesome.UrlInterpolator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import spectacular.*

import scala.quoted.*

import exceptionDiagnostics.empty
import errorDiagnostics.empty

object UrlInterpolator extends contextual.Interpolator[UrlInput, Text, Url[Label]]:

Expand Down

0 comments on commit 18bce41

Please sign in to comment.