//
//	MiscStringReplacing.m
//		Written by Don Yacktman (c) 1993 by Don Yacktman.
//				Version 1.95  All rights reserved.
//		This notice may not be removed from this source code.
//
//	This object is included in the MiscKit by permission from the author
//	and its use is governed by the MiscKit license, found in the file
//	"LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
//	for a list of all applicable permissions and restrictions.
//	

#import <misckit/MiscString.h>

@implementation MiscString(Replacing)

// This category is composed of methods which modify a MiscString
// by replacing a character or substring with a new character or
// substring.

- replaceFrom:(int)start length:(int)len with:(const char *)aString
{
  return [[self removeFrom:start length:len] insert:aString at:start];
}

- replaceFrom:(int)start to:(int)end with:(const char *)aString
{
  return [[self removeFrom:start to:end] insert:aString at:start];
}

- replaceFrom:(int)start length:(int)len withString:(id)sender
{
  if (![sender respondsTo:@selector(stringValue)]) return self;
  return [self replaceFrom:start length:len with:[sender stringValue]];
}

- replaceFrom:(int)start to:(int)end withString:(id)sender
{
  if (![sender respondsTo:@selector(stringValue)]) return self;
  return [self replaceFrom:start to:end with:[sender stringValue]];
}

/* Two methods no longer used:
- replace:(const char *)subString with:(const char *)newString
{
  const char *spot;
  
  if ((spot = [self strstr:subString]))
    [self replaceFrom:(int)(spot-buffer) length:strlen(subString) with:newString];
  return self;
}

- replace:(const char *)subString withString:(id)sender
{
  if (![sender respondsTo:@selector(stringValue)]) return self;
  return [self replace:subString with:[sender stringValue]];
}
*/

- replaceCharAt:(int)index withChar:(char)aChar
{	// no change if index is out of range.
	// Other option is to limit index to be in range.  which is better?
  if ((index < 0) || (index >= length)) return self;

  if (aChar == 0) return self; // should this return nil? DAY: leave it.

  buffer[index] = aChar;
  return self;
}

- replaceFrom:(int)start length:(int)len withChar:(char)aChar
{
    id retval,tempStr;
   
    if (aChar == 0) return nil;
    tempStr = [[[[self class] alloc] init] addChar:aChar];
    retval = [self  replaceFrom:start length:len
					withString:tempStr];
    [tempStr free];
    return retval;
}

- replaceFrom:(int)start to:(int)end withChar:(char)aChar
{
  return [self replaceFrom:start length:end-start+1 withChar:aChar];
}

- replaceEveryOccurrenceOfChars:(const char *)aString
		with:(const char *)replaceString
{
	return [self replaceEveryOccurrenceOfChars:aString
			with:replaceString caseSensitive:YES];
}

- replaceEveryOccurrenceOfChars:(const char *)aString
		with:(const char *)replaceString caseSensitive:(BOOL)sense
{
	int i;
	id tempStr;

	if (!aString) return self;
		// I think a null replace string should be allowed here...
 
	tempStr = [MiscString newWithString:aString];
	for (i=length-1;i>=0;i--)
	if ([tempStr spotOf:buffer[i] caseSensitive:sense] != -1)
		[self replaceFrom:i to:i with:replaceString];

	[tempStr free];
	return self;
}

- replaceEveryOccurrenceOfChars:(const char *)aString
		withChar:(char)replaceChar
{
	return [self replaceEveryOccurrenceOfChars:aString
			withChar:replaceChar caseSensitive:YES];
}

- replaceEveryOccurrenceOfChars:(const char *)aString
		withChar:(char)replaceChar caseSensitive:(BOOL)sense
{
	int i;
	id tempStr;

	if (!aString) return self;
	if (!replaceChar) return nil;  //or return self?

	tempStr = [MiscString newWithString:aString];
	for (i=length-1;i>=0;i--)
		if ([tempStr spotOf:buffer[i] caseSensitive:sense] != -1)
			buffer[i] = replaceChar;

	[tempStr free];
	return self;
}

