1
- % %% -*- coding: utf-8 -*-
2
- % %% -*- erlang-indent-level: 2 -*-
1
+ % %% -*- coding: utf-8; erlang-indent-level: 2 -*-
3
2
% %% -------------------------------------------------------------------
4
3
% %% Copyright 2014 Motiejus Jakstys <[email protected] >
5
4
% %%
24
23
25
24
% %% @doc Unicode generators for PropEr
26
25
% %%
27
- % %% This module exposes utf8 binary generator .
26
+ % %% This module exposes utf8 binary and string generators .
28
27
% %%
29
- % %% Makes it easy to create custom-encoded unicode binaries. For example,
30
- % %% utf16 binary generator:
28
+ % %% Makes it easy to create custom-encoded unicode binaries and strings.
29
+ % %% For example, utf16 binary generator:
31
30
% %%
32
31
% %% ```
33
32
% %% utf16() ->
40
39
% %% ?FORALL(S, utf16(),
41
40
% %% size(S) >= 2*length(unicode:characters_to_list(S, utf16))).
42
41
% %% '''
43
- % %% Only utf8 generation is supported: {@link utf8/0}, {@link utf8/1}, {@link
44
- % %% utf8/2}. Unicode codepoints and other encodings are trivial to get with
45
- % %% utf8 generators and {@link unicode} module in OTP.
42
+
43
+ % %% Only utf8 generation is supported: see {@link utf8/0}, {@link utf8/1},
44
+ % %% {@link utf8/2} which generate binaries and the corresponding functions
45
+ % %% generating strings. Unicode codepoints and other encodings are trivial
46
+ % %% to get with utf8 generators and the {@link unicode} module in OTP.
46
47
-module (proper_unicode ).
47
48
48
- -export ([utf8 /0 , utf8 /1 , utf8 /2 ]).
49
+ -export ([utf8 /0 , utf8 /1 , utf8 /2 , utf8_string / 0 , utf8_string / 1 , utf8_string / 2 ]).
49
50
50
51
-include (" proper_common.hrl" ).
51
52
52
53
% % @private_type
53
54
% % @alias
54
- -type nonnegextint () :: non_neg_integer () | 'inf' .
55
+ -type nonnegextint () :: non_neg_integer () | 'inf' .
55
56
56
57
57
58
% % @doc utf8-encoded unbounded size binary.
@@ -78,6 +79,21 @@ utf8(N, MaxCodePointSize) ->
78
79
unicode :characters_to_binary (Str )).
79
80
80
81
82
+ % % @doc utf8-encoded unbounded size string.
83
+ -spec utf8_string () -> proper_types :type ().
84
+ utf8_string () ->
85
+ utf8_string (inf , 4 ).
86
+
87
+ % % @doc utf8-encoded bounded upper size string.
88
+ -spec utf8_string (nonnegextint ()) -> proper_types :type ().
89
+ utf8_string (N ) ->
90
+ utf8_string (N , 4 ).
91
+
92
+ % % @doc Bounded upper size utf8 string, `codepoint length =< MaxCodePointSize'.
93
+ -spec utf8_string (nonnegextint (), 1 ..4 ) -> proper_types :type ().
94
+ utf8_string (N , MaxCodePointSize ) ->
95
+ vector_upto (N , unicode_codepoint_upto (MaxCodePointSize )).
96
+
81
97
% % =============================================================================
82
98
% % Internal functions
83
99
% % =============================================================================
0 commit comments