Line data Source code
1 : // Copyright (c) 2006-2022 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/libutf8
4 : // contact@m2osw.com
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : #pragma once
20 :
21 : // libutf8
22 : //
23 : #include <libutf8/libutf8.h> // for the ostream
24 :
25 :
26 : // catch2
27 : //
28 : #include <catch2/snapcatch2.hpp>
29 :
30 :
31 : // C++
32 : //
33 : #include <string>
34 : #include <cstring>
35 : #include <cstdlib>
36 : #include <iostream>
37 :
38 :
39 : // last include
40 : //
41 : #include <snapdev/poison.h>
42 :
43 :
44 :
45 : namespace SNAP_CATCH2_NAMESPACE
46 : {
47 :
48 :
49 :
50 :
51 2098472 : inline char32_t rand_char(bool full_range = false)
52 : {
53 2098472 : char32_t const max((full_range ? 0x0110000 : 0x0010000) - (0xE000 - 0xD800));
54 :
55 : char32_t wc;
56 36 : do
57 : {
58 2098508 : wc = ((rand() << 16) ^ rand()) % max;
59 : }
60 2098508 : while(wc == 0);
61 2098472 : if(wc >= 0xD800)
62 : {
63 : // skip the surrogates
64 : //
65 273583 : wc += 0xE000 - 0xD800;
66 : }
67 :
68 2098472 : return wc;
69 : }
70 :
71 :
72 :
73 : }
74 : // unittest namespace
75 : // vim: ts=4 sw=4 et
|