Important: The information in this document is obsolete and should not be used for new development.
Munger
TheMungerfunction searches text for a specified string pattern and replaces it with another string.
FUNCTION Munger (h: Handle; offset: LongInt; ptr1: Ptr; len1: LongInt; ptr2: Ptr; len2: LongInt): LongInt;
h- A handle to the text string that is being manipulated.
offset- The byte offset in the destination string at which
Mungerbegins
its operation.ptr1- A pointer to the first character in the string for which
Mungeris searching.len1- The number of bytes in the string for which
Mungeris searching.ptr2- A pointer to the first character in the substitution string.
len2- The number of bytes in the substitution string.
DESCRIPTION
Mungermanipulates bytes in a string to which you specify a handle in thehparameter. The manipulation begins at a byte offset, specified inoffset, in the string. Munger searches for the string specified byptr1andlen1; when it finds an instance of that string, it replaces it with the substitution string, which is specified byptr2andlen2.
- IMPORTANT
Mungeroperates on a byte-by-byte basis, which can produce inappropriate results for 2-byte script systems. TheReplaceTextfunction works properly for all languages. You are encouraged to useReplaceTextinstead ofMungerwhenever possible.![]()
Mungertakes special action if either of the specified pointer values isNILor if either of the length values is0.
- If
ptr1isNIL,Mungerreplaces characters without searching. It replaceslen1characters starting at theoffsetlocation with the substitution string.- If
ptr1isNILandlen1is negative,Mungerreplaces all of the characters from theoffsetlocation to the end of the string with the substitution string.- If
len1is 0,Mungerinserts the substitution string without replacing anything.Mungerinserts the string at theoffsetlocation and returns the offset of the first byte past where the insertion occurred.- If
ptr2isNIL,Mungersearches but does not replace. In this case,Mungerreturns the offset at which the string was found.- If
len2is 0 andptr2is notNIL,Mungersearches and deletes. In this case,Mungerreturns the offset at which it deleted.- If the portion of the string from the
offsetlocation to its end matches the beginning of the string thatMungeris searching for,Mungerreplaces that portion with the substitution string.
Mungerreturns a negative value when it cannot find the designated string.
- WARNING
- Be careful not to specify an offset with a value that is greater than the length of the destination string. Unpredictable results may occur.
![]()
SPECIAL CONSIDERATIONS
Mungermay move memory; your application should not call this function at
interrupt time.The destination string must be in a relocatable block that was allocated by the
Memory Manager.SEE ALSO
Mungercalls theGetHandleSizeandSetHandleSizeroutines to access or modify the length of the string it is manipulating. These routines are described in the book Inside Macintosh: Memory Manager.ASSEMBLY-LANGUAGE INFORMATION
The trap macro for theMungerfunction is
Trap macro _Munger