source: mainline/kernel/generic/include/str.h@ 901b302

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 901b302 was 28a5ebd, checked in by Martin Decky <martin@…>, 5 years ago

Use char32_t instead of wchat_t to represent UTF-32 strings

The intention of the native HelenOS string API has been always to
support Unicode in the UTF-8 and UTF-32 encodings as the sole character
representations and ignore the obsolete mess of older single-byte and
multibyte character encodings. Before C11, the wchar_t type has been
slightly misused for the purpose of the UTF-32 strings. The newer
char32_t type is obviously a much more suitable option. The standard
defines char32_t as uint_least32_t, thus we can take the liberty to fix
it to uint32_t.

To maintain compatilibity with the C Standard, the putwchar(wchar_t)
functions has been replaced by our custom putuchar(char32_t) functions
where appropriate.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2001-2004 Jakub Jermar
3 * Copyright (c) 2005 Martin Decky
4 * Copyright (c) 2011 Oleg Romanenko
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup kernel_generic
32 * @{
33 */
34/** @file
35 */
36
37#ifndef KERN_STR_H_
38#define KERN_STR_H_
39
40#include <errno.h>
41#include <stdbool.h>
42#include <stddef.h>
43#include <stdint.h>
44
45/* Common Unicode characters */
46#define U_SPECIAL '?'
47
48#define U_LEFT_ARROW 0x2190
49#define U_UP_ARROW 0x2191
50#define U_RIGHT_ARROW 0x2192
51#define U_DOWN_ARROW 0x2193
52
53#define U_PAGE_UP 0x21de
54#define U_PAGE_DOWN 0x21df
55
56#define U_HOME_ARROW 0x21f1
57#define U_END_ARROW 0x21f2
58
59#define U_NULL 0x2400
60#define U_ESCAPE 0x241b
61#define U_DELETE 0x2421
62
63#define U_CURSOR 0x2588
64
65/** No size limit constant */
66#define STR_NO_LIMIT ((size_t) -1)
67
68/** Maximum size of a string containing @c length characters */
69#define STR_BOUNDS(length) ((length) << 2)
70
71extern char32_t str_decode(const char *, size_t *, size_t);
72extern errno_t chr_encode(char32_t, char *, size_t *, size_t);
73
74extern size_t str_size(const char *);
75extern size_t wstr_size(const char32_t *);
76
77extern size_t str_lsize(const char *, size_t);
78extern size_t wstr_lsize(const char32_t *, size_t);
79
80extern size_t str_length(const char *);
81extern size_t wstr_length(const char32_t *);
82
83extern size_t str_nlength(const char *, size_t);
84extern size_t wstr_nlength(const char32_t *, size_t);
85
86extern bool ascii_check(char32_t);
87extern bool chr_check(char32_t);
88
89extern int str_cmp(const char *, const char *);
90extern int str_lcmp(const char *, const char *, size_t);
91
92extern void str_cpy(char *, size_t, const char *);
93extern void str_ncpy(char *, size_t, const char *, size_t);
94extern void wstr_to_str(char *, size_t, const char32_t *);
95
96extern char *str_chr(const char *, char32_t);
97
98extern bool wstr_linsert(char32_t *, char32_t, size_t, size_t);
99extern bool wstr_remove(char32_t *, size_t);
100
101extern char *str_dup(const char *);
102extern char *str_ndup(const char *, size_t);
103
104extern errno_t str_uint64_t(const char *, char **, unsigned int, bool,
105 uint64_t *);
106
107extern void order_suffix(const uint64_t, uint64_t *, char *);
108extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
109
110extern const char *str_error(errno_t);
111extern const char *str_error_name(errno_t);
112
113#endif
114
115/** @}
116 */
Note: See TracBrowser for help on using the repository browser.