- replaceEveryOccurrenceOfChars:(const char *)aString withString:(id)sender
{
	if (![sender respondsTo:@selector(stringValue)]) return self;
	return [self replaceEveryOccurrenceOfChars:aString
			with:[sender stringValue] caseSensitive:YES];
}

- replaceEveryOccurrenceOfChars:(const char *)aString
		withString:(id)sender caseSensitive:(BOOL)sense
{
	if (![sender respondsTo:@selector(stringValue)]) return self;
	return [self replaceEveryOccurrenceOfChars:aString
			with:[sender stringValue] caseSensitive:sense];
}

- replaceEveryOccurrenceOfChar:(char)aChar with:(const char *)aString
		caseSensitive:(BOOL)sense
{
	int i;

	if (!aChar) return self; // I think a null string should be allowed here...
	if (sense) {
		for (i=length-1;i>=0;i--)
			if (buffer[i] == aChar)
				[self replaceFrom:i to:i with:aString];
	} else {
		for (i=length-1;i>=0;i--)
			if (NXToUpper(buffer[i]) == NXToUpper(aChar))
				[self replaceFrom:i to:i with:aString];
	}
	return self;
}

- replaceEveryOccurrenceOfChar:(char)aChar with:(const char *)aString
{
	return [self replaceEveryOccurrenceOfChar:aChar
			with:aString caseSensitive:YES];
}

- replaceEveryOccurrenceOfChar:(char)aChar withString:(id)sender
{
	if (![sender respondsTo:@selector(stringValue)]) return self;
	return [self replaceEveryOccurrenceOfChar:aChar
			with:[sender stringValue] caseSensitive:YES];
}

- replaceEveryOccurrenceOfChar:(char)aChar withString:(id)sender
		caseSensitive:(BOOL)sense
{
	if (![sender respondsTo:@selector(stringValue)]) return self;
	return [self replaceEveryOccurrenceOfChar:aChar
			with:[sender stringValue] caseSensitive:sense];
}

- replaceEveryOccurrenceOfChar:(char)aChar withChar:(char)replaceChar
		caseSensitive:(BOOL)sense
{
	int i;

	if (!aChar) return self;
	if (!replaceChar) return nil;  //or return self?

	if (sense) {
		for (i=length-1; i>=0; i--)
			if (buffer[i] == aChar)
				buffer[i] = replaceChar;
	} else {
		for (i=length-1; i>=0; i--)
			if (NXToUpper(buffer[i]) == NXToUpper(aChar))
				buffer[i] = replaceChar;
	}
	return self;
}


- replaceEveryOccurrenceOfChar:(char)aChar withChar:(char)replaceChar
{
	return [self replaceEveryOccurrenceOfChar:aChar
			withChar:replaceChar caseSensitive:YES];
}

/* old methods no longer used:
// string replacements by Bruce McKenzie <bruce@trwlasd.com>
- replaceEveryOccurrenceOf:(const char *)subString	
	with:(const char *)newString
{
	const char *spot;
	int subStringLen;
	
	if (!subString) return nil;
	subStringLen = strlen(subString);
	if (!subStringLen) return nil;
	while ((spot = [self strstr:subString]))
		[self replaceFrom:(int)(spot-buffer) length:subStringLen
				with:(newString ? newString : "")];
	return self;
}

// and three extra covers by Don Yacktman:
- replaceEveryOccurrenceOfString:(id)subString with:(const char *)newString
{
	return [self replaceEveryOccurrenceOf:[subString stringValue]
				with:newString];
}

- replaceEveryOccurrenceOf:(const char *)subString withString:(id)newString
{
	return [self replaceEveryOccurrenceOf:subString
				with:[newString stringValue]];
}

- replaceEveryOccurrenceOfString:(id)subString withString:(id)newString
{
	return [self replaceEveryOccurrenceOf:[subString stringValue]
				with:[newString stringValue]];
}
*/

- replaceType:(int)type with:(const char *)str occurrenceNum:(int)n
{
  int spot;

  if (n == MISC_STRING_LAST) spot = [self rspotOfType:type occurrenceNum:0];
  else spot = [self spotOfType:type occurrenceNum:n];

  if (spot < 0) return self;
  return [self replaceFrom:spot length:1 with:str];
}

