Module proper_unicode

Unicode generators for PropEr.

Copyright © 2014 Motiejus Jakstys

Version: May 18 2021 22:41:22

Authors: Motiejus Jakstys.


Unicode generators for PropEr

This module exposes utf8 binary generator.

Makes it easy to create custom-encoded unicode binaries. For example, utf16 binary generator:

   utf16() ->
       ?LET(S, utf8(), unicode:characters_to_binary(S, utf8, utf16)).

Verify it has at least twice as many bytes as codepoints:

   ?FORALL(S, utf16(),
           size(S) >= 2*length(unicode:characters_to_list(S, utf16))).
Only utf8 generation is supported: utf8/0, utf8/1, utf8/2. Unicode codepoints and other encodings are trivial to get with utf8 generators and unicode module in OTP.

Data Types


nonnegextint() = non_neg_integer() | inf

Function Index

utf8/0utf8-encoded unbounded size binary.
utf8/1utf8-encoded bounded upper size binary.
utf8/2Bounded upper size utf8 binary, codepoint length =< MaxCodePointSize.

Function Details


utf8() -> proper_types:type()

utf8-encoded unbounded size binary.


utf8(N :: nonnegextint()) -> proper_types:type()

utf8-encoded bounded upper size binary.


utf8(N :: nonnegextint(), MaxCodePointSize :: 1..4) ->

Bounded upper size utf8 binary, codepoint length =< MaxCodePointSize.

Limiting codepoint size can be useful when applications do not accept full unicode range. For example, MySQL in utf8 encoding accepts only 3-byte unicode codepoints in VARCHAR fields.

If unbounded length is needed, use inf as first argument.

Generated by EDoc