src/cx/string.h

changeset 890
54565fd74e74
parent 806
e06249e09f99
equal deleted inserted replaced
889:f549fd9fbd8f 890:54565fd74e74
70 /** 70 /**
71 * A pointer to the immutable string. 71 * A pointer to the immutable string.
72 * \note The string is not necessarily \c NULL terminated. 72 * \note The string is not necessarily \c NULL terminated.
73 * Always use the length. 73 * Always use the length.
74 */ 74 */
75 char const *ptr; 75 const char *ptr;
76 /** The length of the string */ 76 /** The length of the string */
77 size_t length; 77 size_t length;
78 }; 78 };
79 79
80 /** 80 /**
95 */ 95 */
96 cxstring delim; 96 cxstring delim;
97 /** 97 /**
98 * Optional array of more delimiters. 98 * Optional array of more delimiters.
99 */ 99 */
100 cxstring const *delim_more; 100 const cxstring *delim_more;
101 /** 101 /**
102 * Length of the array containing more delimiters. 102 * Length of the array containing more delimiters.
103 */ 103 */
104 size_t delim_more_count; 104 size_t delim_more_count;
105 /** 105 /**
211 * @return the wrapped string 211 * @return the wrapped string
212 * 212 *
213 * @see cx_strn() 213 * @see cx_strn()
214 */ 214 */
215 __attribute__((__warn_unused_result__, __nonnull__)) 215 __attribute__((__warn_unused_result__, __nonnull__))
216 cxstring cx_str(char const *cstring); 216 cxstring cx_str(const char *cstring);
217 217
218 218
219 /** 219 /**
220 * Wraps a string that does not need to be zero-terminated. 220 * Wraps a string that does not need to be zero-terminated.
221 * 221 *
232 * 232 *
233 * @see cx_str() 233 * @see cx_str()
234 */ 234 */
235 __attribute__((__warn_unused_result__)) 235 __attribute__((__warn_unused_result__))
236 cxstring cx_strn( 236 cxstring cx_strn(
237 char const *cstring, 237 const char *cstring,
238 size_t length 238 size_t length
239 ); 239 );
240 240
241 /** 241 /**
242 * Casts a mutable string to an immutable string. 242 * Casts a mutable string to an immutable string.
255 * Passes the pointer in this string to \c free(). 255 * Passes the pointer in this string to \c free().
256 * 256 *
257 * The pointer in the struct is set to \c NULL and the length is set to zero. 257 * The pointer in the struct is set to \c NULL and the length is set to zero.
258 * 258 *
259 * \note There is no implementation for cxstring, because it is unlikely that 259 * \note There is no implementation for cxstring, because it is unlikely that
260 * you ever have a \c char \c const* you are really supposed to free. If you 260 * you ever have a <code>const char*</code> you are really supposed to free.
261 * encounter such situation, you should double-check your code. 261 * If you encounter such situation, you should double-check your code.
262 * 262 *
263 * @param str the string to free 263 * @param str the string to free
264 */ 264 */
265 __attribute__((__nonnull__)) 265 __attribute__((__nonnull__))
266 void cx_strfree(cxmutstr *str); 266 void cx_strfree(cxmutstr *str);
269 * Passes the pointer in this string to the allocators free function. 269 * Passes the pointer in this string to the allocators free function.
270 * 270 *
271 * The pointer in the struct is set to \c NULL and the length is set to zero. 271 * The pointer in the struct is set to \c NULL and the length is set to zero.
272 * 272 *
273 * \note There is no implementation for cxstring, because it is unlikely that 273 * \note There is no implementation for cxstring, because it is unlikely that
274 * you ever have a \c char \c const* you are really supposed to free. If you 274 * you ever have a <code>const char*</code> you are really supposed to free.
275 * encounter such situation, you should double-check your code. 275 * If you encounter such situation, you should double-check your code.
276 * 276 *
277 * @param alloc the allocator 277 * @param alloc the allocator
278 * @param str the string to free 278 * @param str the string to free
279 */ 279 */
280 __attribute__((__nonnull__)) 280 __attribute__((__nonnull__))
281 void cx_strfree_a( 281 void cx_strfree_a(
282 CxAllocator const *alloc, 282 const CxAllocator *alloc,
283 cxmutstr *str 283 cxmutstr *str
284 ); 284 );
285 285
286 /** 286 /**
287 * Returns the accumulated length of all specified strings. 287 * Returns the accumulated length of all specified strings.
317 * @param ... all other strings 317 * @param ... all other strings
318 * @return the concatenated string 318 * @return the concatenated string
319 */ 319 */
320 __attribute__((__warn_unused_result__, __nonnull__)) 320 __attribute__((__warn_unused_result__, __nonnull__))
321 cxmutstr cx_strcat_ma( 321 cxmutstr cx_strcat_ma(
322 CxAllocator const *alloc, 322 const CxAllocator *alloc,
323 cxmutstr str, 323 cxmutstr str,
324 size_t count, 324 size_t count,
325 ... 325 ...
326 ); 326 );
327 327
627 * written to 627 * written to
628 * @return the actual number of split items 628 * @return the actual number of split items
629 */ 629 */
630 __attribute__((__warn_unused_result__, __nonnull__)) 630 __attribute__((__warn_unused_result__, __nonnull__))
631 size_t cx_strsplit_a( 631 size_t cx_strsplit_a(
632 CxAllocator const *allocator, 632 const CxAllocator *allocator,
633 cxstring string, 633 cxstring string,
634 cxstring delim, 634 cxstring delim,
635 size_t limit, 635 size_t limit,
636 cxstring **output 636 cxstring **output
637 ); 637 );
676 * written to 676 * written to
677 * @return the actual number of split items 677 * @return the actual number of split items
678 */ 678 */
679 __attribute__((__warn_unused_result__, __nonnull__)) 679 __attribute__((__warn_unused_result__, __nonnull__))
680 size_t cx_strsplit_ma( 680 size_t cx_strsplit_ma(
681 CxAllocator const *allocator, 681 const CxAllocator *allocator,
682 cxmutstr string, 682 cxmutstr string,
683 cxstring delim, 683 cxstring delim,
684 size_t limit, 684 size_t limit,
685 cxmutstr **output 685 cxmutstr **output
686 ); 686 );
723 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 723 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger
724 * than \p s2, zero if both strings equal 724 * than \p s2, zero if both strings equal
725 */ 725 */
726 __attribute__((__warn_unused_result__, __nonnull__)) 726 __attribute__((__warn_unused_result__, __nonnull__))
727 int cx_strcmp_p( 727 int cx_strcmp_p(
728 void const *s1, 728 const void *s1,
729 void const *s2 729 const void *s2
730 ); 730 );
731 731
732 /** 732 /**
733 * Compares two strings ignoring case. 733 * Compares two strings ignoring case.
734 * 734 *
739 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger 739 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger
740 * than \p s2, zero if both strings equal ignoring case 740 * than \p s2, zero if both strings equal ignoring case
741 */ 741 */
742 __attribute__((__warn_unused_result__, __nonnull__)) 742 __attribute__((__warn_unused_result__, __nonnull__))
743 int cx_strcasecmp_p( 743 int cx_strcasecmp_p(
744 void const *s1, 744 const void *s1,
745 void const *s2 745 const void *s2
746 ); 746 );
747 747
748 748
749 /** 749 /**
750 * Creates a duplicate of the specified string. 750 * Creates a duplicate of the specified string.
758 * @return a duplicate of the string 758 * @return a duplicate of the string
759 * @see cx_strdup() 759 * @see cx_strdup()
760 */ 760 */
761 __attribute__((__warn_unused_result__, __nonnull__)) 761 __attribute__((__warn_unused_result__, __nonnull__))
762 cxmutstr cx_strdup_a( 762 cxmutstr cx_strdup_a(
763 CxAllocator const *allocator, 763 const CxAllocator *allocator,
764 cxstring string 764 cxstring string
765 ); 765 );
766 766
767 /** 767 /**
768 * Creates a duplicate of the specified string. 768 * Creates a duplicate of the specified string.
926 * @param replmax maximum number of replacements 926 * @param replmax maximum number of replacements
927 * @return the resulting string after applying the replacements 927 * @return the resulting string after applying the replacements
928 */ 928 */
929 __attribute__((__warn_unused_result__, __nonnull__)) 929 __attribute__((__warn_unused_result__, __nonnull__))
930 cxmutstr cx_strreplacen_a( 930 cxmutstr cx_strreplacen_a(
931 CxAllocator const *allocator, 931 const CxAllocator *allocator,
932 cxstring str, 932 cxstring str,
933 cxstring pattern, 933 cxstring pattern,
934 cxstring replacement, 934 cxstring replacement,
935 size_t replmax 935 size_t replmax
936 ); 936 );
1068 * @param count number of elements in the array 1068 * @param count number of elements in the array
1069 */ 1069 */
1070 __attribute__((__nonnull__)) 1070 __attribute__((__nonnull__))
1071 void cx_strtok_delim( 1071 void cx_strtok_delim(
1072 CxStrtokCtx *ctx, 1072 CxStrtokCtx *ctx,
1073 cxstring const *delim, 1073 const cxstring *delim,
1074 size_t count 1074 size_t count
1075 ); 1075 );
1076 1076
1077 1077
1078 #ifdef __cplusplus 1078 #ifdef __cplusplus

mercurial