Reunite uspace string-to-int conversion functions
[helenos.git] / uspace / lib / c / include / str.h
blob1d892d4844515e508338492f6fb01eb51f2c77b5
1 /*
2 * Copyright (c) 2001-2004 Jakub Jermar
3 * Copyright (c) 2005 Martin Decky
4 * Copyright (c) 2011 Oleg Romanenko
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
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.
31 /** @addtogroup libc
32 * @{
34 /** @file
37 #ifndef _LIBC_STR_H_
38 #define _LIBC_STR_H_
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 #include <errno.h>
45 #include <stdbool.h>
46 #include <stddef.h>
47 #include <stdint.h>
49 #include <mem.h>
51 /* Common Unicode characters */
52 #define U_SPECIAL '?'
54 /** No size limit constant */
55 #define STR_NO_LIMIT ((size_t) -1)
57 /** Maximum size of a string containing @c length characters */
58 #define STR_BOUNDS(length) ((length) << 2)
60 /**
61 * Maximum size of a buffer needed to a string converted from space-padded
62 * ASCII of size @a spa_size using spascii_to_str().
64 #define SPASCII_STR_BUFSIZE(spa_size) ((spa_size) + 1)
66 extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
67 extern wchar_t str_decode_reverse(const char *str, size_t *offset, size_t sz);
68 extern errno_t chr_encode(wchar_t ch, char *str, size_t *offset, size_t sz);
70 extern size_t str_size(const char *str);
71 extern size_t wstr_size(const wchar_t *str);
73 extern size_t str_nsize(const char *str, size_t max_size);
74 extern size_t wstr_nsize(const wchar_t *str, size_t max_size);
76 extern size_t str_lsize(const char *str, size_t max_len);
77 extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
79 extern size_t str_length(const char *str);
80 extern size_t wstr_length(const wchar_t *wstr);
82 extern size_t str_nlength(const char *str, size_t size);
83 extern size_t wstr_nlength(const wchar_t *str, size_t size);
85 extern size_t chr_width(wchar_t ch);
86 extern size_t str_width(const char *str);
88 extern bool ascii_check(wchar_t ch);
89 extern bool chr_check(wchar_t ch);
91 extern int str_cmp(const char *s1, const char *s2);
92 extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
93 extern int str_casecmp(const char *s1, const char *s2);
94 extern int str_lcasecmp(const char *s1, const char *s2, size_t max_len);
96 extern bool str_test_prefix(const char *s, const char *p);
98 extern void str_cpy(char *dest, size_t size, const char *src);
99 extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
100 extern void str_append(char *dest, size_t size, const char *src);
102 extern errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n);
103 extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
104 extern char *wstr_to_astr(const wchar_t *src);
105 extern void str_to_wstr(wchar_t *dest, size_t dlen, const char *src);
106 extern wchar_t *str_to_awstr(const char *src);
107 extern errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src);
108 extern errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src);
109 extern size_t utf16_wsize(const uint16_t *ustr);
111 extern char *str_chr(const char *str, wchar_t ch);
112 extern char *str_rchr(const char *str, wchar_t ch);
113 extern char *str_str(const char *hs, const char *n);
115 extern void str_rtrim(char *str, wchar_t ch);
116 extern void str_ltrim(char *str, wchar_t ch);
118 extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos);
119 extern bool wstr_remove(wchar_t *str, size_t pos);
121 extern char *str_dup(const char *src);
122 extern char *str_ndup(const char *src, size_t n);
124 extern char *str_tok(char *, const char *, char **);
126 extern errno_t str_uint8_t(const char *, const char **, unsigned int, bool,
127 uint8_t *);
128 extern errno_t str_uint16_t(const char *, const char **, unsigned int, bool,
129 uint16_t *);
130 extern errno_t str_uint32_t(const char *, const char **, unsigned int, bool,
131 uint32_t *);
132 extern errno_t str_uint64_t(const char *, const char **, unsigned int, bool,
133 uint64_t *);
134 extern errno_t str_size_t(const char *, const char **, unsigned int, bool,
135 size_t *);
136 extern errno_t str_int64_t(const char *, const char **, unsigned int, bool,
137 int64_t *);
139 extern void order_suffix(const uint64_t, uint64_t *, char *);
140 extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
143 * TODO: Get rid of this.
146 extern long int strtol(const char *, char **, int);
147 extern unsigned long strtoul(const char *, char **, int);
149 #ifdef __cplusplus
151 #endif
153 #endif
155 /** @}