EpicKnarvik97 f59152a819
Some checks failed
KnarCraft/FFmpegConvert/pipeline/head There was a failure building this commit
Improves some method names and comments. Refactors parser
2020-05-12 01:05:52 +02:00

33 lines
1.2 KiB
Java

package net.knarcraft.ffmpegconverter.utility;
/**
* A class which helps with operations on strings
*/
final class StringUtil {
private StringUtil() {
}
/**
* Finds all substrings between two substrings in a string
*
* @param string <p>The string containing the substrings.</p>
* @param start <p>The substring before the wanted substring.</p>
* @param end <p>The substring after the wanted substring.</p>
* @return <p>A list of all occurrences of the substring.</p>
*/
static String[] stringBetween(String string, String start, String end) {
int startPosition = string.indexOf(start) + start.length();
//Return if the string is not found
if (!string.contains(start) || string.indexOf(end, startPosition) < startPosition) {
return new String[]{};
}
int endPosition = string.indexOf(end, startPosition);
//Get the string between the start and end string
String outString = string.substring(startPosition, endPosition).trim();
String nextString = string.substring(endPosition + end.length());
//Add other occurrences recursively
return ListUtil.concatenate(new String[]{outString}, stringBetween(nextString, start, end));
}
}