public static String getRequiredReplName(String text) { if (text == null) { return null; } String trimmed = text.trim(); if (!trimmed.startsWith("%")) { return null; } // get script head int scriptHeadIndex = 0; for (int i = 0; i < trimmed.length(); i++) { char ch = trimmed.charAt(i); if (Character.isWhitespace(ch) || ch == '(' || ch == '\n') { break; } scriptHeadIndex = i; } if (scriptHeadIndex < 1) { return null; } String head = text.substring(1, scriptHeadIndex + 1); return head; }
public static String getRequiredReplName(String text) { if (text == null) { return null; } // get script head int scriptHeadIndex = 0; for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); if (Character.isWhitespace(ch) || ch == '(') { scriptHeadIndex = i; break; } } if (scriptHeadIndex == 0) { return null; } String head = text.substring(0, scriptHeadIndex); if (head.startsWith("%")) { return head.substring(1); } else { return null; } }