aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/include/eina_inline_str.x
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/include/eina_inline_str.x')
-rw-r--r--libraries/eina/src/include/eina_inline_str.x76
1 files changed, 76 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_inline_str.x b/libraries/eina/src/include/eina_inline_str.x
new file mode 100644
index 0000000..2daeb85
--- /dev/null
+++ b/libraries/eina/src/include/eina_inline_str.x
@@ -0,0 +1,76 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2002-2008 Gustavo Sverzut Barbieri
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef EINA_STR_INLINE_H_
20#define EINA_STR_INLINE_H_
21
22/**
23 * @addtogroup Eina_String_Group String
24 *
25 * @{
26 */
27
28/**
29 * @brief Count up to a given amount of bytes of the given string.
30 *
31 * @param str The string pointer.
32 * @param maxlen The maximum length to allow.
33 * @return the string size or (size_t)-1 if greater than @a maxlen.
34 *
35 * This function returns the size of @p str, up to @p maxlen
36 * characters. It avoid needless iterations after that size. @p str
37 * must be a valid pointer and MUST not be @c NULL, otherwise this
38 * function will crash. This function returns the string size, or
39 * (size_t)-1 if the size is greater than @a maxlen.
40 */
41static inline size_t
42eina_strlen_bounded(const char *str, size_t maxlen)
43{
44 const char *itr, *str_maxend = str + maxlen;
45 for (itr = str; *itr != '\0'; itr++)
46 if (itr == str_maxend) return (size_t)-1;
47 return itr - str;
48}
49
50/**
51 * @brief Join two strings of known length.
52 *
53 * @param dst The buffer to store the result.
54 * @param size Size (in byte) of the buffer.
55 * @param sep The separator character to use.
56 * @param a First string to use, before @p sep.
57 * @param b Second string to use, after @p sep.
58 * @return The number of characters printed.
59 *
60 * This function is similar to eina_str_join_len(), but will compute
61 * the length of @p a and @p b using strlen().
62 *
63 * @see eina_str_join_len()
64 * @see eina_str_join_static()
65 */
66static inline size_t
67eina_str_join(char *dst, size_t size, char sep, const char *a, const char *b)
68{
69 return eina_str_join_len(dst, size, sep, a, strlen(a), b, strlen(b));
70}
71
72/**
73 * @}
74 */
75
76#endif /* EINA_STR_INLINE_H_ */