Skip to content

Commit

Permalink
Merge branch 'fasit'
Browse files Browse the repository at this point in the history
  • Loading branch information
hamnis committed Sep 2, 2024
2 parents ccd9294 + bdff7c9 commit 280d981
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions oppgaver/src/test/scala/arktekk/oppgave2/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,27 @@ enum Ref {
case Property(name: String)
case Index(idx: Int) extends Ref with ArrayRef
case EndOfList extends Ref with ArrayRef

def unescape: Ref = this match
case Property(name) => Property(name.replaceAll("~1", "/").replaceAll("~0", "~"))
case i: Index => i
case EndOfList => EndOfList

def escape: Ref = this match
case Property(name) => Property(name.replaceAll("~", "~0").replaceAll("/", "~1"))
case i: Index => i
case EndOfList => EndOfList
}

enum Path {
case Root
case Refs(parts: NonEmptyList[Ref])

def unescape: Path = this match
case Path.Root => Path.Root
case Path.Refs(parts) => Path.Refs(parts.map(_.unescape))

def escape: Path = this match
case Path.Root => Path.Root
case Path.Refs(parts) => Path.Refs(parts.map(_.escape))
}

0 comments on commit 280d981

Please sign in to comment.