- replaceType:(int)type withString:(id)sender occurrenceNum:(int)n
{ 
  if (![sender respondsTo:@selector(stringValue)]) return self;
  return [self replaceType:type with:[sender stringValue] occurrenceNum:0];
}

- replaceType:(int)type withChar:(char)aChar occurrenceNum:(int)n
{ 
  char str[2] = {aChar, 0};
  return [self replaceType:type with:str occurrenceNum:n]; 
}


- replaceEveryOccurrenceOfType:(int)type with:(const char *)str
{
  int i;
  id tmpStr = [[[self class] alloc] initCapacity:length];

  for (i=0;i<length;i++) {
    if (type & MISC_UPPER)  if (NXIsUpper(buffer[i]))  {[tmpStr cat:str]; continue;}
    if (type & MISC_LOWER)  if (NXIsLower(buffer[i]))  {[tmpStr cat:str]; continue;}
    if (type & MISC_DIGIT)  if (NXIsDigit(buffer[i]))  {[tmpStr cat:str]; continue;}
    if (type & MISC_XDIGIT) if (NXIsXDigit(buffer[i])) {[tmpStr cat:str]; continue;}
    if (type & MISC_PUNCT)  if (NXIsPunct(buffer[i]))  {[tmpStr cat:str]; continue;}
    if (type & MISC_ASCII)  if (NXIsAscii(buffer[i]))  {[tmpStr cat:str]; continue;}
    if (type & MISC_CNTRL)  if (NXIsCntrl(buffer[i]))  {[tmpStr cat:str]; continue;}
    if (type & MISC_PRINT)  if (NXIsPrint(buffer[i]))  {[tmpStr cat:str]; continue;}
    if (type & MISC_SPACE)  if (NXIsSpace(buffer[i]))  {[tmpStr cat:str]; continue;}
    if (type & MISC_GRAPH)  if (NXIsGraph(buffer[i]))  {[tmpStr cat:str]; continue;}
    [tmpStr addChar:buffer[i]];
   }

  [self takeStringValueFrom:tmpStr];
  [tmpStr free];
  return self;
}


- replaceEveryOccurrenceOfType:(int)type withChar:(char)aChar 
{
  char str[2] = {aChar, 0};
  return [self replaceEveryOccurrenceOfType:type with:str];
}

- replaceEveryOccurrenceOfType:(int)type withString:(id)sender
{ 
  if (![sender respondsTo:@selector(stringValue)]) return self;
  return [self replaceEveryOccurrenceOfType:type with:[sender stringValue]]; 
}

- (int)replaceEveryOccurrenceOf:(const char *)str with:(const char *)repl caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  char fchar;
  int currspot = 0, len, lastspot = 0, currnum = 0;
  id tmpStr;

  if (!str || ((len = strlen(str)) == 0)) return 0;
  tmpStr = [[[self class] alloc] initCapacity:length];
  fchar = (sense)? str[0]:NXToUpper(str[0]);
  
  while (currspot <= (length-len)) {
    while ((currspot <= (length-len)) && (fchar != ((sense)?
           buffer[currspot]:NXToUpper(buffer[currspot]))))
      currspot++;
    if (!NXOrderStrings((unsigned char *)str,(unsigned char *)buffer+currspot,sense,len,orderTable)) {
      if ((currspot-lastspot) > 0)  // Can't -cat:n: if n < 0, so don't try (happens if overlapping)
        [tmpStr cat:buffer+lastspot n:currspot-lastspot];
      [tmpStr cat:repl];
      lastspot=currspot+len;
      if (overlap) currspot++;
      else currspot+=len;
      currnum++;
     }
    else currspot++;
   }
  
  if (currnum) {  //there was a change made
    [tmpStr cat:buffer+lastspot n:length-lastspot];
    [self takeStringValueFrom:tmpStr];
   }
  [tmpStr free];
  return currnum;
}

