[7ad3c2f] | 1 | /*
|
---|
[d066259] | 2 | * Copyright (c) 2001-2004 Jakub Jermar
|
---|
[df4ed85] | 3 | * Copyright (c) 2005 Martin Decky
|
---|
[c4bbca8] | 4 | * Copyright (c) 2011 Oleg Romanenko
|
---|
[7ad3c2f] | 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 |
|
---|
[fadd381] | 31 | /** @addtogroup libc
|
---|
[b2951e2] | 32 | * @{
|
---|
| 33 | */
|
---|
| 34 | /** @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[4805495] | 37 | #ifndef _LIBC_STR_H_
|
---|
| 38 | #define _LIBC_STR_H_
|
---|
[7ad3c2f] | 39 |
|
---|
[36f0738] | 40 | #include <errno.h>
|
---|
[d066259] | 41 | #include <stdbool.h>
|
---|
[8d2dd7f2] | 42 | #include <stddef.h>
|
---|
| 43 | #include <stdint.h>
|
---|
[171f9a1] | 44 |
|
---|
[d066259] | 45 | #include <mem.h>
|
---|
[bc56f30] | 46 | #include <_bits/decls.h>
|
---|
[fdfb24e] | 47 | #include <_bits/uchar.h>
|
---|
[bc56f30] | 48 |
|
---|
| 49 | #ifndef __cplusplus
|
---|
[d066259] | 50 |
|
---|
| 51 | /* Common Unicode characters */
|
---|
| 52 | #define U_SPECIAL '?'
|
---|
[171f9a1] | 53 |
|
---|
[fdfb24e] | 54 | #define U_LEFT_ARROW 0x2190
|
---|
| 55 | #define U_UP_ARROW 0x2191
|
---|
| 56 | #define U_RIGHT_ARROW 0x2192
|
---|
| 57 | #define U_DOWN_ARROW 0x2193
|
---|
| 58 |
|
---|
| 59 | #define U_PAGE_UP 0x21de
|
---|
| 60 | #define U_PAGE_DOWN 0x21df
|
---|
| 61 |
|
---|
| 62 | #define U_HOME_ARROW 0x21f1
|
---|
| 63 | #define U_END_ARROW 0x21f2
|
---|
| 64 |
|
---|
| 65 | #define U_NULL 0x2400
|
---|
| 66 | #define U_ESCAPE 0x241b
|
---|
| 67 | #define U_DELETE 0x2421
|
---|
| 68 |
|
---|
| 69 | #define U_CURSOR 0x2588
|
---|
| 70 |
|
---|
[54a6ff6] | 71 | /** No size limit constant */
|
---|
[f2b8cdc] | 72 | #define STR_NO_LIMIT ((size_t) -1)
|
---|
| 73 |
|
---|
[54a6ff6] | 74 | /** Maximum size of a string containing @c length characters */
|
---|
[92fd52d7] | 75 | #define STR_BOUNDS(length) ((length) << 2)
|
---|
[f2b8cdc] | 76 |
|
---|
[dcb74c0a] | 77 | /**
|
---|
| 78 | * Maximum size of a buffer needed to a string converted from space-padded
|
---|
| 79 | * ASCII of size @a spa_size using spascii_to_str().
|
---|
| 80 | */
|
---|
| 81 | #define SPASCII_STR_BUFSIZE(spa_size) ((spa_size) + 1)
|
---|
| 82 |
|
---|
[bc56f30] | 83 | #endif
|
---|
| 84 |
|
---|
| 85 | __HELENOS_DECLS_BEGIN;
|
---|
| 86 |
|
---|
[28a5ebd] | 87 | extern char32_t str_decode(const char *str, size_t *offset, size_t sz);
|
---|
| 88 | extern char32_t str_decode_reverse(const char *str, size_t *offset, size_t sz);
|
---|
| 89 | extern errno_t chr_encode(char32_t ch, char *str, size_t *offset, size_t sz);
|
---|
[171f9a1] | 90 |
|
---|
[f2b8cdc] | 91 | extern size_t str_size(const char *str);
|
---|
[28a5ebd] | 92 | extern size_t wstr_size(const char32_t *str);
|
---|
[f2b8cdc] | 93 |
|
---|
[560d79f] | 94 | extern size_t str_nsize(const char *str, size_t max_size);
|
---|
[28a5ebd] | 95 | extern size_t wstr_nsize(const char32_t *str, size_t max_size);
|
---|
[560d79f] | 96 |
|
---|
[d4a3ee5] | 97 | extern size_t str_lsize(const char *str, size_t max_len);
|
---|
[28a5ebd] | 98 | extern size_t wstr_lsize(const char32_t *str, size_t max_len);
|
---|
[f2b8cdc] | 99 |
|
---|
[d4a3ee5] | 100 | extern size_t str_length(const char *str);
|
---|
[28a5ebd] | 101 | extern size_t wstr_length(const char32_t *wstr);
|
---|
[f2b8cdc] | 102 |
|
---|
[d4a3ee5] | 103 | extern size_t str_nlength(const char *str, size_t size);
|
---|
[28a5ebd] | 104 | extern size_t wstr_nlength(const char32_t *str, size_t size);
|
---|
[f2b8cdc] | 105 |
|
---|
[28a5ebd] | 106 | extern size_t chr_width(char32_t ch);
|
---|
[be2a38ad] | 107 | extern size_t str_width(const char *str);
|
---|
| 108 |
|
---|
[28a5ebd] | 109 | extern bool ascii_check(char32_t ch);
|
---|
| 110 | extern bool chr_check(char32_t ch);
|
---|
[f2b8cdc] | 111 |
|
---|
| 112 | extern int str_cmp(const char *s1, const char *s2);
|
---|
[d4a3ee5] | 113 | extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
|
---|
[8227d63] | 114 | extern int str_casecmp(const char *s1, const char *s2);
|
---|
| 115 | extern int str_lcasecmp(const char *s1, const char *s2, size_t max_len);
|
---|
[f2b8cdc] | 116 |
|
---|
[dce39b4] | 117 | extern bool str_test_prefix(const char *s, const char *p);
|
---|
[086cab0] | 118 | extern const char *str_suffix(const char *s, size_t prefix_length);
|
---|
[dce39b4] | 119 |
|
---|
[6eb2e96] | 120 | extern void str_cpy(char *dest, size_t size, const char *src);
|
---|
| 121 | extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
|
---|
[4482bc7] | 122 | extern void str_append(char *dest, size_t size, const char *src);
|
---|
[6eb2e96] | 123 |
|
---|
[b7fd2a0] | 124 | extern errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n);
|
---|
[28a5ebd] | 125 | extern void wstr_to_str(char *dest, size_t size, const char32_t *src);
|
---|
| 126 | extern char *wstr_to_astr(const char32_t *src);
|
---|
| 127 | extern void str_to_wstr(char32_t *dest, size_t dlen, const char *src);
|
---|
| 128 | extern char32_t *str_to_awstr(const char *src);
|
---|
[b7fd2a0] | 129 | extern errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src);
|
---|
| 130 | extern errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src);
|
---|
[b2906c0] | 131 | extern size_t utf16_wsize(const uint16_t *ustr);
|
---|
[f2b8cdc] | 132 |
|
---|
[28a5ebd] | 133 | extern char *str_chr(const char *str, char32_t ch);
|
---|
| 134 | extern char *str_rchr(const char *str, char32_t ch);
|
---|
[da680b4b] | 135 | extern char *str_str(const char *hs, const char *n);
|
---|
[f2b8cdc] | 136 |
|
---|
[28a5ebd] | 137 | extern void str_rtrim(char *str, char32_t ch);
|
---|
| 138 | extern void str_ltrim(char *str, char32_t ch);
|
---|
[1737bfb] | 139 |
|
---|
[28a5ebd] | 140 | extern bool wstr_linsert(char32_t *str, char32_t ch, size_t pos, size_t max_pos);
|
---|
| 141 | extern bool wstr_remove(char32_t *str, size_t pos);
|
---|
[f2b8cdc] | 142 |
|
---|
[d066259] | 143 | extern char *str_dup(const char *src);
|
---|
| 144 | extern char *str_ndup(const char *src, size_t n);
|
---|
[095003a8] | 145 |
|
---|
[ee3f6f6] | 146 | extern char *str_tok(char *, const char *, char **);
|
---|
| 147 |
|
---|
[b7fd2a0] | 148 | extern errno_t str_uint8_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 149 | uint8_t *);
|
---|
[b7fd2a0] | 150 | extern errno_t str_uint16_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 151 | uint16_t *);
|
---|
[b7fd2a0] | 152 | extern errno_t str_uint32_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 153 | uint32_t *);
|
---|
[b7fd2a0] | 154 | extern errno_t str_uint64_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 155 | uint64_t *);
|
---|
[b7fd2a0] | 156 | extern errno_t str_size_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 157 | size_t *);
|
---|
[1c9bf292] | 158 | extern errno_t str_int64_t(const char *, const char **, unsigned int, bool,
|
---|
[af8bda0] | 159 | int64_t *);
|
---|
[d47279b] | 160 |
|
---|
[933cadf] | 161 | extern void order_suffix(const uint64_t, uint64_t *, char *);
|
---|
| 162 | extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
|
---|
[e535eeb] | 163 |
|
---|
[f2b8cdc] | 164 | /*
|
---|
| 165 | * TODO: Get rid of this.
|
---|
| 166 | */
|
---|
[c9857c6] | 167 |
|
---|
[1526594c] | 168 | extern long int strtol(const char *, char **, int);
|
---|
| 169 | extern unsigned long strtoul(const char *, char **, int);
|
---|
[c9857c6] | 170 |
|
---|
[bc56f30] | 171 | __HELENOS_DECLS_END;
|
---|
[82fd245] | 172 |
|
---|
[7ad3c2f] | 173 | #endif
|
---|
[b2951e2] | 174 |
|
---|
[fadd381] | 175 | /** @}
|
---|
[b2951e2] | 176 | */
|
---|