[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 |
|
---|
[171f9a1] | 69 | extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
|
---|
[568693b] | 70 | extern wchar_t str_decode_reverse(const char *str, size_t *offset, size_t sz);
|
---|
[d066259] | 71 | extern errno_t chr_encode(wchar_t ch, char *str, size_t *offset, size_t sz);
|
---|
[171f9a1] | 72 |
|
---|
[f2b8cdc] | 73 | extern size_t str_size(const char *str);
|
---|
| 74 | extern size_t wstr_size(const wchar_t *str);
|
---|
| 75 |
|
---|
[560d79f] | 76 | extern size_t str_nsize(const char *str, size_t max_size);
|
---|
| 77 | extern size_t wstr_nsize(const wchar_t *str, size_t max_size);
|
---|
| 78 |
|
---|
[d4a3ee5] | 79 | extern size_t str_lsize(const char *str, size_t max_len);
|
---|
| 80 | extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
|
---|
[f2b8cdc] | 81 |
|
---|
[d4a3ee5] | 82 | extern size_t str_length(const char *str);
|
---|
| 83 | extern size_t wstr_length(const wchar_t *wstr);
|
---|
[f2b8cdc] | 84 |
|
---|
[d4a3ee5] | 85 | extern size_t str_nlength(const char *str, size_t size);
|
---|
| 86 | extern size_t wstr_nlength(const wchar_t *str, size_t size);
|
---|
[f2b8cdc] | 87 |
|
---|
[be2a38ad] | 88 | extern size_t chr_width(wchar_t ch);
|
---|
| 89 | extern size_t str_width(const char *str);
|
---|
| 90 |
|
---|
[f2b8cdc] | 91 | extern bool ascii_check(wchar_t ch);
|
---|
| 92 | extern bool chr_check(wchar_t ch);
|
---|
| 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);
|
---|
| 100 |
|
---|
[6eb2e96] | 101 | extern void str_cpy(char *dest, size_t size, const char *src);
|
---|
| 102 | extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
|
---|
[4482bc7] | 103 | extern void str_append(char *dest, size_t size, const char *src);
|
---|
[6eb2e96] | 104 |
|
---|
[b7fd2a0] | 105 | extern errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n);
|
---|
[81e9cb3] | 106 | extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
|
---|
[b67c7d64] | 107 | extern char *wstr_to_astr(const wchar_t *src);
|
---|
[81e9cb3] | 108 | extern void str_to_wstr(wchar_t *dest, size_t dlen, const char *src);
|
---|
[22cf42d9] | 109 | extern wchar_t *str_to_awstr(const char *src);
|
---|
[b7fd2a0] | 110 | extern errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src);
|
---|
| 111 | extern errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src);
|
---|
[b2906c0] | 112 | extern size_t utf16_wsize(const uint16_t *ustr);
|
---|
[f2b8cdc] | 113 |
|
---|
[dd2cfa7] | 114 | extern char *str_chr(const char *str, wchar_t ch);
|
---|
| 115 | extern char *str_rchr(const char *str, wchar_t ch);
|
---|
[da680b4b] | 116 | extern char *str_str(const char *hs, const char *n);
|
---|
[f2b8cdc] | 117 |
|
---|
[1737bfb] | 118 | extern void str_rtrim(char *str, wchar_t ch);
|
---|
| 119 | extern void str_ltrim(char *str, wchar_t ch);
|
---|
| 120 |
|
---|
[d4a3ee5] | 121 | extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos);
|
---|
| 122 | extern bool wstr_remove(wchar_t *str, size_t pos);
|
---|
[f2b8cdc] | 123 |
|
---|
[d066259] | 124 | extern char *str_dup(const char *src);
|
---|
| 125 | extern char *str_ndup(const char *src, size_t n);
|
---|
[095003a8] | 126 |
|
---|
[ee3f6f6] | 127 | extern char *str_tok(char *, const char *, char **);
|
---|
| 128 |
|
---|
[b7fd2a0] | 129 | extern errno_t str_uint8_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 130 | uint8_t *);
|
---|
[b7fd2a0] | 131 | extern errno_t str_uint16_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 132 | uint16_t *);
|
---|
[b7fd2a0] | 133 | extern errno_t str_uint32_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 134 | uint32_t *);
|
---|
[b7fd2a0] | 135 | extern errno_t str_uint64_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 136 | uint64_t *);
|
---|
[b7fd2a0] | 137 | extern errno_t str_size_t(const char *, const char **, unsigned int, bool,
|
---|
[b49d872] | 138 | size_t *);
|
---|
[1c9bf292] | 139 | extern errno_t str_int64_t(const char *, const char **, unsigned int, bool,
|
---|
[af8bda0] | 140 | int64_t *);
|
---|
[d47279b] | 141 |
|
---|
[933cadf] | 142 | extern void order_suffix(const uint64_t, uint64_t *, char *);
|
---|
| 143 | extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
|
---|
[e535eeb] | 144 |
|
---|
[f2b8cdc] | 145 | /*
|
---|
| 146 | * TODO: Get rid of this.
|
---|
| 147 | */
|
---|
[c9857c6] | 148 |
|
---|
[1526594c] | 149 | extern long int strtol(const char *, char **, int);
|
---|
| 150 | extern unsigned long strtoul(const char *, char **, int);
|
---|
[c9857c6] | 151 |
|
---|
[bc56f30] | 152 | __HELENOS_DECLS_END;
|
---|
[82fd245] | 153 |
|
---|
[7ad3c2f] | 154 | #endif
|
---|
[b2951e2] | 155 |
|
---|
[fadd381] | 156 | /** @}
|
---|
[b2951e2] | 157 | */
|
---|