final int parameterCount = parameters.getParameterCount();
if (parameterCount != 4)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
}
final TypeRegistry typeRegistry = context.getTypeRegistry();
final Type newTextType = parameters.getType(3);
final Object newTextValue = parameters.getValue(3);
final Type textType = parameters.getType(0);
final Object textValue = parameters.getValue(0);
final Type startType = parameters.getType(1);
final Object startValue = parameters.getValue(1);
final Type lengthType = parameters.getType(2);
final Object lengthValue = parameters.getValue(2);
final String newText = typeRegistry.convertToText(newTextType, newTextValue);
final String text = typeRegistry.convertToText(textType, textValue);
final Number start = typeRegistry.convertToNumber(startType, startValue);
final Number length = typeRegistry.convertToNumber(lengthType, lengthValue);
final MidFunction function = new MidFunction();
final String result1 = function.process(text, new Integer(1), new Integer(start.intValue() - 1));
final String result2 = function.process(text,
new Integer(start.intValue() + length.intValue()), new Integer(text.length()));