Changeset 63 for trunk/src/helpers/xstring.c
- Timestamp:
- Apr 25, 2001, 8:55:35 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/xstring.c
r45 r63 690 690 /* 691 691 *@@ xstrrpl: 692 * replaces cReplLencharacters in pxstr, starting693 * at the position ulFirstReplPos, with the string694 * in pxstrReplaceWith.692 * replaces "cReplLen" characters in pxstr, starting 693 * at the position "ulFirstReplPos", with the first 694 * "cReplaceWithLen" characters from pcszReplaceWith. 695 695 * 696 696 * Returns the new length of the string, excluding … … 727 727 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash 728 728 *@@changed V0.9.9 (2001-03-09) [umoeller]: now using xstrReserve 729 *@@changed V0.9.11 (2001-04-22) [umoeller]: replaced replacement XSTRING with PCSZ 729 730 */ 730 731 … … 732 733 ULONG ulFirstReplOfs, // in: ofs of first char to replace 733 734 ULONG cReplLen, // in: no. of chars to replace 734 const XSTRING *pstrReplaceWith) // in: string to replace chars with 735 const char *pcszReplaceWith, // in: string to replace chars with 736 ULONG cReplaceWithLen) // in: length of replacement string 737 // (this MUST be specified; if 0, chars are removed only) 735 738 { 736 739 ULONG ulrc = 0; … … 739 742 if ( (pxstr) // V0.9.9 (2001-02-14) [umoeller] 740 743 && (ulFirstReplOfs + cReplLen <= pxstr->ulLength) 741 && (pstrReplaceWith) 742 // && (pstrReplaceWith->ulLength) no, this can be empty 744 && (pcszReplaceWith) 743 745 ) 744 746 { 745 ULONG cReplaceLen = pstrReplaceWith->ulLength;746 // can be 0!747 748 747 // size of new buffer: 749 ULONG cbNeeded = pxstr->ulLength 750 + cReplace Len751 - cReplLen 752 + 1; //null terminator748 ULONG cbNeeded = pxstr->ulLength // existing 749 + cReplaceWithLen // plus replacement string length 750 - cReplLen // minus replaced characters 751 + 1; // plus null terminator 753 752 // offset where pszSearch was found 754 753 PSZ pFound = pxstr->psz + ulFirstReplOfs; … … 791 790 ulFirstReplOfs); // up to "found" 792 791 793 if (cReplace Len)792 if (cReplaceWithLen) 794 793 { 795 794 // we have a replacement: 796 795 // insert it next 796 797 /* memcpy(pszNew + ulFirstReplOfs, 798 pstrReplaceWith->psz, 799 cReplaceWithLen + 1); // include null terminator 800 */ 801 // no, we no longer can be sure that pcszReplaceWith is 802 // null terminated, so terminate explicitly 803 // V0.9.11 (2001-04-22) [umoeller] 804 797 805 memcpy(pszNew + ulFirstReplOfs, 798 pstrReplaceWith->psz, 799 cReplaceLen + 1); // include null terminator 806 pcszReplaceWith, 807 cReplaceWithLen); 808 *(pszNew + ulFirstReplOfs + cReplaceWithLen) = '\0'; 800 809 } 801 810 … … 810 819 // ³ ³ 811 820 // pxstr->ulLength = 14 812 memcpy(pszNew + ulFirstReplOfs + cReplace Len,821 memcpy(pszNew + ulFirstReplOfs + cReplaceWithLen, 813 822 pFound + cReplLen, 814 823 // remaining bytes: … … 833 842 // first, we move the end to its new location 834 843 // (memmove handles overlap if needed) 835 memmove(pFound + cReplace Len,844 memmove(pFound + cReplaceWithLen, 836 845 pFound + cReplLen, 837 846 cTailLength + 1); // including null terminator 838 847 839 848 // now overwrite "found" in the middle 840 if (cReplace Len)849 if (cReplaceWithLen) 841 850 { 842 851 memcpy(pFound, 843 p strReplaceWith->psz,844 cReplace Len); // no null terminator852 pcszReplaceWith, 853 cReplaceWithLen); // no null terminator 845 854 } 846 855 … … 1032 1041 ulFirstReplOfs, // where to start 1033 1042 cSearchLen, // chars to replace 1034 pstrReplace); 1043 pstrReplace->psz, 1044 pstrReplace->ulLength); // adjusted V0.9.11 (2001-04-22) [umoeller] 1035 1045 1036 1046 // return new length
Note:
See TracChangeset
for help on using the changeset viewer.