play1 icon indicating copy to clipboard operation
play1 copied to clipboard

[#1764]feature: add advanced urlcheck

Open flybyray opened this issue 8 years ago • 3 comments

replacement for #706

flybyray avatar May 29 '17 22:05 flybyray

@asolntsev is that version better? https://gist.github.com/flybyray/4c8c974d104478a101713ec9f9171038

flybyray avatar Jun 02 '17 11:06 flybyray

@flybyray I added a comment to the gist:

May be this could be a shorter solution:

private static String[] origRegex = { ... };
private static String[][] regexFragments = {
  origRegex,
  replace(origRegex, 4, "(?!(?:10)(?:\\.\\d{1,3}){3})"),
  replace(origRegex, 13, ""),
  replace(origRegex, 13, "")
};

P.S. I agree, all my comments are quite minor (cosmetic).

asolntsev avatar Jun 02 '17 11:06 asolntsev

would need something like this. but is this nicer to read?

    private static String[] origRegex = { ... };
    private static IntFunction[] intf = {
            x -> (x == 4) ? "(?!(?:10)(?:\\.\\d{1,3}){3})" : null,
            x -> (x == 13) ? "" : null
    };
    private static String[][] regexFragments = {
            origRegex,
            replace(origRegex.clone(), intf[0]),
            replace(origRegex.clone(), intf[1]),
            replace(replace(origRegex.clone(), intf[0]), intf[1])};
    private static String[] replace(String[] array, IntFunction<? extends String> generator) {
        for (int i = 0; i < array.length; i++) {
            final String object = generator.apply(i);
            if (object != null) array[i] = object;
        }
        return array;
    }

flybyray avatar Jun 02 '17 13:06 flybyray