Welcome to mirror list, hosted at ThFree Co, Russian Federation.

c_string.h « std « src « csync - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d80727a634011d06ca6f78f9302f40f20bbd9b1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 * cynapses libc functions
 *
 * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
 * Copyright (c) 2012-2013 by Klaas Freitag <freitag@owncloud.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/**
 * @file c_string.h
 *
 * @brief Interface of the cynapses string implementations
 *
 * @defgroup cynStringInternals cynapses libc string functions
 * @ingroup cynLibraryAPI
 *
 * @{
 */
#ifndef _C_STR_H
#define _C_STR_H

#include "c_private.h"
#include "c_macro.h"

#include <stdlib.h>

struct c_strlist_s; typedef struct c_strlist_s c_strlist_t;

/**
 * @brief Structure for a stringlist
 *
 * Using a for loop you can access the strings saved in the vector.
 *
 * c_strlist_t strlist;
 * int i;
 * for (i = 0; i < strlist->count; i++) {
 *   printf("value: %s", strlist->vector[i];
 * }
 */
struct c_strlist_s {
  /** The string vector */
  char **vector;
  /** The count of the strings saved in the vector */
  size_t count;
  /** Size of strings allocated */
  size_t size;
};

/**
 * @brief Compare to strings if they are equal.
 *
 * @param a  First string to compare.
 * @param b  Second string to compare.
 *
 * @return  1 if they are equal, 0 if not.
 */
int c_streq(const char *a, const char *b);

/**
 * @brief Create a new stringlist.
 *
 * @param size  Size to allocate.
 *
 * @return  Pointer to the newly allocated stringlist. NULL if an error occured.
 */
c_strlist_t *c_strlist_new(size_t size);

/**
 * @brief Expand the stringlist
 *
 * @param strlist  Stringlist to expand
 * @param size     New size of the strlinglist to expand
 *
 * @return  Pointer to the expanded stringlist. NULL if an error occured.
 */
c_strlist_t *c_strlist_expand(c_strlist_t *strlist, size_t size);

/**
 * @brief  Add a string to the stringlist.
 *
 * Duplicates the string and stores it in the stringlist.
 *
 * @param strlist  Stringlist to add the string.
 * @param string   String to add.
 *
 * @return  0 on success, less than 0 and errno set if an error occured.
 *          ENOBUFS if the list is full.
 */
int c_strlist_add(c_strlist_t *strlist, const char *string);

/**
 * @brief Removes all strings from the list.
 *
 * Frees the strings.
 *
 * @param strlist  Stringlist to clear
 */
void c_strlist_clear(c_strlist_t *strlist);

/**
 * @brief Destroy the memory of the stringlist.
 *
 * Frees the strings and the stringlist.
 *
 * @param strlist  Stringlist to destroy
 */
void c_strlist_destroy(c_strlist_t *strlist);

/**
 * @brief Convert a platform locale string to utf8.
 *
 * This function is part of the multi platform abstraction of basic file
 * operations to handle various platform encoding correctly.
 *
 * Instead of using the standard file operations the multi platform aliases
 * defined in c_private.h have to be used instead.
 *
 * To convert path names returned by these functions to the internally used
 * utf8 format this function has to be used. The returned string has to
 * be freed by c_free_locale_string(). On some platforms this method allocates
 * memory and on others not but it has never to be cared about.
 *
 * @param  str     The multibyte encoded string to convert
 *
 * @return The malloced converted string or NULL on error.
 *
 * @see c_free_locale_string()
 * @see c_utf8_to_locale()
 *
 */
 char*   c_utf8_from_locale(const mbchar_t *str);

/**
 * @brief Convert a utf8 encoded string to platform specific locale.
 *
 * This function is part of the multi platform abstraction of basic file
 * operations to handle various platform encoding correctly.
 *
 * Instead of using the standard file operations the multi platform aliases
 * defined in c_private.h have to be used instead.
 *
 * To convert path names as input for the cross platform functions from the
 * internally used utf8 format, this function has to be used.
 * The returned string has to be freed by c_free_locale_string(). On some
 * platforms this method allocates memory and on others not but it has never
 * sto be cared about.
 *
 * @param  str     The utf8 string to convert.
 *
 * @return The malloced converted multibyte string or NULL on error.
 *
 * @see c_free_locale_string()
 * @see c_utf8_from_locale()
 *
 */
mbchar_t* c_utf8_to_locale(const char *wstr);

#if defined(_WIN32) || defined(WITH_ICONV)

/**
 * @brief Free buffer malloced by c_utf8_from_locale or c_utf8_to_locale().
 *
 * This function is part of the multi platform abstraction of basic file
 * operations to handle various platform encoding correctly.
 *
 * Instead of using the standard file operations the multi platform aliases
 * defined in c_private.h have to be used instead.
 *
 * This function frees the memory that was allocated by a previous call to
 * c_utf8_to_locale() or c_utf8_from_locale().
 *
 * @param  buf     The buffer to free.
 *
 * @see c_utf8_from_locale(), c_utf8_to_locale()
 *
 */
#define c_free_locale_string(x) SAFE_FREE(x)
#else
#define c_free_locale_string(x) (void)x
#endif

/**
 * }@
 */
#endif /* _C_STR_H */