981 cxstring string, |
981 cxstring string, |
982 cxstring suffix |
982 cxstring suffix |
983 ); |
983 ); |
984 |
984 |
985 /** |
985 /** |
986 * Replaces a pattern in a string with another string. |
986 * Replaces a string with another string. |
987 * |
987 * |
988 * The pattern is taken literally and is no regular expression. |
|
989 * Replaces at most @p replmax occurrences. |
988 * Replaces at most @p replmax occurrences. |
990 * |
989 * |
991 * The returned string will be allocated by @p allocator and is guaranteed |
990 * The returned string will be allocated by @p allocator and is guaranteed |
992 * to be zero-terminated. |
991 * to be zero-terminated. |
993 * |
992 * |
994 * If allocation fails, or the input string is empty, |
993 * If allocation fails, or the input string is empty, |
995 * the returned string will be empty. |
994 * the returned string will be empty. |
996 * |
995 * |
997 * @param allocator the allocator to use |
996 * @param allocator the allocator to use |
998 * @param str the string where replacements should be applied |
997 * @param str the string where replacements should be applied |
999 * @param pattern the pattern to search for |
998 * @param search the string to search for |
1000 * @param replacement the replacement string |
999 * @param replacement the replacement string |
1001 * @param replmax maximum number of replacements |
1000 * @param replmax maximum number of replacements |
1002 * @return the resulting string after applying the replacements |
1001 * @return the resulting string after applying the replacements |
1003 */ |
1002 */ |
1004 cx_attr_nodiscard |
1003 cx_attr_nodiscard |
1005 cx_attr_nonnull |
1004 cx_attr_nonnull |
1006 cx_attr_export |
1005 cx_attr_export |
1007 cxmutstr cx_strreplacen_a( |
1006 cxmutstr cx_strreplacen_a( |
1008 const CxAllocator *allocator, |
1007 const CxAllocator *allocator, |
1009 cxstring str, |
1008 cxstring str, |
1010 cxstring pattern, |
1009 cxstring search, |
1011 cxstring replacement, |
1010 cxstring replacement, |
1012 size_t replmax |
1011 size_t replmax |
1013 ); |
1012 ); |
1014 |
1013 |
1015 /** |
1014 /** |
1016 * Replaces a pattern in a string with another string. |
1015 * Replaces a string with another string. |
1017 * |
1016 * |
1018 * The pattern is taken literally and is no regular expression. |
|
1019 * Replaces at most @p replmax occurrences. |
1017 * Replaces at most @p replmax occurrences. |
1020 * |
1018 * |
1021 * The returned string will be allocated by @c malloc() and is guaranteed |
1019 * The returned string will be allocated by @c malloc() and is guaranteed |
1022 * to be zero-terminated. |
1020 * to be zero-terminated. |
1023 * |
1021 * |
1024 * If allocation fails, or the input string is empty, |
1022 * If allocation fails, or the input string is empty, |
1025 * the returned string will be empty. |
1023 * the returned string will be empty. |
1026 * |
1024 * |
1027 * @param str (@c cxstring) the string where replacements should be applied |
1025 * @param str (@c cxstring) the string where replacements should be applied |
1028 * @param pattern (@c cxstring) the pattern to search for |
1026 * @param search (@c cxstring) the string to search for |
1029 * @param replacement (@c cxstring) the replacement string |
1027 * @param replacement (@c cxstring) the replacement string |
1030 * @param replmax (@c size_t) maximum number of replacements |
1028 * @param replmax (@c size_t) maximum number of replacements |
1031 * @return (@c cxmutstr) the resulting string after applying the replacements |
1029 * @return (@c cxmutstr) the resulting string after applying the replacements |
1032 */ |
1030 */ |
1033 #define cx_strreplacen(str, pattern, replacement, replmax) \ |
1031 #define cx_strreplacen(str, search, replacement, replmax) \ |
1034 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax) |
1032 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax) |
1035 |
1033 |
1036 /** |
1034 /** |
1037 * Replaces a pattern in a string with another string. |
1035 * Replaces a string with another string. |
1038 * |
|
1039 * The pattern is taken literally and is no regular expression. |
|
1040 * |
1036 * |
1041 * The returned string will be allocated by @p allocator and is guaranteed |
1037 * The returned string will be allocated by @p allocator and is guaranteed |
1042 * to be zero-terminated. |
1038 * to be zero-terminated. |
1043 * |
1039 * |
1044 * If allocation fails, or the input string is empty, |
1040 * If allocation fails, or the input string is empty, |
1045 * the returned string will be empty. |
1041 * the returned string will be empty. |
1046 * |
1042 * |
1047 * @param allocator (@c CxAllocator*) the allocator to use |
1043 * @param allocator (@c CxAllocator*) the allocator to use |
1048 * @param str (@c cxstring) the string where replacements should be applied |
1044 * @param str (@c cxstring) the string where replacements should be applied |
1049 * @param pattern (@c cxstring) the pattern to search for |
1045 * @param search (@c cxstring) the string to search for |
1050 * @param replacement (@c cxstring) the replacement string |
1046 * @param replacement (@c cxstring) the replacement string |
1051 * @return (@c cxmutstr) the resulting string after applying the replacements |
1047 * @return (@c cxmutstr) the resulting string after applying the replacements |
1052 */ |
1048 */ |
1053 #define cx_strreplace_a(allocator, str, pattern, replacement) \ |
1049 #define cx_strreplace_a(allocator, str, search, replacement) \ |
1054 cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX) |
1050 cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX) |
1055 |
1051 |
1056 /** |
1052 /** |
1057 * Replaces a pattern in a string with another string. |
1053 * Replaces a string with another string. |
1058 * |
|
1059 * The pattern is taken literally and is no regular expression. |
|
1060 * Replaces at most @p replmax occurrences. |
|
1061 * |
1054 * |
1062 * The returned string will be allocated by @c malloc() and is guaranteed |
1055 * The returned string will be allocated by @c malloc() and is guaranteed |
1063 * to be zero-terminated. |
1056 * to be zero-terminated. |
1064 * |
1057 * |
1065 * If allocation fails, or the input string is empty, |
1058 * If allocation fails, or the input string is empty, |
1066 * the returned string will be empty. |
1059 * the returned string will be empty. |
1067 * |
1060 * |
1068 * @param str (@c cxstring) the string where replacements should be applied |
1061 * @param str (@c cxstring) the string where replacements should be applied |
1069 * @param pattern (@c cxstring) the pattern to search for |
1062 * @param search (@c cxstring) the string to search for |
1070 * @param replacement (@c cxstring) the replacement string |
1063 * @param replacement (@c cxstring) the replacement string |
1071 * @return (@c cxmutstr) the resulting string after applying the replacements |
1064 * @return (@c cxmutstr) the resulting string after applying the replacements |
1072 */ |
1065 */ |
1073 #define cx_strreplace(str, pattern, replacement) \ |
1066 #define cx_strreplace(str, search, replacement) \ |
1074 cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX) |
1067 cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX) |
1075 |
1068 |
1076 /** |
1069 /** |
1077 * Creates a string tokenization context. |
1070 * Creates a string tokenization context. |
1078 * |
1071 * |
1079 * @param str the string to tokenize |
1072 * @param str the string to tokenize |