-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e1f5f9
commit ec4f331
Showing
5 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
core/src/main/scalanative-2.13/sttp/model/internal/idn/IdnApi.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sttp.model.internal.idn | ||
|
||
import scala.scalanative.libc.stdlib.{malloc, free} | ||
import scala.scalanative.unsafe.{CString, Ptr, Zone, fromCString, sizeof, toCString} | ||
|
||
private[model] object IdnApi { | ||
def toAscii(input: String): String = | ||
Zone { implicit z => | ||
val output: Ptr[CString] = malloc(sizeof[CString]).asInstanceOf[Ptr[CString]] | ||
val rc = CIdn.toAscii(toCString(input), output, 0) | ||
if (rc != 0) { | ||
val errMsg = CIdn.errorMsg(rc) | ||
throw new RuntimeException(fromCString(errMsg)) | ||
} else { | ||
val out = fromCString(!output) | ||
CIdn.free(!output) | ||
free(output.asInstanceOf[Ptr[Byte]]) | ||
out | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/scalanative-3/sttp/model/internal/idn/IdnApi.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sttp.model.internal.idn | ||
|
||
import scala.scalanative.libc.stdlib.{malloc, free} | ||
import scala.scalanative.unsafe.{CString, Ptr, Zone, fromCString, sizeof, toCString} | ||
|
||
private[model] object IdnApi { | ||
def toAscii(input: String): String = | ||
Zone { | ||
val output: Ptr[CString] = malloc(sizeof[CString]).asInstanceOf[Ptr[CString]] | ||
val rc = CIdn.toAscii(toCString(input), output, 0) | ||
if (rc != 0) { | ||
val errMsg = CIdn.errorMsg(rc) | ||
throw new RuntimeException(fromCString(errMsg)) | ||
} else { | ||
val out = fromCString(!output) | ||
CIdn.free(!output) | ||
free(output.asInstanceOf[Ptr[Byte]]) | ||
out | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters