680 } |
680 } |
681 |
681 |
682 sstr_t scstrreplacen_a(UcxAllocator *allocator, scstr_t str, |
682 sstr_t scstrreplacen_a(UcxAllocator *allocator, scstr_t str, |
683 scstr_t pattern, scstr_t replacement, size_t replmax) { |
683 scstr_t pattern, scstr_t replacement, size_t replmax) { |
684 |
684 |
685 if (pattern.length == 0 || pattern.length > str.length) |
685 if (pattern.length == 0 || pattern.length > str.length || replmax == 0) |
686 return sstrdup(str); |
686 return sstrdup(str); |
687 |
687 |
688 /* Compute expected buffer length */ |
688 /* Compute expected buffer length */ |
689 size_t ibufmax = str.length / pattern.length; |
689 size_t ibufmax = str.length / pattern.length; |
690 size_t ibuflen = replmax < ibufmax ? replmax : ibufmax; |
690 size_t ibuflen = replmax < ibufmax ? replmax : ibufmax; |