Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String convertMatchesToStringLength(String test) {

        if (test.contains("matches")) {

            int indexMatches = test.indexOf("matches");
            int firstBracketIndex = test.indexOf("(", indexMatches);
            int lastBracketIndex = test.lastIndexOf(")");

            String matchesContext = test.substring(firstBracketIndex + 1, lastBracketIndex);
            String normalizeSpace = matchesContext.split(" , ")[0];
            String regex = matchesContext.split(" , ")[1];

            if (regex.contains("[0-9]")) {
                int firstParenthesis = regex.indexOf("{");
                int lastParenthesis = regex.indexOf("}", firstParenthesis);

                String lengthRange[] = regex.substring(firstParenthesis + 1, lastParenthesis).split(",");

                if (lengthRange.length > 1) {
                    String startOffset = lengthRange[0];
                    String endOffset = lengthRange[1];
                    //string-length(normalize-space(.)) >= 10 and string-length(normalize-space(.)) <= 11
                    test = "string-length" + "(" + normalizeSpace + ")" + " >= " + startOffset + " and "
                            + "string-length" + "(" + normalizeSpace + ")" + " <= " + endOffset;
                } else {
                    String length = lengthRange[0];
                    test = "string-length" + "(" + normalizeSpace + ")" + " = " + length;
                }

            }

        }

        return test.trim();
    }
}