170 * @param cstring the string to wrap, must be zero-terminated |
170 * @param cstring the string to wrap, must be zero-terminated |
171 * @return the wrapped string |
171 * @return the wrapped string |
172 * |
172 * |
173 * @see cx_mutstrn() |
173 * @see cx_mutstrn() |
174 */ |
174 */ |
175 __attribute__((__warn_unused_result__, __nonnull__)) |
175 cx_attr_nonnull |
|
176 cx_attr_nodiscard |
|
177 cx_attr_cstr_arg(1) |
176 cxmutstr cx_mutstr(char *cstring); |
178 cxmutstr cx_mutstr(char *cstring); |
177 |
179 |
178 /** |
180 /** |
179 * Wraps a string that does not need to be zero-terminated. |
181 * Wraps a string that does not need to be zero-terminated. |
180 * |
182 * |
210 * @param cstring the string to wrap, must be zero-terminated |
213 * @param cstring the string to wrap, must be zero-terminated |
211 * @return the wrapped string |
214 * @return the wrapped string |
212 * |
215 * |
213 * @see cx_strn() |
216 * @see cx_strn() |
214 */ |
217 */ |
215 __attribute__((__warn_unused_result__, __nonnull__)) |
218 cx_attr_nonnull |
|
219 cx_attr_nodiscard |
|
220 cx_attr_cstr_arg(1) |
216 cxstring cx_str(const char *cstring); |
221 cxstring cx_str(const char *cstring); |
217 |
222 |
218 |
223 |
219 /** |
224 /** |
220 * Wraps a string that does not need to be zero-terminated. |
225 * Wraps a string that does not need to be zero-terminated. |
246 * point to the same location, though! |
252 * point to the same location, though! |
247 * |
253 * |
248 * @param str the mutable string to cast |
254 * @param str the mutable string to cast |
249 * @return an immutable copy of the string pointer |
255 * @return an immutable copy of the string pointer |
250 */ |
256 */ |
251 __attribute__((__warn_unused_result__)) |
257 cx_attr_nodiscard |
252 cxstring cx_strcast(cxmutstr str); |
258 cxstring cx_strcast(cxmutstr str); |
253 |
259 |
254 /** |
260 /** |
255 * Passes the pointer in this string to \c free(). |
261 * Passes the pointer in this string to \c free(). |
256 * |
262 * |
260 * you ever have a <code>const char*</code> you are really supposed to free. |
266 * you ever have a <code>const char*</code> you are really supposed to free. |
261 * If you encounter such situation, you should double-check your code. |
267 * If you encounter such situation, you should double-check your code. |
262 * |
268 * |
263 * @param str the string to free |
269 * @param str the string to free |
264 */ |
270 */ |
265 __attribute__((__nonnull__)) |
|
266 void cx_strfree(cxmutstr *str); |
271 void cx_strfree(cxmutstr *str); |
267 |
272 |
268 /** |
273 /** |
269 * Passes the pointer in this string to the allocators free function. |
274 * Passes the pointer in this string to the allocators free function. |
270 * |
275 * |
275 * If you encounter such situation, you should double-check your code. |
280 * If you encounter such situation, you should double-check your code. |
276 * |
281 * |
277 * @param alloc the allocator |
282 * @param alloc the allocator |
278 * @param str the string to free |
283 * @param str the string to free |
279 */ |
284 */ |
280 __attribute__((__nonnull__)) |
285 cx_attr_nonnull_arg(1) |
281 void cx_strfree_a( |
286 void cx_strfree_a( |
282 const CxAllocator *alloc, |
287 const CxAllocator *alloc, |
283 cxmutstr *str |
288 cxmutstr *str |
284 ); |
289 ); |
285 |
290 |
315 * @param str the string the other strings shall be concatenated to |
320 * @param str the string the other strings shall be concatenated to |
316 * @param count the number of the other following strings to concatenate |
321 * @param count the number of the other following strings to concatenate |
317 * @param ... all other strings |
322 * @param ... all other strings |
318 * @return the concatenated string |
323 * @return the concatenated string |
319 */ |
324 */ |
320 __attribute__((__warn_unused_result__, __nonnull__)) |
325 cx_attr_nodiscard |
|
326 cx_attr_nonnull |
321 cxmutstr cx_strcat_ma( |
327 cxmutstr cx_strcat_ma( |
322 const CxAllocator *alloc, |
328 const CxAllocator *alloc, |
323 cxmutstr str, |
329 cxmutstr str, |
324 size_t count, |
330 size_t count, |
325 ... |
331 ... |
598 * @param delim the delimiter |
604 * @param delim the delimiter |
599 * @param limit the maximum number of split items |
605 * @param limit the maximum number of split items |
600 * @param output a pre-allocated array of at least \p limit length |
606 * @param output a pre-allocated array of at least \p limit length |
601 * @return the actual number of split items |
607 * @return the actual number of split items |
602 */ |
608 */ |
603 __attribute__((__warn_unused_result__, __nonnull__)) |
609 cx_attr_nodiscard |
|
610 cx_attr_nonnull |
|
611 cx_attr_access_w(4, 3) |
604 size_t cx_strsplit( |
612 size_t cx_strsplit( |
605 cxstring string, |
613 cxstring string, |
606 cxstring delim, |
614 cxstring delim, |
607 size_t limit, |
615 size_t limit, |
608 cxstring *output |
616 cxstring *output |
625 * @param limit the maximum number of split items |
633 * @param limit the maximum number of split items |
626 * @param output a pointer where the address of the allocated array shall be |
634 * @param output a pointer where the address of the allocated array shall be |
627 * written to |
635 * written to |
628 * @return the actual number of split items |
636 * @return the actual number of split items |
629 */ |
637 */ |
630 __attribute__((__warn_unused_result__, __nonnull__)) |
638 cx_attr_nodiscard |
|
639 cx_attr_nonnull |
|
640 cx_attr_access_w(5) |
631 size_t cx_strsplit_a( |
641 size_t cx_strsplit_a( |
632 const CxAllocator *allocator, |
642 const CxAllocator *allocator, |
633 cxstring string, |
643 cxstring string, |
634 cxstring delim, |
644 cxstring delim, |
635 size_t limit, |
645 size_t limit, |
647 * @param delim the delimiter |
657 * @param delim the delimiter |
648 * @param limit the maximum number of split items |
658 * @param limit the maximum number of split items |
649 * @param output a pre-allocated array of at least \p limit length |
659 * @param output a pre-allocated array of at least \p limit length |
650 * @return the actual number of split items |
660 * @return the actual number of split items |
651 */ |
661 */ |
652 __attribute__((__warn_unused_result__, __nonnull__)) |
662 cx_attr_nodiscard |
|
663 cx_attr_nonnull |
|
664 cx_attr_access_w(4, 3) |
653 size_t cx_strsplit_m( |
665 size_t cx_strsplit_m( |
654 cxmutstr string, |
666 cxmutstr string, |
655 cxstring delim, |
667 cxstring delim, |
656 size_t limit, |
668 size_t limit, |
657 cxmutstr *output |
669 cxmutstr *output |
674 * @param limit the maximum number of split items |
686 * @param limit the maximum number of split items |
675 * @param output a pointer where the address of the allocated array shall be |
687 * @param output a pointer where the address of the allocated array shall be |
676 * written to |
688 * written to |
677 * @return the actual number of split items |
689 * @return the actual number of split items |
678 */ |
690 */ |
679 __attribute__((__warn_unused_result__, __nonnull__)) |
691 cx_attr_nodiscard |
|
692 cx_attr_nonnull |
|
693 cx_attr_access_w(5) |
680 size_t cx_strsplit_ma( |
694 size_t cx_strsplit_ma( |
681 const CxAllocator *allocator, |
695 const CxAllocator *allocator, |
682 cxmutstr string, |
696 cxmutstr string, |
683 cxstring delim, |
697 cxstring delim, |
684 size_t limit, |
698 size_t limit, |
691 * @param s1 the first string |
705 * @param s1 the first string |
692 * @param s2 the second string |
706 * @param s2 the second string |
693 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger |
707 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger |
694 * than \p s2, zero if both strings equal |
708 * than \p s2, zero if both strings equal |
695 */ |
709 */ |
696 __attribute__((__warn_unused_result__)) |
710 cx_attr_nodiscard |
697 int cx_strcmp( |
711 int cx_strcmp( |
698 cxstring s1, |
712 cxstring s1, |
699 cxstring s2 |
713 cxstring s2 |
700 ); |
714 ); |
701 |
715 |
705 * @param s1 the first string |
719 * @param s1 the first string |
706 * @param s2 the second string |
720 * @param s2 the second string |
707 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger |
721 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger |
708 * than \p s2, zero if both strings equal ignoring case |
722 * than \p s2, zero if both strings equal ignoring case |
709 */ |
723 */ |
710 __attribute__((__warn_unused_result__)) |
724 cx_attr_nodiscard |
711 int cx_strcasecmp( |
725 int cx_strcasecmp( |
712 cxstring s1, |
726 cxstring s1, |
713 cxstring s2 |
727 cxstring s2 |
714 ); |
728 ); |
715 |
729 |
721 * @param s1 the first string |
735 * @param s1 the first string |
722 * @param s2 the second string |
736 * @param s2 the second string |
723 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger |
737 * @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 |
738 * than \p s2, zero if both strings equal |
725 */ |
739 */ |
726 __attribute__((__warn_unused_result__, __nonnull__)) |
740 cx_attr_nodiscard |
|
741 cx_attr_nonnull |
727 int cx_strcmp_p( |
742 int cx_strcmp_p( |
728 const void *s1, |
743 const void *s1, |
729 const void *s2 |
744 const void *s2 |
730 ); |
745 ); |
731 |
746 |
737 * @param s1 the first string |
752 * @param s1 the first string |
738 * @param s2 the second string |
753 * @param s2 the second string |
739 * @return negative if \p s1 is smaller than \p s2, positive if \p s1 is larger |
754 * @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 |
755 * than \p s2, zero if both strings equal ignoring case |
741 */ |
756 */ |
742 __attribute__((__warn_unused_result__, __nonnull__)) |
757 cx_attr_nodiscard |
|
758 cx_attr_nonnull |
743 int cx_strcasecmp_p( |
759 int cx_strcasecmp_p( |
744 const void *s1, |
760 const void *s1, |
745 const void *s2 |
761 const void *s2 |
746 ); |
762 ); |
747 |
763 |
756 * @param allocator the allocator to use |
772 * @param allocator the allocator to use |
757 * @param string the string to duplicate |
773 * @param string the string to duplicate |
758 * @return a duplicate of the string |
774 * @return a duplicate of the string |
759 * @see cx_strdup() |
775 * @see cx_strdup() |
760 */ |
776 */ |
761 __attribute__((__warn_unused_result__, __nonnull__)) |
777 cx_attr_nodiscard |
|
778 cx_attr_nonnull |
762 cxmutstr cx_strdup_a( |
779 cxmutstr cx_strdup_a( |
763 const CxAllocator *allocator, |
780 const CxAllocator *allocator, |
764 cxstring string |
781 cxstring string |
765 ); |
782 ); |
766 |
783 |
814 * must \em not free the returned memory. |
831 * must \em not free the returned memory. |
815 * |
832 * |
816 * @param string the string that shall be trimmed |
833 * @param string the string that shall be trimmed |
817 * @return the trimmed string |
834 * @return the trimmed string |
818 */ |
835 */ |
819 __attribute__((__warn_unused_result__)) |
836 cx_attr_nodiscard |
820 cxstring cx_strtrim(cxstring string); |
837 cxstring cx_strtrim(cxstring string); |
821 |
838 |
822 /** |
839 /** |
823 * Omits leading and trailing spaces. |
840 * Omits leading and trailing spaces. |
824 * |
841 * |
826 * must \em not free the returned memory. |
843 * must \em not free the returned memory. |
827 * |
844 * |
828 * @param string the string that shall be trimmed |
845 * @param string the string that shall be trimmed |
829 * @return the trimmed string |
846 * @return the trimmed string |
830 */ |
847 */ |
831 __attribute__((__warn_unused_result__)) |
848 cx_attr_nodiscard |
832 cxmutstr cx_strtrim_m(cxmutstr string); |
849 cxmutstr cx_strtrim_m(cxmutstr string); |
833 |
850 |
834 /** |
851 /** |
835 * Checks, if a string has a specific prefix. |
852 * Checks, if a string has a specific prefix. |
836 * |
853 * |
837 * @param string the string to check |
854 * @param string the string to check |
838 * @param prefix the prefix the string should have |
855 * @param prefix the prefix the string should have |
839 * @return \c true, if and only if the string has the specified prefix, |
856 * @return \c true, if and only if the string has the specified prefix, |
840 * \c false otherwise |
857 * \c false otherwise |
841 */ |
858 */ |
842 __attribute__((__warn_unused_result__)) |
859 cx_attr_nodiscard |
843 bool cx_strprefix( |
860 bool cx_strprefix( |
844 cxstring string, |
861 cxstring string, |
845 cxstring prefix |
862 cxstring prefix |
846 ); |
863 ); |
847 |
864 |
865 * @param string the string to check |
882 * @param string the string to check |
866 * @param prefix the prefix the string should have |
883 * @param prefix the prefix the string should have |
867 * @return \c true, if and only if the string has the specified prefix, |
884 * @return \c true, if and only if the string has the specified prefix, |
868 * \c false otherwise |
885 * \c false otherwise |
869 */ |
886 */ |
870 __attribute__((__warn_unused_result__)) |
887 cx_attr_nodiscard |
871 bool cx_strcaseprefix( |
888 bool cx_strcaseprefix( |
872 cxstring string, |
889 cxstring string, |
873 cxstring prefix |
890 cxstring prefix |
874 ); |
891 ); |
875 |
892 |
879 * @param string the string to check |
896 * @param string the string to check |
880 * @param suffix the suffix the string should have |
897 * @param suffix the suffix the string should have |
881 * @return \c true, if and only if the string has the specified suffix, |
898 * @return \c true, if and only if the string has the specified suffix, |
882 * \c false otherwise |
899 * \c false otherwise |
883 */ |
900 */ |
884 __attribute__((__warn_unused_result__)) |
901 cx_attr_nodiscard |
885 bool cx_strcasesuffix( |
902 bool cx_strcasesuffix( |
886 cxstring string, |
903 cxstring string, |
887 cxstring suffix |
904 cxstring suffix |
888 ); |
905 ); |
889 |
906 |
924 * @param pattern the pattern to search for |
941 * @param pattern the pattern to search for |
925 * @param replacement the replacement string |
942 * @param replacement the replacement string |
926 * @param replmax maximum number of replacements |
943 * @param replmax maximum number of replacements |
927 * @return the resulting string after applying the replacements |
944 * @return the resulting string after applying the replacements |
928 */ |
945 */ |
929 __attribute__((__warn_unused_result__, __nonnull__)) |
946 cx_attr_nodiscard |
|
947 cx_attr_nonnull |
930 cxmutstr cx_strreplacen_a( |
948 cxmutstr cx_strreplacen_a( |
931 const CxAllocator *allocator, |
949 const CxAllocator *allocator, |
932 cxstring str, |
950 cxstring str, |
933 cxstring pattern, |
951 cxstring pattern, |
934 cxstring replacement, |
952 cxstring replacement, |
1002 * @param str the string to tokenize |
1020 * @param str the string to tokenize |
1003 * @param delim the delimiter (must not be empty) |
1021 * @param delim the delimiter (must not be empty) |
1004 * @param limit the maximum number of tokens that shall be returned |
1022 * @param limit the maximum number of tokens that shall be returned |
1005 * @return a new string tokenization context |
1023 * @return a new string tokenization context |
1006 */ |
1024 */ |
1007 __attribute__((__warn_unused_result__)) |
1025 cx_attr_nodiscard |
1008 CxStrtokCtx cx_strtok( |
1026 CxStrtokCtx cx_strtok( |
1009 cxstring str, |
1027 cxstring str, |
1010 cxstring delim, |
1028 cxstring delim, |
1011 size_t limit |
1029 size_t limit |
1012 ); |
1030 ); |
1017 * @param str the string to tokenize |
1035 * @param str the string to tokenize |
1018 * @param delim the delimiter (must not be empty) |
1036 * @param delim the delimiter (must not be empty) |
1019 * @param limit the maximum number of tokens that shall be returned |
1037 * @param limit the maximum number of tokens that shall be returned |
1020 * @return a new string tokenization context |
1038 * @return a new string tokenization context |
1021 */ |
1039 */ |
1022 __attribute__((__warn_unused_result__)) |
1040 cx_attr_nodiscard |
1023 CxStrtokCtx cx_strtok_m( |
1041 CxStrtokCtx cx_strtok_m( |
1024 cxmutstr str, |
1042 cxmutstr str, |
1025 cxstring delim, |
1043 cxstring delim, |
1026 size_t limit |
1044 size_t limit |
1027 ); |
1045 ); |
1034 * @param ctx the tokenization context |
1052 * @param ctx the tokenization context |
1035 * @param token a pointer to memory where the next token shall be stored |
1053 * @param token a pointer to memory where the next token shall be stored |
1036 * @return true if successful, false if the limit or the end of the string |
1054 * @return true if successful, false if the limit or the end of the string |
1037 * has been reached |
1055 * has been reached |
1038 */ |
1056 */ |
1039 __attribute__((__warn_unused_result__, __nonnull__)) |
1057 cx_attr_nonnull |
|
1058 cx_attr_nodiscard |
|
1059 cx_attr_access_w(2) |
1040 bool cx_strtok_next( |
1060 bool cx_strtok_next( |
1041 CxStrtokCtx *ctx, |
1061 CxStrtokCtx *ctx, |
1042 cxstring *token |
1062 cxstring *token |
1043 ); |
1063 ); |
1044 |
1064 |
1052 * @param ctx the tokenization context |
1072 * @param ctx the tokenization context |
1053 * @param token a pointer to memory where the next token shall be stored |
1073 * @param token a pointer to memory where the next token shall be stored |
1054 * @return true if successful, false if the limit or the end of the string |
1074 * @return true if successful, false if the limit or the end of the string |
1055 * has been reached |
1075 * has been reached |
1056 */ |
1076 */ |
1057 __attribute__((__warn_unused_result__, __nonnull__)) |
1077 cx_attr_nonnull |
|
1078 cx_attr_nodiscard |
|
1079 cx_attr_access_w(2) |
1058 bool cx_strtok_next_m( |
1080 bool cx_strtok_next_m( |
1059 CxStrtokCtx *ctx, |
1081 CxStrtokCtx *ctx, |
1060 cxmutstr *token |
1082 cxmutstr *token |
1061 ); |
1083 ); |
1062 |
1084 |
1065 * |
1087 * |
1066 * @param ctx the tokenization context |
1088 * @param ctx the tokenization context |
1067 * @param delim array of more delimiters |
1089 * @param delim array of more delimiters |
1068 * @param count number of elements in the array |
1090 * @param count number of elements in the array |
1069 */ |
1091 */ |
1070 __attribute__((__nonnull__)) |
1092 cx_attr_nonnull |
|
1093 cx_attr_access_r(2, 3) |
1071 void cx_strtok_delim( |
1094 void cx_strtok_delim( |
1072 CxStrtokCtx *ctx, |
1095 CxStrtokCtx *ctx, |
1073 const cxstring *delim, |
1096 const cxstring *delim, |
1074 size_t count |
1097 size_t count |
1075 ); |
1098 ); |