/** * Extracts a substring from the given text. * * @param details Details about what to extract * @param text The text from which to extract * @return The extracted value * @throws ConversionException Thrown when cannot process the parameters correctly */ private static String extractValueForConversion( final SubstringFormatterDetails details, final String text) throws ConversionException { final int startTagIndex = text.indexOf(details.getStartTag()); if (startTagIndex != -1) { final int endTagIndex = text.indexOf(details.getEndTag(), startTagIndex); if (endTagIndex != -1) { return text.substring(startTagIndex + details.getStartTag().length(), endTagIndex); } } throw new ConversionException("Cannot find tags"); }
/** * Replaces the given input text (optionally with the configured tags) with the given output text. * * @param details The formatter details * @param text The text to modify * @param input The input text to replace * @param output The text to replace the input with * @return The converted text */ private static String replaceTextAndTags( final SubstringFormatterDetails details, final String text, final String input, final String output) { String convertedText = text; if (details.isKeepTags()) { convertedText = convertedText.replace(input, output); } else { convertedText = convertedText.replace(details.getStartTag() + input + details.getEndTag(), output); } return convertedText; }