- (int)replaceEveryOccurrenceOf:(const char *)str withChar:(char)aChar caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  char tmp[2] = {aChar,0};
  return [self replaceEveryOccurrenceOf:str with:tmp caseSensitive:sense overlap:overlap];
}

- (int)replaceEveryOccurrenceOf:(const char *)str withString:(id)sender caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  if (![sender respondsTo:@selector(stringValue)]) return 0;
  return [self replaceEveryOccurrenceOf:str with:[sender stringValue] caseSensitive:sense overlap:overlap];
}

- (int)replaceEveryOccurrenceOfString:(id)sender with:(const char *)repl caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  if (![sender respondsTo:@selector(stringValue)]) return 0;
  return [self replaceEveryOccurrenceOf:[sender stringValue] with:repl caseSensitive:sense overlap:overlap];
}

- (int)replaceEveryOccurrenceOfString:(id)sender withChar:(char)aChar caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  char str[2] = {aChar,0};
  if (![sender respondsTo:@selector(stringValue)]) return 0;
  return [self replaceEveryOccurrenceOf:[sender stringValue] with:str caseSensitive:sense overlap:overlap];
}

- (int)replaceEveryOccurrenceOfString:(id)sender withString:(id)repl caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  if (![sender respondsTo:@selector(stringValue)]) return 0;
  if (![repl   respondsTo:@selector(stringValue)]) return 0;
  return [self replaceEveryOccurrenceOf:[sender stringValue] 
      with:[repl stringValue] caseSensitive:sense overlap:overlap];
}

- replace:(const char *)str with:(const char *)repl occurrenceNum:(int)n caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  int spot, len;

  if (n == MISC_STRING_LAST)
    spot = [self rspotOfStr:str occurrenceNum:0 caseSensitive:sense overlap:overlap];
  else spot = [self spotOfStr:str occurrenceNum:n caseSensitive:sense overlap:overlap];

  if (spot<0) return self;
  len = strlen(str); //str is not NULL here for sure
  
  return [self replaceFrom:spot length:len with:repl];
}

- replace:(const char *)str withChar:(char)aChar occurrenceNum:(int)n caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  char tmp[2] = {aChar, 0};
  return [self replace:str with:tmp occurrenceNum:n caseSensitive:sense overlap:overlap];
}

- replace:(const char *)str withString:(id)sender occurrenceNum:(int)n caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  if (![sender respondsTo:@selector(stringValue)]) return self;
  return [self replace:str with:[sender stringValue] occurrenceNum:n caseSensitive:sense overlap:overlap];
}

- replaceString:(id)sender with:(const char *)repl occurrenceNum:(int)n caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  if (![sender respondsTo:@selector(stringValue)]) return self;
  return [self replace:[sender stringValue] with:repl occurrenceNum:n caseSensitive:sense overlap:overlap];
}

- replaceString:(id)sender withChar:(char)aChar occurrenceNum:(int)n caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  if (![sender respondsTo:@selector(stringValue)]) return self;
  return [self replace:[sender stringValue] withChar:aChar occurrenceNum:n caseSensitive:sense overlap:overlap];
}

- replaceString:(id)sender withString:(id)repl occurrenceNum:(int)n caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{
  if (![sender respondsTo:@selector(stringValue)]) return self;
  if (![repl   respondsTo:@selector(stringValue)]) return self;
  return [self replace:[sender stringValue] with:[repl stringValue] occurrenceNum:n caseSensitive:sense overlap:overlap];
}

/*******************************************************************/
/**************   Convenience methods ******************************/
/*******************************************************************/


- replaceType:(int)type with:(const char *)str
{ return [self replaceType:type with:str occurrenceNum:0]; }

- replaceType:(int)type withChar:(char)aChar
{ return [self replaceType:type withChar:aChar occurrenceNum:0]; }

- replaceType:(int)type withString:(id)sender
{ return [self replaceType:type withString:sender occurrenceNum:0]; }

- (int)replaceEveryOccurrenceOf:(const char *)str with:(const char *)repl
{ return [self replaceEveryOccurrenceOf:str with:repl caseSensitive:YES overlap:NO]; }

