[Python-checkins] CVS: python/dist/src/Modules stropmodule.c,2.75,2.75.6.1
Thomas Wouters
twouters@users.sourceforge.net
2001年5月23日 06:36:39 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv8843/Modules
Modified Files:
Tag: release21-maint
stropmodule.c
Log Message:
Index: stropmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/stropmodule.c,v
retrieving revision 2.75
retrieving revision 2.75.6.1
diff -C2 -r2.75 -r2.75.6.1
*** stropmodule.c 2000年09月26日 05:46:01 2.75
--- stropmodule.c 2001年05月23日 13:36:37 2.75.6.1
***************
*** 1057,1090 ****
if (nfound == 0)
goto return_same;
- new_len = len + nfound*(sub_len - pat_len);
-
- new_s = (char *)PyMem_MALLOC(new_len);
- if (new_s == NULL) return NULL;
-
- *out_len = new_len;
- out_s = new_s;
-
- while (len > 0) {
- /* find index of next instance of pattern */
- offset = mymemfind(str, len, pat, pat_len);
- /* if not found, break out of loop */
- if (offset == -1) break;
! /* copy non matching part of input string */
! memcpy(new_s, str, offset); /* copy part of str before pat */
! str += offset + pat_len; /* move str past pattern */
! len -= offset + pat_len; /* reduce length of str remaining */
!
! /* copy substitute into the output string */
! new_s += offset; /* move new_s to dest for sub string */
! memcpy(new_s, sub, sub_len); /* copy substring into new_s */
! new_s += sub_len; /* offset new_s past sub string */
!
! /* break when we've done count replacements */
! if (--count == 0) break;
}
! /* copy any remaining values into output string */
! if (len > 0)
! memcpy(new_s, str, len);
return out_s;
--- 1057,1097 ----
if (nfound == 0)
goto return_same;
! new_len = len + nfound*(sub_len - pat_len);
! if (new_len == 0) {
! out_s = "";
}
! else {
! assert(new_len > 0);
! new_s = (char *)PyMem_MALLOC(new_len);
! if (new_s == NULL)
! return NULL;
! out_s = new_s;
!
! while (len > 0) {
! /* find index of next instance of pattern */
! offset = mymemfind(str, len, pat, pat_len);
! if (offset == -1)
! break;
!
! /* copy non matching part of input string */
! memcpy(new_s, str, offset);
! str += offset + pat_len;
! len -= offset + pat_len;
!
! /* copy substitute into the output string */
! new_s += offset;
! memcpy(new_s, sub, sub_len);
! new_s += sub_len;
!
! /* note count==0 is effectively infinity */
! if (--count == 0)
! break;
! }
! /* copy any remaining values into output string */
! if (len > 0)
! memcpy(new_s, str, len);
! }
! *out_len = new_len;
return out_s;