[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>
|
---|
| 47 |
|
---|
| 48 | #ifndef __cplusplus
|
---|
[d066259] | 49 |
|
---|
| 50 | /* Common Unicode characters */
|
---|
| 51 | #define U_SPECIAL '?'
|
---|
[171f9a1] | 52 |
|
---|
[54a6ff6] | 53 | /** No size limit constant */
|
---|
[f2b8cdc] | 54 | #define STR_NO_LIMIT ((size_t) -1)
|
---|
| 55 |
|
---|
[54a6ff6] | 56 | /** Maximum size of a string containing @c length characters */
|
---|
[92fd52d7] | 57 | #define STR_BOUNDS(length) ((length) << 2)
|
---|
[f2b8cdc] | 58 |
|
---|
[dcb74c0a] | 59 | /**
|
---|
| 60 | * Maximum size of a buffer needed to a string converted from space-padded
|
---|
| 61 | * ASCII of size @a spa_size using spascii_to_str().
|
---|
| 62 | */
|
---|
| 63 | #define SPASCII_STR_BUFSIZE(spa_size) ((spa_size) + 1)
|
---|
| 64 |
|
---|
[bc56f30] | 65 | #endif
|
---|
| 66 |
|
---|
| 67 | __HELENOS_DECLS_BEGIN;
|
---|
| 68 |
|
---|
[28a5ebd] | 69 | extern char32_t str_decode(const char *str, size_t *offset, size_t sz);
|
---|
| 70 | extern char32_t str_decode_reverse(const char *str, size_t *offset, size_t sz);
|
---|
| 71 | extern errno_t chr_encode(char32_t ch, char *str, size_t *offset, size_t sz);
|
---|
[171f9a1] | 72 |
|
---|
[f2b8cdc] | 73 | extern size_t str_size(const char *str);
|
---|
[28a5ebd] | 74 | extern size_t wstr_size(const char32_t *str);
|
---|
[f2b8cdc] | 75 |
|
---|
[560d79f] | 76 | extern size_t str_nsize(const char *str, size_t max_size);
|
---|
[28a5ebd] | 77 | extern size_t wstr_nsize(const char32_t *str, size_t max_size);
|
---|
[560d79f] | 78 |
|
---|
[d4a3ee5] | 79 | extern size_t str_lsize(const char *str, size_t max_len);
|
---|
[28a5ebd] | 80 | extern size_t wstr_lsize(const char32_t *str, size_t max_len);
|
---|
[f2b8cdc] | 81 |
|
---|
[d4a3ee5] | 82 | extern size_t str_length(const char *str);
|
---|
[28a5ebd] | 83 | extern size_t wstr_length(const char32_t *wstr);
|
---|
[f2b8cdc] | 84 |
|
---|
[d4a3ee5] | 85 | extern size_t str_nlength(const char *str, size_t size);
|
---|
[28a5ebd] | 86 | extern size_t wstr_nlength(const char32_t *str, size_t size);
|
---|
[f2b8cdc] | 87 |
|
---|
[28a5ebd] | 88 | extern size_t chr_width(char32_t ch);
|
---|
[be2a38ad] | 89 | extern size_t str_width(const char *str);
|
---|
| 90 |
|
---|
[28a5ebd] | 91 | extern bool ascii_check(char32_t ch);
|
---|
| 92 | extern bool chr_check(char32_t ch);
|
---|
[f2b8cdc] | 93 |
|
---|
| 94 | extern int str_cmp(const char *s1, const char *s2);
|
---|
[d4a3ee5] | 95 | extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
|
---|
[8227d63] | 96 | extern int str_casecmp(const char *s1, const char *s2);
|
---|
| 97 | extern int str_lcasecmp(const char *s1, const char *s2, size_t max_len);
|
---|
[f2b8cdc] | 98 |
|
---|
[dce39b4] | 99 | extern bool str_test_prefix(const char *s, const char *p);
|
---|
[086cab0] | 100 | extern const char *str_suffix(const char *s, size_t prefix_length);
|
---|
[dce39b4] | 101 |
|
---|
[6eb2e96] | 102 | extern void str_cpy(char *dest, size_t size, const char *src);
|
---|
| 103 | extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
|
---|
[4482bc7] | 104 | extern void str_append(char *dest, size_t size, const char *src);
|
---|
[6eb2e96] | 105 |
|
---|
[b7fd2a0] | 106 | extern errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n);
|
---|
[28a5ebd] | 107 | extern void wstr_to_str(char *dest, size_t size, const char32_t *src);
|
---|
| 108 | extern char *wstr_to_astr(const char32_t *src);
|
---|
| 109 | extern void str_to_wstr(char32_t *dest, size_t dlen, const char *src);
|
---|
| 110 | extern char32_t *str_to_awstr(const char *src);
|
---|
[b7fd2a0] | 111 | extern errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src);
|
---|
| 112 | extern errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src);
|
---|
[b2906c0] | 113 | extern size_t utf16_wsize(const uint16_t *ustr);
|
---|
[f2b8cdc] | 114 |
|
---|
[28a5ebd] | 115 | extern char *str_chr(const char *str, char32_t ch);
|
---|
| 116 | extern char *str_rchr(const char *str, char32_t ch);
|
---|
[da680b4b] | 117 | extern char *str_str(const char *hs, const char *n);
|
---|
[f2b8cdc] | 118 |
|
---|
[28a5ebd] | 119 | extern void str_rtrim(char *str, char32_t ch);
|
---|
| 120 | extern void str_ltrim(char *str, char32_t ch);
|
---|
[1737bfb] | 121 |
|
---|
[28a5ebd] | 122 | extern bool wstr_linsert(char32_t *str, char32_t ch, size_t pos, size_t max_pos);
|
---|
| 123 | extern bool wstr_remove(char32_t *str, size_t pos);
|
---|
[f2b8cdc] | 124 |
|
---|
[d066259] | 125 | extern char *str_dup(const char *src);
|
---|
| 126 | extern char *str_ndup(const char *src, size_t n);
|
---|
[095003a8] | 127 |
|
---|
[ee3f6f6] | 128 | extern char *str_tok(char *, const char *, char **);
|
---|
| 129 |
|
---|
[b7fd2a0] | 130 | extern errno_t str_uint8_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 131 | uint8_t *);
|
---|
[b7fd2a0] | 132 | extern errno_t str_uint16_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 133 | uint16_t *);
|
---|
[b7fd2a0] | 134 | extern errno_t str_uint32_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 135 | uint32_t *);
|
---|
[b7fd2a0] | 136 | extern errno_t str_uint64_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 137 | uint64_t *);
|
---|
[b7fd2a0] | 138 | extern errno_t str_size_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 139 | size_t *);
|
---|
[1c9bf292] | 140 | extern errno_t str_int64_t(const char *, const char **, unsigned int, bool,
|
---|
[af8bda0] | 141 | int64_t *);
|
---|
[d47279b] | 142 |
|
---|
[933cadf] | 143 | extern void order_suffix(const uint64_t, uint64_t *, char *);
|
---|
| 144 | extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
|
---|
[e535eeb] | 145 |
|
---|
[f2b8cdc] | 146 | /*
|
---|
| 147 | * TODO: Get rid of this.
|
---|
| 148 | */
|
---|
[c9857c6] | 149 |
|
---|
[1526594c] | 150 | extern long int strtol(const char *, char **, int);
|
---|
| 151 | extern unsigned long strtoul(const char *, char **, int);
|
---|
[c9857c6] | 152 |
|
---|
[bc56f30] | 153 | __HELENOS_DECLS_END;
|
---|
[82fd245] | 154 |
|
---|
[7ad3c2f] | 155 | #endif
|
---|
[b2951e2] | 156 |
|
---|
[fadd381] | 157 | /** @}
|
---|
[b2951e2] | 158 | */
|
---|