package tars.commons.util;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;

/**
 * Helper functions for handling strings.
 */
public class StringUtil {
    public static boolean containsIgnoreCase(String source, String query) {
        String[] split = source.toLowerCase().split("\\s+");
        List<String> strings = Arrays.asList(split);
        return strings.stream().filter(s -> s.equals(query.toLowerCase())).count() > 0;
    }

    /**
     * Returns a detailed message of the t, including the stack trace.
     */
    public static String getDetails(Throwable t){
        StringWriter sw = new StringWriter();
        t.printStackTrace(new PrintWriter(sw));
        return t.getMessage() + "\n" + sw.toString();
    }

    /**
     * Returns true if s represents an unsigned integer e.g. 1, 2, 3, ... <br>
     *   Will return false for null, empty string, "-1", "0", "+1", and " 2 " (untrimmed) "3 0" (contains whitespace).
     * @param s Should be trimmed.
     */
    public static boolean isUnsignedInteger(String s){
        return s != null && s.matches("^0*[1-9]\\d*$");
    }
}

@@ -127,16 +127,126 @@
 .List;%0A%0A
+import tars.commons.exceptions.IllegalValueException;%0Aimport tars.commons.exceptions.InvalidRangeException;%0A%0A%0A
 /**%0A * H
@@ -1256,10 +1256,1996 @@
 ;%0A    %7D%0A
-%7D
+    %0A    /**%0A     * Handles three different cases of strings and return them in the appropriate format%0A     * @@author A0121533W%0A     */%0A    public static String indexString(String s) throws InvalidRangeException, IllegalValueException %7B%0A        if (s.isEmpty()) %7B%0A            return s;%0A        %7D%0A        // String is single number%0A        if (s.indexOf(%22 %22) == -1 && !s.contains(%22..%22)) %7B%0A            if (!isUnsignedInteger(s)) %7B%0A                throw new IllegalValueException(%22Invalid index entered%22); %0A            %7D%0A            return s;%0A        %7D%0A        // String is list of indexes separated by whitespace%0A        if (s.indexOf(%22 %22) != -1 && !s.contains(%22..%22)) %7B%0A            String indexString = %22%22;%0A            String%5B%5D indexArray = s.split(%22 %22);%0A            for (int i = 0; i %3C indexArray.length; i++) %7B%0A                if (!isUnsignedInteger(indexArray%5Bi%5D)) %7B%0A                    throw new IllegalValueException(%22Invalid index entered%22); %0A                %7D%0A                indexString += indexArray%5Bi%5D + %22 %22;%0A            %7D%0A            return indexString.trim();%0A        %7D%0A        // String is a range of indexes%0A        if (s.contains(%22..%22)) %7B%0A            String rangeToReturn = %22%22;%0A%0A            int toIndex = s.indexOf(%22..%22);%0A            String start = s.substring(0, toIndex);%0A            String end = s.substring(toIndex + 2);%0A            %0A            if (!isUnsignedInteger(start) %7C%7C !isUnsignedInteger(end)) %7B%0A                throw new IllegalValueException(%22Invalid index entered%22);%0A            %7D%0A%0A            int startInt = Integer.parseInt(start);%0A            int endInt = Integer.parseInt(end);%0A%0A            if (startInt %3E endInt) %7B%0A                throw new InvalidRangeException();%0A            %7D%0A%0A            for (int i = startInt; i %3C= endInt; i++) %7B%0A                rangeToReturn += String.valueOf(i) + %22 %22;%0A            %7D%0A%0A            return rangeToReturn.trim();%0A        %7D else %7B%0A            throw new IllegalValueException(%22Unexpected error!%22);%0A        %7D%0A    %7D%0A%7D%0A
 %0A

Fix method to take in index from string