Utf8proc - UTF-8 text processing
This binding for utf8proc.h
provides Unicode normalization, case-folding, and other operations for strings in the UTF-8 encoding.
To use it add the following resolver and the dependency:
- sbt
-
resolvers += Resolver.bintrayRepo("scala-native-bindgen", "maven") libraryDependencies += "org.scala-native.bindgen" %%% "libutf8proc" % "0.3.1"
- Maven
-
<repositories> <repository> <id>maven</id> <url>http://dl.bintray.com/scala-native-bindgen/maven</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.scala-native.bindgen</groupId> <artifactId>libutf8proc_native0.3_2.11</artifactId> <version>0.3.1</version> </dependency> </dependencies>
- Gradle
-
repositories { maven { url "http://dl.bintray.com/scala-native-bindgen/maven" } } dependencies { compile group: 'org.scala-native.bindgen', name: 'libutf8proc_native0.3_2.11', version: '0.3.1' }
Example
import org.scalanative.bindgen.bindings.utf8proc.utf8proc._
import scala.scalanative.native._
val text = c"Spørge"
val textlen = string.strlen(text)
val codepoint = stackalloc[utf8proc_int32_t]
var textpos: CSize = 0
var textwidth: CSize = 0
while (textpos < textlen) {
val bytes = utf8proc_iterate(
text.cast[Ptr[UByte]] + textpos,
textlen - textpos,
codepoint
)
textwidth += utf8proc_charwidth(!codepoint)
textpos += bytes
}
assert(textlen == 7)
assert(textwidth == 6)
Full source at GitHub
0.3.1