- (int)replaceEveryOccurrenceOf:(const char *)str with:(const char *)repl caseSensitive:(BOOL)sense
{ return [self replaceEveryOccurrenceOf:str with:repl caseSensitive:sense overlap:NO]; }

- (int)replaceEveryOccurrenceOf:(const char *)str with:(const char *)repl overlap:(BOOL)overlap
{ return [self replaceEveryOccurrenceOf:str with:repl caseSensitive:YES overlap:overlap]; }


- (int)replaceEveryOccurrenceOf:(const char *)str withChar:(char)aChar
{ return [self replaceEveryOccurrenceOf:str withChar:aChar caseSensitive:YES overlap:NO]; }

- (int)replaceEveryOccurrenceOf:(const char *)str withChar:(char)aChar caseSensitive:(BOOL)sense
{ return [self replaceEveryOccurrenceOf:str withChar:aChar caseSensitive:sense overlap:NO]; }

- (int)replaceEveryOccurrenceOf:(const char *)str withChar:(char)aChar overlap:(BOOL)overlap
{ return [self replaceEveryOccurrenceOf:str withChar:aChar caseSensitive:YES overlap:overlap]; }


- (int)replaceEveryOccurrenceOf:(const char *)str withString:(id)sender
{ return [self replaceEveryOccurrenceOf:str withString:sender caseSensitive:YES overlap:NO]; }

- (int)replaceEveryOccurrenceOf:(const char *)str withString:(id)sender caseSensitive:(BOOL)sense
{ return [self replaceEveryOccurrenceOf:str withString:sender caseSensitive:sense overlap:NO]; }

- (int)replaceEveryOccurrenceOf:(const char *)str withString:(id)sender overlap:(BOOL)overlap
{ return [self replaceEveryOccurrenceOf:str withString:sender caseSensitive:YES overlap:overlap]; }



- (int)replaceEveryOccurrenceOfString:(id)sender with:(const char *)repl
{ return [self replaceEveryOccurrenceOfString:sender with:repl caseSensitive:YES overlap:NO]; }

- (int)replaceEveryOccurrenceOfString:(id)sender with:(const char *)repl caseSensitive:(BOOL)sense
{ return [self replaceEveryOccurrenceOfString:sender with:repl caseSensitive:sense overlap:NO]; }

- (int)replaceEveryOccurrenceOfString:(id)sender with:(const char *)repl overlap:(BOOL)overlap
{ return [self replaceEveryOccurrenceOfString:sender with:repl caseSensitive:YES overlap:overlap]; }


- (int)replaceEveryOccurrenceOfString:(id)sender withChar:(char)aChar
{ return [self replaceEveryOccurrenceOfString:sender withChar:aChar caseSensitive:YES overlap:NO]; }

- (int)replaceEveryOccurrenceOfString:(id)sender withChar:(char)aChar caseSensitive:(BOOL)sense
{ return [self replaceEveryOccurrenceOfString:sender withChar:aChar caseSensitive:sense overlap:NO]; }

- (int)replaceEveryOccurrenceOfString:(id)sender withChar:(char)aChar overlap:(BOOL)overlap
{ return [self replaceEveryOccurrenceOfString:sender withChar:aChar caseSensitive:YES overlap:overlap]; }


- (int)replaceEveryOccurrenceOfString:(id)sender withString:(id)repl
{ return [self replaceEveryOccurrenceOfString:sender withString:repl caseSensitive:YES overlap:NO]; }

- (int)replaceEveryOccurrenceOfString:(id)sender withString:(id)repl caseSensitive:(BOOL)sense
{ return [self replaceEveryOccurrenceOfString:sender withString:repl caseSensitive:sense overlap:NO]; }

- (int)replaceEveryOccurrenceOfString:(id)sender withString:(id)repl overlap:(BOOL)overlap
{ return [self replaceEveryOccurrenceOfString:sender withString:repl caseSensitive:YES overlap:overlap]; }



- replace:(const char *)str with:(const char *)repl
{ return [self replace:str with:repl occurrenceNum:0 caseSensitive:YES overlap:NO]; }

