/[zanavi_public1]/navit/navit/maptool/cfustring.h
ZANavi

Contents of /navit/navit/maptool/cfustring.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 4774 byte(s)
new map version, lots of fixes and experimental new features
1 /* Creation date: 2005-06-26 19:56:34
2 * Authors: Don
3 * Change log:
4 */
5
6 /* Copyright (c) 2005 Don Owens
7 All rights reserved.
8
9 This code is released under the BSD license:
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions
13 are met:
14
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the following
20 disclaimer in the documentation and/or other materials provided
21 with the distribution.
22
23 * Neither the name of the author nor the names of its
24 contributors may be used to endorse or promote products derived
25 from this software without specific prior written permission.
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
38 OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 #ifndef _CFU_STRING_H_
42 #define _CFU_STRING_H_
43
44 #include <cfu.h>
45
46 #include <string.h>
47 #include <stdarg.h>
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 struct cfustring;
54 typedef struct cfustring cfustring_t;
55
56 /* Returns a new String. */
57 extern cfustring_t * cfustring_new();
58
59 /* Returns a new String, but preallocates a buffer of the given size. */
60 extern cfustring_t * cfustring_new_with_initial_size(size_t initial_size);
61
62 /* Returns a new String initalized with the given string. */
63 extern cfustring_t * cfustring_new_from_string(const char *string);
64
65 /* Overwrite anything currently in cfu_str with string. */
66 extern int cfustring_dup(cfustring_t *cfu_str, const char *string);
67
68 /* Truncate the string. */
69 extern int cfustring_clear(cfustring_t *cfu_str);
70
71 /* Append str to the end of the buffer in cfu_str. */
72 extern int cfustring_append(cfustring_t *cfu_str, const char *str);
73
74 /* Get the buffer used to hold the string. Do not free() it, as it is
75 * used directly by cfustring and will be destroyed when
76 * cfustring_destroy() is called.
77 */
78 extern char * cfustring_get_buffer(cfustring_t *cfu_str);
79
80 /* Same as cfustring_get_buffer(), except return a copy of the string.
81 * Caller is responsible for deallocating the buffer with free().
82 */
83 extern char * cfustring_get_buffer_copy(cfustring_t *cfu_str);
84
85 /* Split cfu_str on one or more delimiting strings, e.g.,
86 * cfustring_split(cfu_str, 2, 0, "\r\n", "\n"). Use a limit > 0 if
87 * you want to only get back a certain number of strings and ignore
88 * any extra delimiters.
89 */
90 extern cfustring_t ** cfustring_split(cfustring_t *cfu_str, size_t *num_strings,
91 size_t limit, ...);
92
93 /* Same as cfustring_split(), except return an array of C-strings.
94 * Caller is responsible for deallocating the buffers.
95 */
96 extern char ** cfustring_split_to_c_str(cfustring_t *cfu_str, size_t *num_strings,
97 size_t limit, ...);
98
99 /* Free all resources allocated by cfu_str. */
100 extern int cfustring_destroy(cfustring_t *cfu_str);
101
102 /* Duplicate the C string str. Caller must free with free(). */
103 extern char * cfustring_dup_c_str(const char *str);
104
105 /* Same as cfustring_dup_c_str(), but only copy at most n chars */
106 extern char * cfustring_dup_c_str_n(const char *str, size_t n);
107
108 /* Like sprintf(), but writes to a self-extending string. */
109 extern size_t cfustring_sprintf(cfustring_t *cfu_str, const char *fmt, ...);
110
111 /* Like vsprintf(), but writes to a self-extending string. */
112 extern size_t cfustring_vsprintf(cfustring_t *cfu_str, const char *fmt, va_list ap);
113
114 /* Similar to sprintf(), but allocates a C string of the
115 * appropriate size for you and returns it.
116 */
117 extern char * cfustring_sprintf_c_str(const char *fmt, ...);
118
119 /* Like cfustring_split_to_c_str(), but split a char * instead of a cfustring_t *. */
120 extern char ** cfustring_c_str_split(const char *c_str, size_t *num_strings, size_t limit, ...);
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif

   
Visit the ZANavi Wiki