/** Returns if a string shares at least a specified numbers starting characters with a number of matches. * <p> * This method just exercise {@link #startsWithLenient(String, String, int, boolean)} with every one of * <code>matches</code> and <code>minChars</code>. * @param s The string to check. Not <code>null</code>. * @param matches A number of possible starts for <code>s</code>. * @param minChars The minimum number of characters to match for every element in <code>matches</code>. Needs * to be of same length as <code>matches</code>. Can be <code>null</code>. * @param acceptTrailing If after the required number of characters are matched on recognized characters that are not * in one of the the <code>matches</code> string should be accepted. For instance if "abczz" should be matched with * "abcdef" and min chars 3. * @return The index of the first unmatched character if <code>minChars</code> was reached or <code>-1</code> if a match was not * found. */ private static int startsWithLenient(String s, String[] matches, int[] minChars, boolean acceptTrailing) { for (int i = 0; i < matches.length; i++) { int minChar = minChars != null ? minChars[i] : -1; int ix = startsWithLenient(s, matches[i], minChar, acceptTrailing); if (ix > -1) return ix; } return -1; }
/** Parses alignment keywords and returns the appropriate <code>UnitValue</code>. * @param s The string to parse. Not <code>null</code>. * @param isHor If alignments for horizontal is checked. <code>false</code> means vertical. * @return The unit value or <code>null</code> if not recognized (no exception). */ static UnitValue parseAlignKeywords(String s, boolean isHor) { if (startsWithLenient(s, "center", 1, false) != -1) return UnitValue.CENTER; if (isHor) { if (startsWithLenient(s, "left", 1, false) != -1) return UnitValue.LEFT; if (startsWithLenient(s, "right", 1, false) != -1) return UnitValue.RIGHT; if (startsWithLenient(s, "leading", 4, false) != -1) return UnitValue.LEADING; if (startsWithLenient(s, "trailing", 5, false) != -1) return UnitValue.TRAILING; if (startsWithLenient(s, "label", 5, false) != -1) return UnitValue.LABEL; } else { if (startsWithLenient(s, "baseline", 4, false) != -1) return UnitValue.BASELINE_IDENTITY; if (startsWithLenient(s, "top", 1, false) != -1) return UnitValue.TOP; if (startsWithLenient(s, "bottom", 1, false) != -1) return UnitValue.BOTTOM; } return null; }
int ix = startsWithLenient(s, "gaptop", -1, true); if (ix > -1) { s = s.substring(ix).trim(); ix = startsWithLenient(s, "gapleft", -1, true); if (ix > -1) { s = s.substring(ix).trim(); ix = startsWithLenient(s, "gapbottom", -1, true); if (ix > -1) { s = s.substring(ix).trim(); ix = startsWithLenient(s, "gapright", -1, true); if (ix > -1) { s = s.substring(ix).trim(); ix = startsWithLenient(s, "gapbefore", -1, true); if (ix > -1) { s = s.substring(ix).trim(); ix = startsWithLenient(s, "gapafter", -1, true); if (ix > -1) { s = s.substring(ix).trim(); ix = startsWithLenient(s, new String[] {"gapx", "gapy"}, null, true); if (ix > -1) { boolean x = s.charAt(3) == 'x'; ix = startsWithLenient(s, "gap ", 1, true);
ix = startsWithLenient(part, new String[] {"sizegroup", "sg"}, new int[] {5, 2}, true); if (ix > -1) { dimConstraint.setSizeGroup(part.substring(ix).trim()); ix = startsWithLenient(part, new String[] {"shrinkprio", "shp"}, new int[] {10, 3}, true); if (ix > -1) { dimConstraint.setShrinkPriority(Integer.parseInt(part.substring(ix).trim())); ix = startsWithLenient(part, "shrink", 6, true); if (ix > -1) { dimConstraint.setShrink(parseFloat(part.substring(ix).trim(), ResizeConstraint.WEIGHT_100)); ix = startsWithLenient(part, new String[] {"growpriority", "gp"}, new int[] {5, 2}, true); if (ix > -1) { dimConstraint.setGrowPriority(Integer.parseInt(part.substring(ix).trim())); ix = startsWithLenient(part, "grow", 4, true); if (ix > -1) { dimConstraint.setGrow(parseFloat(part.substring(ix).trim(), ResizeConstraint.WEIGHT_100)); ix = startsWithLenient(part, "align", 2, true); if (ix > -1) {
ix = startsWithLenient(part, "wrap", -1, true); if (ix > -1) { String num = part.substring(ix).trim(); ix = startsWithLenient(part, "debug", 5, true); if (ix > -1) { String millis = part.substring(ix).trim(); ix = startsWithLenient(part, "insets", 3, true); if (ix > -1) { String insStr = part.substring(ix).trim(); ix = startsWithLenient(part, new String[]{"aligny", "ay"}, new int[]{6, 2}, true); if (ix > -1) { UnitValue align = parseUnitValueOrAlign(part.substring(ix).trim(), false, null); ix = startsWithLenient(part, new String[]{"alignx", "ax"}, new int[]{6, 2}, true); if (ix > -1) { lc.setAlignX(parseUnitValueOrAlign(part.substring(ix).trim(), true, null)); ix = startsWithLenient(part, "align", 2, true); if (ix > -1) { String[] gaps = toTrimmedTokens(part.substring(ix).trim(), ' ');
ix = startsWithLenient(part, "skip", 4, true); if (ix > -1) { String num = part.substring(ix).trim(); ix = startsWithLenient(part, "split", 5, true); if (ix > -1) { String split = part.substring(ix).trim(); ix = startsWithLenient(part, new String[]{"spany", "sy"}, new int[]{5, 2}, true); if (ix > -1) { cc.setSpanY(parseSpan(part.substring(ix).trim())); ix = startsWithLenient(part, new String[]{"spanx", "sx"}, new int[]{5, 2}, true); if (ix > -1) { cc.setSpanX(parseSpan(part.substring(ix).trim())); ix = startsWithLenient(part, "span", 4, true); if (ix > -1) { String[] spans = toTrimmedTokens(part.substring(ix).trim(), ' '); ix = startsWithLenient(part, "shrinkx", 7, true); if (ix > -1) { cc.getHorizontal().setShrink(parseFloat(part.substring(ix).trim(), ResizeConstraint.WEIGHT_100)); ix = startsWithLenient(part, "shrinky", 7, true); if (ix > -1) { cc.getVertical().setShrink(parseFloat(part.substring(ix).trim(), ResizeConstraint.WEIGHT_100)); ix = startsWithLenient(part, "shrink", 6, false);