- replace:(const char *)str with:(const char *)repl occurrenceNum:(int)n
{ return [self replace:str with:repl occurrenceNum:n caseSensitive:YES overlap:NO]; }

- replace:(const char *)str with:(const char *)repl caseSensitive:(BOOL)sense
{ return [self replace:str with:repl occurrenceNum:0 caseSensitive:sense overlap:NO]; }

- replace:(const char *)str with:(const char *)repl occurrenceNum:(int)n caseSensitive:(BOOL)sense
{ return [self replace:str with:repl occurrenceNum:n caseSensitive:sense overlap:NO]; }

- replace:(const char *)str with:(const char *)repl overlap:(BOOL)overlap
{ return [self replace:str with:repl occurrenceNum:0 caseSensitive:YES overlap:overlap]; }

- replace:(const char *)str with:(const char *)repl occurrenceNum:(int)n overlap:(BOOL)overlap
{ return [self replace:str with:repl occurrenceNum:n caseSensitive:YES overlap:overlap]; }

- replace:(const char *)str with:(const char *)repl caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{ return [self replace:str with:repl occurrenceNum:0 caseSensitive:sense overlap:overlap]; }


- replace:(const char *)str withChar:(char)aChar
{ return [self replace:str withChar:aChar occurrenceNum:0 caseSensitive:YES overlap:NO]; }

- replace:(const char *)str withChar:(char)aChar occurrenceNum:(int)n
{ return [self replace:str withChar:aChar occurrenceNum:n caseSensitive:YES overlap:NO]; }

- replace:(const char *)str withChar:(char)aChar caseSensitive:(BOOL)sense
{ return [self replace:str withChar:aChar occurrenceNum:0 caseSensitive:sense overlap:NO]; }

- replace:(const char *)str withChar:(char)aChar occurrenceNum:(int)n caseSensitive:(BOOL)sense
{ return [self replace:str withChar:aChar occurrenceNum:n caseSensitive:sense overlap:NO]; }

- replace:(const char *)str withChar:(char)aChar overlap:(BOOL)overlap
{ return [self replace:str withChar:aChar occurrenceNum:0 caseSensitive:YES overlap:overlap]; }

- replace:(const char *)str withChar:(char)aChar occurrenceNum:(int)n overlap:(BOOL)overlap
{ return [self replace:str withChar:aChar occurrenceNum:n caseSensitive:YES overlap:overlap]; }

- replace:(const char *)str withChar:(char)aChar caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{ return [self replace:str withChar:aChar occurrenceNum:0 caseSensitive:sense overlap:overlap]; }


- replace:(const char *)str withString:(id)sender
{ return [self replace:str withString:sender occurrenceNum:0 caseSensitive:YES overlap:NO]; }

- replace:(const char *)str withString:(id)sender occurrenceNum:(int)n
{ return [self replace:str withString:sender occurrenceNum:n caseSensitive:YES overlap:NO]; }

- replace:(const char *)str withString:(id)sender caseSensitive:(BOOL)sense
{ return [self replace:str withString:sender occurrenceNum:0 caseSensitive:sense overlap:NO]; }

- replace:(const char *)str withString:(id)sender occurrenceNum:(int)n caseSensitive:(BOOL)sense
{ return [self replace:str withString:sender occurrenceNum:n caseSensitive:sense overlap:NO]; }

- replace:(const char *)str withString:(id)sender overlap:(BOOL)overlap
{ return [self replace:str withString:sender occurrenceNum:0 caseSensitive:YES overlap:overlap]; }

- replace:(const char *)str withString:(id)sender occurrenceNum:(int)n overlap:(BOOL)overlap
{ return [self replace:str withString:sender occurrenceNum:n caseSensitive:YES overlap:overlap]; }

- replace:(const char *)str withString:(id)sender caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{ return [self replace:str withString:sender occurrenceNum:0 caseSensitive:sense overlap:overlap]; }



- replaceString:(id)sender with:(const char *)repl
{ return [self replaceString:sender with:repl occurrenceNum:0 caseSensitive:YES overlap:NO]; }

