src/string.c

changeset 383
db4c6b94939b
parent 380
2c9a5aebaee1
equal deleted inserted replaced
382:d746888af4e5 383:db4c6b94939b
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;

mercurial