1251881Speter/**
2251881Speter * @copyright
3251881Speter * ====================================================================
4251881Speter *    Licensed to the Apache Software Foundation (ASF) under one
5251881Speter *    or more contributor license agreements.  See the NOTICE file
6251881Speter *    distributed with this work for additional information
7251881Speter *    regarding copyright ownership.  The ASF licenses this file
8251881Speter *    to you under the Apache License, Version 2.0 (the
9251881Speter *    "License"); you may not use this file except in compliance
10251881Speter *    with the License.  You may obtain a copy of the License at
11251881Speter *
12251881Speter *      http://www.apache.org/licenses/LICENSE-2.0
13251881Speter *
14251881Speter *    Unless required by applicable law or agreed to in writing,
15251881Speter *    software distributed under the License is distributed on an
16251881Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17251881Speter *    KIND, either express or implied.  See the License for the
18251881Speter *    specific language governing permissions and limitations
19251881Speter *    under the License.
20251881Speter * ====================================================================
21251881Speter * @endcopyright
22251881Speter *
23251881Speter * @file svn_string.h
24251881Speter * @brief Counted-length strings for Subversion, plus some C string goodies.
25251881Speter *
26251881Speter * There are two string datatypes: @c svn_string_t and @c svn_stringbuf_t.
27251881Speter * The former is a simple pointer/length pair useful for passing around
28251881Speter * strings (or arbitrary bytes) with a counted length. @c svn_stringbuf_t is
29251881Speter * buffered to enable efficient appending of strings without an allocation
30251881Speter * and copy for each append operation.
31251881Speter *
32251881Speter * @c svn_string_t contains a <tt>const char *</tt> for its data, so it is
33251881Speter * most appropriate for constant data and for functions which expect constant,
34251881Speter * counted data. Functions should generally use <tt>const @c svn_string_t
35251881Speter * *</tt> as their parameter to indicate they are expecting a constant,
36251881Speter * counted string.
37251881Speter *
38251881Speter * @c svn_stringbuf_t uses a plain <tt>char *</tt> for its data, so it is
39251881Speter * most appropriate for modifiable data.
40251881Speter *
41251881Speter * <h3>Invariants</h3>
42251881Speter *
43251881Speter *   1. Null termination:
44251881Speter *
45251881Speter *      Both structures maintain a significant invariant:
46251881Speter *
47251881Speter *         <tt>s->data[s->len] == '\\0'</tt>
48251881Speter *
49251881Speter *      The functions defined within this header file will maintain
50251881Speter *      the invariant (which does imply that memory is
51251881Speter *      allocated/defined as @c len+1 bytes).  If code outside of the
52251881Speter *      @c svn_string.h functions manually builds these structures,
53251881Speter *      then they must enforce this invariant.
54251881Speter *
55251881Speter *      Note that an @c svn_string(buf)_t may contain binary data,
56251881Speter *      which means that strlen(s->data) does not have to equal @c
57251881Speter *      s->len. The null terminator is provided to make it easier to
58251881Speter *      pass @c s->data to C string interfaces.
59251881Speter *
60251881Speter *
61251881Speter *   2. Non-NULL input:
62251881Speter *
63251881Speter *      All the functions assume their input data pointer is non-NULL,
64251881Speter *      unless otherwise documented, and may seg fault if passed
65251881Speter *      NULL.  The input data may *contain* null bytes, of course, just
66251881Speter *      the data pointer itself must not be NULL.
67251881Speter *
68251881Speter * <h3>Memory allocation</h3>
69251881Speter *
70251881Speter *   All the functions make a deep copy of all input data, and never store
71251881Speter *   a pointer to the original input data.
72251881Speter */
73251881Speter
74251881Speter
75251881Speter#ifndef SVN_STRING_H
76251881Speter#define SVN_STRING_H
77251881Speter
78251881Speter#include <apr.h>          /* for apr_size_t */
79251881Speter#include <apr_pools.h>    /* for apr_pool_t */
80251881Speter#include <apr_tables.h>   /* for apr_array_header_t */
81251881Speter
82251881Speter#include "svn_types.h"    /* for svn_boolean_t, svn_error_t */
83251881Speter
84251881Speter#ifdef __cplusplus
85251881Speterextern "C" {
86251881Speter#endif /* __cplusplus */
87251881Speter
88251881Speter/**
89251881Speter * @defgroup svn_string String handling
90251881Speter * @{
91251881Speter */
92251881Speter
93251881Speter
94251881Speter
95251881Speter/** A simple counted string. */
96251881Spetertypedef struct svn_string_t
97251881Speter{
98251881Speter  const char *data; /**< pointer to the bytestring */
99251881Speter  apr_size_t len;   /**< length of bytestring */
100251881Speter} svn_string_t;
101251881Speter
102251881Speter/** A buffered string, capable of appending without an allocation and copy
103251881Speter * for each append. */
104251881Spetertypedef struct svn_stringbuf_t
105251881Speter{
106251881Speter  /** a pool from which this string was originally allocated, and is not
107251881Speter   * necessarily specific to this string.  This is used only for allocating
108251881Speter   * more memory from when the string needs to grow.
109251881Speter   */
110251881Speter  apr_pool_t *pool;
111251881Speter
112251881Speter  /** pointer to the bytestring */
113251881Speter  char *data;
114251881Speter
115251881Speter  /** length of bytestring */
116251881Speter  apr_size_t len;
117251881Speter
118251881Speter  /** total size of buffer allocated */
119251881Speter  apr_size_t blocksize;
120251881Speter} svn_stringbuf_t;
121251881Speter
122251881Speter
123251881Speter/**
124251881Speter * @defgroup svn_string_svn_string_t svn_string_t functions
125251881Speter * @{
126251881Speter */
127251881Speter
128251881Speter/** Create a new string copied from the null-terminated C string @a cstring.
129251881Speter */
130251881Spetersvn_string_t *
131251881Spetersvn_string_create(const char *cstring, apr_pool_t *pool);
132251881Speter
133251881Speter/** Create a new, empty string.
134251881Speter *
135251881Speter * @since New in 1.8.
136251881Speter */
137251881Spetersvn_string_t *
138251881Spetersvn_string_create_empty(apr_pool_t *pool);
139251881Speter
140251881Speter/** Create a new string copied from a generic string of bytes, @a bytes, of
141251881Speter * length @a size bytes.  @a bytes is NOT assumed to be null-terminated, but
142251881Speter * the new string will be.
143299742Sdim *
144299742Sdim * @since Since 1.9, @a bytes can be NULL if @a size is zero.
145251881Speter */
146251881Spetersvn_string_t *
147251881Spetersvn_string_ncreate(const char *bytes, apr_size_t size, apr_pool_t *pool);
148251881Speter
149251881Speter/** Create a new string copied from the stringbuf @a strbuf.
150251881Speter */
151251881Spetersvn_string_t *
152251881Spetersvn_string_create_from_buf(const svn_stringbuf_t *strbuf, apr_pool_t *pool);
153251881Speter
154251881Speter/** Create a new string by printf-style formatting using @a fmt and the
155251881Speter * variable arguments, which are as appropriate for apr_psprintf().
156251881Speter */
157251881Spetersvn_string_t *
158251881Spetersvn_string_createf(apr_pool_t *pool, const char *fmt, ...)
159251881Speter  __attribute__((format(printf, 2, 3)));
160251881Speter
161251881Speter/** Create a new string by printf-style formatting using @c fmt and @a ap.
162251881Speter * This is the same as svn_string_createf() except for the different
163251881Speter * way of passing the variable arguments.
164251881Speter */
165251881Spetersvn_string_t *
166251881Spetersvn_string_createv(apr_pool_t *pool, const char *fmt, va_list ap)
167251881Speter  __attribute__((format(printf, 2, 0)));
168251881Speter
169251881Speter/** Return TRUE if @a str is empty (has length zero). */
170251881Spetersvn_boolean_t
171251881Spetersvn_string_isempty(const svn_string_t *str);
172251881Speter
173299742Sdim/** Return a duplicate of @a original_string.
174299742Sdim *
175299742Sdim * @since Since 1.9, @a original_string can be NULL in which case NULL will
176299742Sdim * be returned.
177299742Sdim */
178251881Spetersvn_string_t *
179251881Spetersvn_string_dup(const svn_string_t *original_string, apr_pool_t *pool);
180251881Speter
181251881Speter/** Return @c TRUE iff @a str1 and @a str2 have identical length and data. */
182251881Spetersvn_boolean_t
183251881Spetersvn_string_compare(const svn_string_t *str1, const svn_string_t *str2);
184251881Speter
185251881Speter/** Return offset of first non-whitespace character in @a str, or return
186251881Speter * @a str->len if none.
187251881Speter */
188251881Speterapr_size_t
189251881Spetersvn_string_first_non_whitespace(const svn_string_t *str);
190251881Speter
191251881Speter/** Return position of last occurrence of @a ch in @a str, or return
192251881Speter * @a str->len if no occurrence.
193251881Speter */
194251881Speterapr_size_t
195251881Spetersvn_string_find_char_backward(const svn_string_t *str, char ch);
196251881Speter
197251881Speter/** @} */
198251881Speter
199251881Speter
200251881Speter/**
201251881Speter * @defgroup svn_string_svn_stringbuf_t svn_stringbuf_t functions
202251881Speter * @{
203251881Speter */
204251881Speter
205251881Speter/** Create a new stringbuf copied from the null-terminated C string
206251881Speter * @a cstring.
207251881Speter */
208251881Spetersvn_stringbuf_t *
209251881Spetersvn_stringbuf_create(const char *cstring, apr_pool_t *pool);
210251881Speter
211251881Speter/** Create a new stringbuf copied from the generic string of bytes, @a bytes,
212251881Speter * of length @a size bytes.  @a bytes is NOT assumed to be null-terminated,
213251881Speter * but the new stringbuf will be.
214299742Sdim *
215299742Sdim * @since Since 1.9, @a bytes can be NULL if @a size is zero.
216251881Speter */
217251881Spetersvn_stringbuf_t *
218251881Spetersvn_stringbuf_ncreate(const char *bytes, apr_size_t size, apr_pool_t *pool);
219251881Speter
220251881Speter/** Create a new, empty stringbuf.
221251881Speter *
222251881Speter * @since New in 1.8.
223251881Speter */
224251881Spetersvn_stringbuf_t *
225251881Spetersvn_stringbuf_create_empty(apr_pool_t *pool);
226251881Speter
227251881Speter/** Create a new, empty stringbuf with at least @a minimum_size bytes of
228251881Speter * space available in the memory block.
229251881Speter *
230251881Speter * The allocated string buffer will be at least one byte larger than
231251881Speter * @a minimum_size to account for a final '\\0'.
232251881Speter *
233251881Speter * @since New in 1.6.
234251881Speter */
235251881Spetersvn_stringbuf_t *
236251881Spetersvn_stringbuf_create_ensure(apr_size_t minimum_size, apr_pool_t *pool);
237251881Speter
238251881Speter/** Create a new stringbuf copied from the string @a str.
239251881Speter */
240251881Spetersvn_stringbuf_t *
241251881Spetersvn_stringbuf_create_from_string(const svn_string_t *str, apr_pool_t *pool);
242251881Speter
243299742Sdim/** Create a new stringbuf using the given @a str as initial buffer.
244299742Sdim * Allocate the result in @a pool.  In contrast to #svn_stringbuf_create,
245299742Sdim * the contents of @a str may change when the stringbuf gets modified.
246299742Sdim *
247299742Sdim * @since New in 1.9
248299742Sdim */
249299742Sdimsvn_stringbuf_t *
250299742Sdimsvn_stringbuf_create_wrap(char *str, apr_pool_t *pool);
251299742Sdim
252251881Speter/** Create a new stringbuf by printf-style formatting using @a fmt and the
253251881Speter * variable arguments, which are as appropriate for apr_psprintf().
254251881Speter */
255251881Spetersvn_stringbuf_t *
256251881Spetersvn_stringbuf_createf(apr_pool_t *pool, const char *fmt, ...)
257251881Speter  __attribute__((format(printf, 2, 3)));
258251881Speter
259251881Speter/** Create a new stringbuf by printf-style formatting using @c fmt and @a ap.
260251881Speter * This is the same as svn_stringbuf_createf() except for the different
261251881Speter * way of passing the variable arguments.
262251881Speter */
263251881Spetersvn_stringbuf_t *
264251881Spetersvn_stringbuf_createv(apr_pool_t *pool, const char *fmt, va_list ap)
265251881Speter  __attribute__((format(printf, 2, 0)));
266251881Speter
267251881Speter/** Make sure that @a str has at least @a minimum_size
268251881Speter * bytes of space available in the memory block.
269251881Speter *
270251881Speter * The allocated string buffer will be at least one byte larger than
271251881Speter * @a minimum_size to account for a final '\\0'.
272251881Speter *
273251881Speter * @note: Before Subversion 1.8 this function did not ensure space for
274251881Speter * one byte more than @a minimum_size.  If compatibility with pre-1.8
275251881Speter * behaviour is required callers must assume space for only
276251881Speter * @a minimum_size-1 data bytes plus a final '\\0'.
277251881Speter */
278251881Spetervoid
279251881Spetersvn_stringbuf_ensure(svn_stringbuf_t *str, apr_size_t minimum_size);
280251881Speter
281251881Speter/** Set @a str to a copy of the null-terminated C string @a value. */
282251881Spetervoid
283251881Spetersvn_stringbuf_set(svn_stringbuf_t *str, const char *value);
284251881Speter
285251881Speter/** Set @a str to empty (zero length). */
286251881Spetervoid
287251881Spetersvn_stringbuf_setempty(svn_stringbuf_t *str);
288251881Speter
289251881Speter/** Return @c TRUE if @a str is empty (has length zero). */
290251881Spetersvn_boolean_t
291251881Spetersvn_stringbuf_isempty(const svn_stringbuf_t *str);
292251881Speter
293251881Speter/** Chop @a nbytes bytes off end of @a str, but not more than @a str->len. */
294251881Spetervoid
295251881Spetersvn_stringbuf_chop(svn_stringbuf_t *str, apr_size_t nbytes);
296251881Speter
297251881Speter/** Fill @a str with character @a c. */
298251881Spetervoid
299251881Spetersvn_stringbuf_fillchar(svn_stringbuf_t *str, unsigned char c);
300251881Speter
301251881Speter/** Append the single character @a byte onto @a targetstr.
302251881Speter *
303251881Speter * This is an optimized version of svn_stringbuf_appendbytes()
304251881Speter * that is much faster to call and execute. Gains vary with the ABI.
305251881Speter * The advantages extend beyond the actual call because the reduced
306251881Speter * register pressure allows for more optimization within the caller.
307251881Speter *
308299742Sdim * Reallocs if necessary. @a targetstr is affected, nothing else is.
309251881Speter * @since New in 1.7.
310251881Speter */
311251881Spetervoid
312251881Spetersvn_stringbuf_appendbyte(svn_stringbuf_t *targetstr,
313251881Speter                         char byte);
314251881Speter
315299742Sdim/** Append the array of bytes @a bytes of length @a count onto @a targetstr.
316251881Speter *
317299742Sdim * Reallocs if necessary. @a targetstr is affected, nothing else is.
318299742Sdim *
319299742Sdim * @since 1.9 @a bytes can be NULL if @a count is zero.
320251881Speter */
321251881Spetervoid
322251881Spetersvn_stringbuf_appendbytes(svn_stringbuf_t *targetstr,
323251881Speter                          const char *bytes,
324251881Speter                          apr_size_t count);
325251881Speter
326299742Sdim/** Append @a byte @a count times onto @a targetstr.
327299742Sdim *
328299742Sdim * Reallocs if necessary. @a targetstr is affected, nothing else is.
329299742Sdim * @since New in 1.9.
330299742Sdim */
331299742Sdimvoid
332299742Sdimsvn_stringbuf_appendfill(svn_stringbuf_t *targetstr,
333299742Sdim                         char byte,
334299742Sdim                         apr_size_t count);
335299742Sdim
336251881Speter/** Append the stringbuf @c appendstr onto @a targetstr.
337251881Speter *
338299742Sdim * Reallocs if necessary. @a targetstr is affected, nothing else is.
339251881Speter */
340251881Spetervoid
341251881Spetersvn_stringbuf_appendstr(svn_stringbuf_t *targetstr,
342251881Speter                        const svn_stringbuf_t *appendstr);
343251881Speter
344251881Speter/** Append the C string @a cstr onto @a targetstr.
345251881Speter *
346299742Sdim * Reallocs if necessary. @a targetstr is affected, nothing else is.
347251881Speter */
348251881Spetervoid
349251881Spetersvn_stringbuf_appendcstr(svn_stringbuf_t *targetstr,
350251881Speter                         const char *cstr);
351251881Speter
352299742Sdim/** Insert into @a str at position @a pos an array of bytes @a bytes
353299742Sdim * which is @a count bytes long.
354251881Speter *
355299742Sdim * The resulting string will be @c count+str->len bytes long.  If
356299742Sdim * @a pos is larger than or equal to @c str->len, simply append @a bytes.
357299742Sdim *
358251881Speter * Reallocs if necessary. @a str is affected, nothing else is.
359251881Speter *
360299742Sdim * @note The inserted string may be a sub-range of @a str.
361251881Speter *
362251881Speter * @since New in 1.8.
363299742Sdim *
364299742Sdim * @since Since 1.9, @a bytes can be NULL if @a count is zero.
365251881Speter */
366251881Spetervoid
367251881Spetersvn_stringbuf_insert(svn_stringbuf_t *str,
368251881Speter                     apr_size_t pos,
369251881Speter                     const char *bytes,
370251881Speter                     apr_size_t count);
371251881Speter
372299742Sdim/** Remove @a count bytes from @a str, starting at position @a pos.
373299742Sdim *
374299742Sdim * If that range exceeds the current string data, truncate @a str at
375299742Sdim * @a pos.  If @a pos is larger than or equal to @c str->len, this will
376251881Speter * be a no-op.  Otherwise, the resulting string will be @c str->len-count
377251881Speter * bytes long.
378251881Speter *
379251881Speter * @since New in 1.8.
380251881Speter */
381251881Spetervoid
382251881Spetersvn_stringbuf_remove(svn_stringbuf_t *str,
383251881Speter                     apr_size_t pos,
384251881Speter                     apr_size_t count);
385251881Speter
386251881Speter/** Replace in @a str the substring which starts at @a pos and is @a
387299742Sdim * old_count bytes long with a new substring @a bytes which is @a
388299742Sdim * new_count bytes long.
389251881Speter *
390251881Speter * This is faster but functionally equivalent to the following sequence:
391251881Speter * @code
392251881Speter     svn_stringbuf_remove(str, pos, old_count);
393251881Speter     svn_stringbuf_insert(str, pos, bytes, new_count);
394251881Speter * @endcode
395251881Speter *
396251881Speter * @since New in 1.8.
397299742Sdim *
398299742Sdim * @since Since 1.9, @a bytes can be NULL if @a new_count is zero.
399251881Speter */
400251881Spetervoid
401251881Spetersvn_stringbuf_replace(svn_stringbuf_t *str,
402251881Speter                      apr_size_t pos,
403251881Speter                      apr_size_t old_count,
404251881Speter                      const char *bytes,
405251881Speter                      apr_size_t new_count);
406251881Speter
407251881Speter/** Return a duplicate of @a original_string. */
408251881Spetersvn_stringbuf_t *
409251881Spetersvn_stringbuf_dup(const svn_stringbuf_t *original_string, apr_pool_t *pool);
410251881Speter
411251881Speter/** Return @c TRUE iff @a str1 and @a str2 have identical length and data. */
412251881Spetersvn_boolean_t
413251881Spetersvn_stringbuf_compare(const svn_stringbuf_t *str1,
414251881Speter                      const svn_stringbuf_t *str2);
415251881Speter
416251881Speter/** Return offset of first non-whitespace character in @a str, or return
417251881Speter * @a str->len if none.
418251881Speter */
419251881Speterapr_size_t
420251881Spetersvn_stringbuf_first_non_whitespace(const svn_stringbuf_t *str);
421251881Speter
422251881Speter/** Strip whitespace from both sides of @a str (modified in place). */
423251881Spetervoid
424251881Spetersvn_stringbuf_strip_whitespace(svn_stringbuf_t *str);
425251881Speter
426251881Speter/** Return position of last occurrence of @a ch in @a str, or return
427251881Speter * @a str->len if no occurrence.
428251881Speter */
429251881Speterapr_size_t
430251881Spetersvn_stringbuf_find_char_backward(const svn_stringbuf_t *str, char ch);
431251881Speter
432251881Speter/** Return @c TRUE iff @a str1 and @a str2 have identical length and data. */
433251881Spetersvn_boolean_t
434251881Spetersvn_string_compare_stringbuf(const svn_string_t *str1,
435251881Speter                             const svn_stringbuf_t *str2);
436251881Speter
437251881Speter/** @} */
438251881Speter
439251881Speter
440251881Speter/**
441251881Speter * @defgroup svn_string_cstrings C string functions
442251881Speter * @{
443251881Speter */
444251881Speter
445299742Sdim/** Divide @a input into substrings, interpreting any char from @a sep
446299742Sdim * as a token separator.
447251881Speter *
448299742Sdim * Return an array of copies of those substrings (plain const char*),
449299742Sdim * allocating both the array and the copies in @a pool.
450299742Sdim *
451251881Speter * None of the elements added to the array contain any of the
452251881Speter * characters in @a sep_chars, and none of the new elements are empty
453251881Speter * (thus, it is possible that the returned array will have length
454251881Speter * zero).
455251881Speter *
456251881Speter * If @a chop_whitespace is TRUE, then remove leading and trailing
457251881Speter * whitespace from the returned strings.
458251881Speter */
459251881Speterapr_array_header_t *
460251881Spetersvn_cstring_split(const char *input,
461251881Speter                  const char *sep_chars,
462251881Speter                  svn_boolean_t chop_whitespace,
463251881Speter                  apr_pool_t *pool);
464251881Speter
465251881Speter/** Like svn_cstring_split(), but append to existing @a array instead of
466251881Speter * creating a new one.  Allocate the copied substrings in @a pool
467251881Speter * (i.e., caller decides whether or not to pass @a array->pool as @a pool).
468251881Speter */
469251881Spetervoid
470251881Spetersvn_cstring_split_append(apr_array_header_t *array,
471251881Speter                         const char *input,
472251881Speter                         const char *sep_chars,
473251881Speter                         svn_boolean_t chop_whitespace,
474251881Speter                         apr_pool_t *pool);
475251881Speter
476251881Speter
477251881Speter/** Return @c TRUE iff @a str matches any of the elements of @a list, a list
478251881Speter * of zero or more glob patterns.
479251881Speter */
480251881Spetersvn_boolean_t
481251881Spetersvn_cstring_match_glob_list(const char *str, const apr_array_header_t *list);
482251881Speter
483251881Speter/** Return @c TRUE iff @a str exactly matches any of the elements of @a list.
484251881Speter *
485251881Speter * @since new in 1.7
486251881Speter */
487251881Spetersvn_boolean_t
488251881Spetersvn_cstring_match_list(const char *str, const apr_array_header_t *list);
489251881Speter
490251881Speter/**
491251881Speter * Get the next token from @a *str interpreting any char from @a sep as a
492251881Speter * token separator.  Separators at the beginning of @a str will be skipped.
493251881Speter * Returns a pointer to the beginning of the first token in @a *str or NULL
494251881Speter * if no token is left.  Modifies @a str such that the next call will return
495251881Speter * the next token.
496251881Speter *
497251881Speter * @note The content of @a *str may be modified by this function.
498251881Speter *
499251881Speter * @since New in 1.8.
500251881Speter */
501251881Speterchar *
502251881Spetersvn_cstring_tokenize(const char *sep, char **str);
503251881Speter
504251881Speter/**
505251881Speter * Return the number of line breaks in @a msg, allowing any kind of newline
506251881Speter * termination (CR, LF, CRLF, or LFCR), even inconsistent.
507251881Speter *
508251881Speter * @since New in 1.2.
509251881Speter */
510251881Speterint
511251881Spetersvn_cstring_count_newlines(const char *msg);
512251881Speter
513251881Speter/**
514251881Speter * Return a cstring which is the concatenation of @a strings (an array
515251881Speter * of char *) each followed by @a separator (that is, @a separator
516251881Speter * will also end the resulting string).  Allocate the result in @a pool.
517251881Speter * If @a strings is empty, then return the empty string.
518251881Speter *
519251881Speter * @since New in 1.2.
520251881Speter */
521251881Speterchar *
522251881Spetersvn_cstring_join(const apr_array_header_t *strings,
523251881Speter                 const char *separator,
524251881Speter                 apr_pool_t *pool);
525251881Speter
526251881Speter/**
527251881Speter * Compare two strings @a atr1 and @a atr2, treating case-equivalent
528251881Speter * unaccented Latin (ASCII subset) letters as equal.
529251881Speter *
530251881Speter * Returns in integer greater than, equal to, or less than 0,
531251881Speter * according to whether @a str1 is considered greater than, equal to,
532251881Speter * or less than @a str2.
533251881Speter *
534251881Speter * @since New in 1.5.
535251881Speter */
536251881Speterint
537251881Spetersvn_cstring_casecmp(const char *str1, const char *str2);
538251881Speter
539251881Speter/**
540251881Speter * Parse the C string @a str into a 64 bit number, and return it in @a *n.
541251881Speter * Assume that the number is represented in base @a base.
542251881Speter * Raise an error if conversion fails (e.g. due to overflow), or if the
543251881Speter * converted number is smaller than @a minval or larger than @a maxval.
544299742Sdim * Leading whitespace in @a str is skipped in a locale-dependent way.
545251881Speter *
546251881Speter * @since New in 1.7.
547251881Speter */
548251881Spetersvn_error_t *
549251881Spetersvn_cstring_strtoi64(apr_int64_t *n, const char *str,
550251881Speter                     apr_int64_t minval, apr_int64_t maxval,
551251881Speter                     int base);
552251881Speter
553251881Speter/**
554251881Speter * Parse the C string @a str into a 64 bit number, and return it in @a *n.
555251881Speter * Assume that the number is represented in base 10.
556251881Speter * Raise an error if conversion fails (e.g. due to overflow).
557299742Sdim * Leading whitespace in @a str is skipped in a locale-dependent way.
558251881Speter *
559251881Speter * @since New in 1.7.
560251881Speter */
561251881Spetersvn_error_t *
562251881Spetersvn_cstring_atoi64(apr_int64_t *n, const char *str);
563251881Speter
564251881Speter/**
565251881Speter * Parse the C string @a str into a 32 bit number, and return it in @a *n.
566251881Speter * Assume that the number is represented in base 10.
567251881Speter * Raise an error if conversion fails (e.g. due to overflow).
568299742Sdim * Leading whitespace in @a str is skipped in a locale-dependent way.
569251881Speter *
570251881Speter * @since New in 1.7.
571251881Speter */
572251881Spetersvn_error_t *
573251881Spetersvn_cstring_atoi(int *n, const char *str);
574251881Speter
575251881Speter/**
576251881Speter * Parse the C string @a str into an unsigned 64 bit number, and return
577251881Speter * it in @a *n. Assume that the number is represented in base @a base.
578251881Speter * Raise an error if conversion fails (e.g. due to overflow), or if the
579251881Speter * converted number is smaller than @a minval or larger than @a maxval.
580299742Sdim * Leading whitespace in @a str is skipped in a locale-dependent way.
581251881Speter *
582251881Speter * @since New in 1.7.
583251881Speter */
584251881Spetersvn_error_t *
585251881Spetersvn_cstring_strtoui64(apr_uint64_t *n, const char *str,
586251881Speter                      apr_uint64_t minval, apr_uint64_t maxval,
587251881Speter                      int base);
588251881Speter
589251881Speter/**
590251881Speter * Parse the C string @a str into an unsigned 64 bit number, and return
591251881Speter * it in @a *n. Assume that the number is represented in base 10.
592251881Speter * Raise an error if conversion fails (e.g. due to overflow).
593299742Sdim * Leading whitespace in @a str is skipped in a locale-dependent way.
594251881Speter *
595251881Speter * @since New in 1.7.
596251881Speter */
597251881Spetersvn_error_t *
598251881Spetersvn_cstring_atoui64(apr_uint64_t *n, const char *str);
599251881Speter
600251881Speter/**
601251881Speter * Parse the C string @a str into an unsigned 32 bit number, and return
602251881Speter * it in @a *n. Assume that the number is represented in base 10.
603251881Speter * Raise an error if conversion fails (e.g. due to overflow).
604299742Sdim * Leading whitespace in @a str is skipped in a locale-dependent way.
605251881Speter *
606251881Speter * @since New in 1.7.
607251881Speter */
608251881Spetersvn_error_t *
609251881Spetersvn_cstring_atoui(unsigned int *n, const char *str);
610251881Speter
611299742Sdim/**
612299742Sdim * Skip the common prefix @a prefix from the C string @a str, and return
613299742Sdim * a pointer to the next character after the prefix.
614299742Sdim * Return @c NULL if @a str does not start with @a prefix.
615299742Sdim *
616299742Sdim * @since New in 1.9.
617299742Sdim */
618299742Sdimconst char *
619299742Sdimsvn_cstring_skip_prefix(const char *str, const char *prefix);
620299742Sdim
621251881Speter/** @} */
622251881Speter
623251881Speter/** @} */
624251881Speter
625251881Speter
626251881Speter#ifdef __cplusplus
627251881Speter}
628251881Speter#endif /* __cplusplus */
629251881Speter
630251881Speter#endif  /* SVN_STRING_H */
631