<commit_before>/**
 * Implements the CFML Function replacenocase
 */
package railo.runtime.functions.string;

import java.util.Map;

import railo.commons.lang.StringUtil;
import railo.runtime.PageContext;
import railo.runtime.exp.ExpressionException;
import railo.runtime.exp.FunctionException;
import railo.runtime.exp.PageException;
import railo.runtime.ext.function.Function;
import railo.runtime.op.Caster;
import railo.runtime.op.Decision;

public final class ReplaceNoCase implements Function {

	public static String call(PageContext pc , String str, String sub1, String sub2) throws FunctionException {
		return _call(pc, str, sub1, sub2, true);
	}
	
	public static String call(PageContext pc , String str, String sub1, String sub2, String scope) throws FunctionException {
		return _call(pc, str, sub1, sub2, !scope.equalsIgnoreCase("all"));
	}

	public static String call( PageContext pc, String input, Object find, String repl, String scope ) throws ExpressionException {
		return _call(pc, input, find, repl, !scope.equalsIgnoreCase("all") );
	}

	public static String call( PageContext pc, String input, Object find, String repl ) throws ExpressionException {
		return _call(pc, input, find, repl, true);
	}
	
	private static String _call(PageContext pc , String str, String sub1, String sub2, boolean onlyFirst) throws FunctionException {
		if (StringUtil.isEmpty(sub1))
			throw new FunctionException(pc,"ReplaceNoCase",2,"sub1","The string length must be greater than 0");
		return StringUtil.replace(str, sub1, sub2, onlyFirst, true);
	}
	
	private static String _call( PageContext pc, String input, Object find, String repl , boolean onlyFirst) throws ExpressionException {
		if(!Decision.isSimpleValue(find ) )
			throw new FunctionException(pc,"ReplaceNoCase",2,"sub1","When passing three parameters or more, the second parameter must be a String.");
		return _call(pc, input, Caster.toString(input), repl, onlyFirst);
	}
	
	public static String call( PageContext pc, String input, Object struct ) throws PageException {
		if(!Decision.isStruct(struct))
			throw new FunctionException(pc,"ReplaceNoCase",2,"sub1","When passing only two parameters, the second parameter must be a Struct.");
		return StringUtil.replaceMap( input, Caster.toStruct(struct), true );
	}
	
}<commit_msg>replaceNoCase was using the source string as the replace string.<commit_after>/**
 * Implements the CFML Function replacenocase
 */
package railo.runtime.functions.string;

import railo.commons.lang.StringUtil;
import railo.runtime.PageContext;
import railo.runtime.exp.FunctionException;
import railo.runtime.exp.PageException;
import railo.runtime.ext.function.Function;
import railo.runtime.op.Caster;
import railo.runtime.op.Decision;

public final class ReplaceNoCase implements Function {

	private static final long serialVersionUID = -8001488161940178031L;

	public static String call(PageContext pc , String str, String sub1, String sub2) throws FunctionException {
		return _call(pc, str, sub1, sub2, true);
	}
	
	public static String call(PageContext pc , String str, String sub1, String sub2, String scope) throws FunctionException {
		return _call(pc, str, sub1, sub2, !scope.equalsIgnoreCase("all"));
	}

	public static String call( PageContext pc, String input, Object find, String repl, String scope ) throws PageException {
		return _call(pc, input, find, repl, !scope.equalsIgnoreCase("all") );
	}

	public static String call( PageContext pc, String input, Object find, String repl ) throws PageException {
		return _call(pc, input, find, repl, true);
	}
	
	private static String _call(PageContext pc , String str, String sub1, String sub2, boolean onlyFirst) throws FunctionException {
		if (StringUtil.isEmpty(sub1))
			throw new FunctionException(pc,"ReplaceNoCase",2,"sub1","The string length must be greater than 0");
		return StringUtil.replace(str, sub1, sub2, onlyFirst, true);
	}
	
	private static String _call( PageContext pc, String input, Object find, String repl , boolean onlyFirst) throws PageException {
		if(!Decision.isSimpleValue(find ) )
			throw new FunctionException(pc,"ReplaceNoCase",2,"sub1","When passing three parameters or more, the second parameter must be a String.");
		return _call(pc, input, Caster.toString(find), repl, onlyFirst);
	}
	
	public static String call( PageContext pc, String input, Object struct ) throws PageException {
		if(!Decision.isStruct(struct))
			throw new FunctionException(pc,"ReplaceNoCase",2,"sub1","When passing only two parameters, the second parameter must be a Struct.");
		return StringUtil.replaceMap( input, Caster.toStruct(struct), true );
	}
	
}
{'fraction_non_alphanumeric': 0.0982085042089359, 'fraction_numerical': 0.012734729117202677, 'mean_word_length': 5.554455445544554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6746083', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1288, 'n_words': 445}