[16da5f8e] | 1 | /*
|
---|
| 2 | * Copyright (c) 2001-2004 Jakub Jermar
|
---|
[d066259] | 3 | * Copyright (c) 2005 Martin Decky
|
---|
| 4 | * Copyright (c) 2011 Oleg Romanenko
|
---|
[16da5f8e] | 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 |
|
---|
[174156fd] | 31 | /** @addtogroup kernel_generic
|
---|
[16da5f8e] | 32 | * @{
|
---|
| 33 | */
|
---|
| 34 | /** @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[19f857a] | 37 | #ifndef KERN_STR_H_
|
---|
| 38 | #define KERN_STR_H_
|
---|
[16da5f8e] | 39 |
|
---|
[d066259] | 40 | #include <errno.h>
|
---|
[525c5ac] | 41 | #include <stdbool.h>
|
---|
[83dab11] | 42 | #include <stddef.h>
|
---|
| 43 | #include <stdint.h>
|
---|
[16da5f8e] | 44 |
|
---|
[d066259] | 45 | /* Common Unicode characters */
|
---|
[c8bf88d] | 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 |
|
---|
[d066259] | 65 | /** No size limit constant */
|
---|
[b888d5f] | 66 | #define STR_NO_LIMIT ((size_t) -1)
|
---|
| 67 |
|
---|
[d066259] | 68 | /** Maximum size of a string containing @c length characters */
|
---|
| 69 | #define STR_BOUNDS(length) ((length) << 2)
|
---|
[74c8da2c] | 70 |
|
---|
[b888d5f] | 71 | extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
|
---|
[b7fd2a0] | 72 | extern errno_t chr_encode(wchar_t ch, char *str, size_t *offset, size_t sz);
|
---|
[b888d5f] | 73 |
|
---|
| 74 | extern size_t str_size(const char *str);
|
---|
| 75 | extern size_t wstr_size(const wchar_t *str);
|
---|
| 76 |
|
---|
[98000fb] | 77 | extern size_t str_lsize(const char *str, size_t max_len);
|
---|
| 78 | extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
|
---|
[74c8da2c] | 79 |
|
---|
[98000fb] | 80 | extern size_t str_length(const char *str);
|
---|
| 81 | extern size_t wstr_length(const wchar_t *wstr);
|
---|
[82bb9c1] | 82 |
|
---|
[98000fb] | 83 | extern size_t str_nlength(const char *str, size_t size);
|
---|
| 84 | extern size_t wstr_nlength(const wchar_t *str, size_t size);
|
---|
[74c8da2c] | 85 |
|
---|
[f2b8cdc] | 86 | extern bool ascii_check(wchar_t ch);
|
---|
| 87 | extern bool chr_check(wchar_t ch);
|
---|
[b888d5f] | 88 |
|
---|
| 89 | extern int str_cmp(const char *s1, const char *s2);
|
---|
[98000fb] | 90 | extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
|
---|
[b888d5f] | 91 |
|
---|
[f4b1535] | 92 | extern void str_cpy(char *dest, size_t size, const char *src);
|
---|
| 93 | extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
|
---|
[0f06dbc] | 94 | extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
|
---|
[06b785f] | 95 |
|
---|
[dd2cfa7] | 96 | extern char *str_chr(const char *str, wchar_t ch);
|
---|
[16da5f8e] | 97 |
|
---|
[98000fb] | 98 | extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos);
|
---|
| 99 | extern bool wstr_remove(wchar_t *str, size_t pos);
|
---|
[20f1597] | 100 |
|
---|
[d066259] | 101 | extern char *str_dup(const char *src);
|
---|
| 102 | extern char *str_ndup(const char *src, size_t n);
|
---|
| 103 |
|
---|
| 104 | extern errno_t str_uint64_t(const char *, char **, unsigned int, bool,
|
---|
| 105 | uint64_t *);
|
---|
[30a5470] | 106 |
|
---|
[933cadf] | 107 | extern void order_suffix(const uint64_t, uint64_t *, char *);
|
---|
| 108 | extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
|
---|
[e535eeb] | 109 |
|
---|
[62ca560] | 110 | extern const char *str_error(errno_t err);
|
---|
| 111 | extern const char *str_error_name(errno_t err);
|
---|
| 112 |
|
---|
[16da5f8e] | 113 | #endif
|
---|
| 114 |
|
---|
| 115 | /** @}
|
---|
| 116 | */
|
---|