package seedu.taskell.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){
        assert t != null;
        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*$");
    }
}

@@ -491,24 +491,457 @@
 ) %3E 0;%0A    %7D
+%0A    %0A    /** @@author A0142130A **/%0A    /** checks if source contains query as substring and ignores case%0A     */%0A    public static boolean containsSubstringAndIgnoreCase(String source, String query) %7B%0A        String%5B%5D split = source.toLowerCase().split(%22%5C%5Cs+%22);%0A        List%3CString%3E strings = Arrays.asList(split);%0A        return strings.stream().filter(s -%3E s.contains(query.toLowerCase())).count() %3E 0;%0A    %7D%0A    /** @@author **/
 %0A%0A    /**%0A  

add method to find substrings