Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.typelevel.idna4s.build._

ThisBuild / tlBaseVersion := "0.1"
ThisBuild / tlBaseVersion := "0.2"

val UnicodeVersion: String = "15.0.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ object CodePoint extends CodePointPlatform {
e.getLocalizedMessage
}

/**
* A method to attempt to get a string description of an int32 value which is assumed to be a
* code point.
*
* The primary goal of this method is to create strings for error messages. We would like to
* have a rich description of the code point if possible, but in the event the int32 isn't a
* code point we don't want to fail.
*/
def descriptionFromInt(value: Int): String =
CodePoint
.fromInt(value)
.fold(
_ => s"Value is outside the domain of valid code points: ${value}",
_.toString
)

implicit val hashAndOrderForCodePoint: Hash[CodePoint] with Order[CodePoint] =
new Hash[CodePoint] with Order[CodePoint] {
override def hash(x: CodePoint): Int = x.hashCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ object Bootstring {
}
}

def encodePunycodeRaw(value: String): Either[BootstringException, String] =
encodeRaw(BootstringParams.PunycodeParams)(value)

def decodePunycodeRaw(value: String): Either[BootstringException, String] =
decodeRaw(BootstringParams.PunycodeParams)(value)

/**
* An error which occurred during the application of the Bootstring algorithm.
*/
Expand All @@ -351,15 +357,6 @@ object Bootstring {

object BootstringException {

private def codePointDescription(value: Int): String =
CodePoint
.fromInt(value)
.fold(
// The first case should be impossible.
_ => s"Value is outside the domain of valid code points: ${value}",
_.toString
)

private[Bootstring] case object UnableToResizeBufferException extends BootstringException {
override val getMessage: String =
s"Can not resize buffer as it would exceed largest valid size ${Int.MaxValue}. What are you doing?"
Expand All @@ -374,11 +371,11 @@ object Bootstring {
extends BootstringException {

final override def getMessage: String =
s"Input contains a non-basic code point < the initial N value. Code Point: ${codePointDescription(
s"Input contains a non-basic code point < the initial N value. Code Point: ${CodePoint.descriptionFromInt(
invalidCodePoint)}, Initial N: ${initialN}."

final override def toString: String =
s"InvalidNonBasicCodePointException(invalidCodePoint = ${codePointDescription(
s"InvalidNonBasicCodePointException(invalidCodePoint = ${CodePoint.descriptionFromInt(
invalidCodePoint)}, initialN = ${initialN}, getMessage = ${getMessage})"
}

Expand All @@ -398,13 +395,13 @@ object Bootstring {
final private[Bootstring] case class BasicCodePointInNonBasicSection(codePoint: Int)
extends BootstringException {
final override def getMessage: String =
s"Decoded a basic code point in the non-basic section of the input. All basic code points must occur in the basic section. Code point: ${codePointDescription(codePoint)}"
s"Decoded a basic code point in the non-basic section of the input. All basic code points must occur in the basic section. Code point: ${CodePoint.descriptionFromInt(codePoint)}"
}

final private[Bootstring] case class NonBasicCodePointInBasicSection(codePoint: Int)
extends BootstringException {
final override def getMessage: String =
s"Decoded a non-basic code point in the basic section of the input. All non-basic code points must occurr in the non-basic section. Code point: ${codePointDescription(codePoint)}"
s"Decoded a non-basic code point in the basic section of the input. All non-basic code points must occurr in the non-basic section. Code point: ${CodePoint.descriptionFromInt(codePoint)}"
}

final private[Bootstring] case class WrappedException(
Expand Down
Loading