- replaceString:(id)sender with:(const char *)repl occurrenceNum:(int)n
{ return [self replaceString:sender with:repl occurrenceNum:n caseSensitive:YES overlap:NO]; }

- replaceString:(id)sender with:(const char *)repl caseSensitive:(BOOL)sense
{ return [self replaceString:sender with:repl occurrenceNum:0 caseSensitive:sense overlap:NO]; }

- replaceString:(id)sender with:(const char *)repl occurrenceNum:(int)n caseSensitive:(BOOL)sense
{ return [self replaceString:sender with:repl occurrenceNum:n caseSensitive:sense overlap:NO]; }

- replaceString:(id)sender with:(const char *)repl overlap:(BOOL)overlap
{ return [self replaceString:sender with:repl occurrenceNum:0 caseSensitive:YES overlap:overlap]; }

- replaceString:(id)sender with:(const char *)repl occurrenceNum:(int)n overlap:(BOOL)overlap
{ return [self replaceString:sender with:repl occurrenceNum:n caseSensitive:YES overlap:overlap]; }

- replaceString:(id)sender with:(const char *)repl caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{ return [self replaceString:sender with:repl occurrenceNum:0 caseSensitive:sense overlap:overlap]; }


- replaceString:(id)sender withChar:(char)aChar
{ return [self replaceString:sender withChar:aChar occurrenceNum:0 caseSensitive:YES overlap:NO]; }

- replaceString:(id)sender withChar:(char)aChar occurrenceNum:(int)n
{ return [self replaceString:sender withChar:aChar occurrenceNum:n caseSensitive:YES overlap:NO]; }

- replaceString:(id)sender withChar:(char)aChar caseSensitive:(BOOL)sense
{ return [self replaceString:sender withChar:aChar occurrenceNum:0 caseSensitive:sense overlap:NO]; }

- replaceString:(id)sender withChar:(char)aChar occurrenceNum:(int)n caseSensitive:(BOOL)sense
{ return [self replaceString:sender withChar:aChar occurrenceNum:n caseSensitive:sense overlap:NO]; }

- replaceString:(id)sender withChar:(char)aChar overlap:(BOOL)overlap
{ return [self replaceString:sender withChar:aChar occurrenceNum:0 caseSensitive:YES overlap:overlap]; }

- replaceString:(id)sender withChar:(char)aChar occurrenceNum:(int)n overlap:(BOOL)overlap
{ return [self replaceString:sender withChar:aChar occurrenceNum:n caseSensitive:YES overlap:overlap]; }

- replaceString:(id)sender withChar:(char)aChar caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{ return [self replaceString:sender withChar:aChar occurrenceNum:0 caseSensitive:sense overlap:overlap]; }


- replaceString:(id)sender withString:(id)repl
{ return [self replaceString:sender withString:repl occurrenceNum:0 caseSensitive:YES overlap:NO]; }

- replaceString:(id)sender withString:(id)repl occurrenceNum:(int)n
{ return [self replaceString:sender withString:repl occurrenceNum:n caseSensitive:YES overlap:NO]; }

- replaceString:(id)sender withString:(id)repl caseSensitive:(BOOL)sense
{ return [self replaceString:sender withString:repl occurrenceNum:0 caseSensitive:sense overlap:NO]; }

- replaceString:(id)sender withString:(id)repl occurrenceNum:(int)n caseSensitive:(BOOL)sense
{ return [self replaceString:sender withString:repl occurrenceNum:n caseSensitive:sense overlap:NO]; }

- replaceString:(id)sender withString:(id)repl overlap:(BOOL)overlap
{ return [self replaceString:sender withString:repl occurrenceNum:0 caseSensitive:YES overlap:overlap]; }

- replaceString:(id)sender withString:(id)repl occurrenceNum:(int)n overlap:(BOOL)overlap
{ return [self replaceString:sender withString:repl occurrenceNum:n caseSensitive:YES overlap:overlap]; }

- replaceString:(id)sender withString:(id)repl caseSensitive:(BOOL)sense overlap:(BOOL)overlap
{ return [self replaceString:sender withString:repl occurrenceNum:0 caseSensitive:sense overlap:overlap]; }


@end
