/** * Retrieves the error index. * * @return The approximate index in the pattern of the error, or {@code -1} * if the index is not known */ public int getIndex() { return pse.getIndex(); }
findRegexStart(this.pathPatternData, this.pathElementStart) + pse.getIndex(), this.pathPatternData, PatternMessage.REGEX_PATTERN_SYNTAX_EXCEPTION);
findRegexStart(this.pathPatternData, this.pathElementStart) + pse.getIndex(), this.pathPatternData, PatternMessage.REGEX_PATTERN_SYNTAX_EXCEPTION);
/** * Retrieves the error index. * * @return the approximate index in the pattern of the error, or {@code -1} if the index is * not known */ public int getIndex() { return pse.getIndex(); }
/** * Retrieves the error index. * * @return the approximate index in the pattern of the error, or {@code -1} if the index is * not known */ public int getIndex() { return pse.getIndex(); }
/** * Retrieves the error index. * * @return The approximate index in the pattern of the error, or {@code -1} * if the index is not known */ public int getIndex() { return pse.getIndex(); }
/** * Checks text value of JTextField if it is a valid regular expression. If not, focus is set to the text field and * an alert is shown. * * @param textfield * the text field with the regular expression * @return true if regular expression is valid, false otherwise */ private boolean checkRegExp(JTextField textfield) { try { Pattern.compile(textfield.getText()); } catch (PatternSyntaxException e) { textfield.setCaretPosition(e.getIndex()); JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), OStrings.getString("HTML_ERROR_CUSTOMREGEXP_TITLE"), JOptionPane.ERROR_MESSAGE); textfield.grabFocus(); return false; } return true; }
/** * Checks text value of JTextField if it is a valid regular expression. If not, focus is set to the text field and * an alert is shown. * * @param textfield * the text field with the regular expression * @return true if regular expression is valid, false otherwise */ private boolean checkRegExp(JTextField textfield) { try { Pattern.compile(textfield.getText()); } catch (PatternSyntaxException e) { textfield.setCaretPosition(e.getIndex()); JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), OStrings.getString("HTML_ERROR_CUSTOMREGEXP_TITLE"), JOptionPane.ERROR_MESSAGE); textfield.grabFocus(); return false; } return true; }
details.getPattern(), details.getIndex());
@Override public void saveOrUpdate(SpamRule rule) throws NotFoundException { try { Pattern.compile(rule.getRegex()); } catch (PatternSyntaxException ex){ throw new ValidationException(Sets.newHashSet(new ValidationError("regex", ex.getDescription() + " near index " + ex.getIndex()))); } getDao().saveOrUpdate(rule); }
@Override void analyze(Locals locals) { if (!read) { throw createError(new IllegalArgumentException("Regex constant may only be read [" + pattern + "].")); } try { Pattern.compile(pattern, flags); } catch (PatternSyntaxException e) { throw new Location(location.getSourceName(), location.getOffset() + 1 + e.getIndex()).createError( new IllegalArgumentException("Error compiling regex: " + e.getDescription())); } constant = new Constant( location, MethodWriter.getType(Pattern.class), "regexAt$" + location.getOffset(), this::initializeConstant); actual = Pattern.class; }
protected void addValidatorsForPattern( Document parent, Path parentPath, Problems problems, CompositeValidator validators ) { String regex = parent.getString("pattern"); if (regex != null) { String requiredName = parentPath.getLast(); if (requiredName != null) { try { Pattern pattern = Pattern.compile(regex); validators.add(new PatternValidator(requiredName, pattern)); } catch (PatternSyntaxException e) { problems.recordError(parentPath.with("pattern"), "The supplied value '" + regex + "' is expected to be a valid regular expression, but there was an error at position " + e.getIndex() + ": " + e.getDescription()); } } } }
protected void addValidatorsForPattern( Document parent, Path parentPath, Problems problems, CompositeValidator validators ) { String regex = parent.getString("pattern"); if (regex != null) { String requiredName = parentPath.getLast(); if (requiredName != null) { try { Pattern pattern = Pattern.compile(regex); validators.add(new PatternValidator(requiredName, pattern)); } catch (PatternSyntaxException e) { problems.recordError(parentPath.with("pattern"), "The supplied value '" + regex + "' is expected to be a valid regular expression, but there was an error at position " + e.getIndex() + ": " + e.getDescription()); } } } }
private void mark(NSMutableAttributedString text, PatternSyntaxException e) { if(null == e) { text.removeAttributeInRange( NSAttributedString.ForegroundColorAttributeName, NSRange.NSMakeRange(new NSUInteger(0), text.length())); return; } int index = e.getIndex(); //The approximate index in the pattern of the error NSRange range = null; if(-1 == index) { range = NSRange.NSMakeRange(new NSUInteger(0), text.length()); } if(index < text.length().intValue()) { //Initializes the NSRange with the range elements of location and length; range = NSRange.NSMakeRange(new NSUInteger(index), new NSUInteger(1)); } text.addAttributesInRange(RED_FONT, range); }
findRegexStart(this.pathPatternData, this.pathElementStart) + pse.getIndex(), this.pathPatternData, PatternMessage.REGEX_PATTERN_SYNTAX_EXCEPTION);
findRegexStart(this.pathPatternData, this.pathElementStart) + pse.getIndex(), this.pathPatternData, PatternMessage.REGEX_PATTERN_SYNTAX_EXCEPTION);