⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regexpnode.java

📁 RESIN 3.2 最新源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	       || value == Character.PRIVATE_USE	       || value == Character.SURROGATE)) {	  return offset + 1;	}      }      return -1;    }  }  static class PropL extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (value == Character.LOWERCASE_LETTER	    || value == Character.MODIFIER_LETTER	    || value == Character.OTHER_LETTER	    || value == Character.TITLECASE_LETTER	    || value == Character.UPPERCASE_LETTER) {	  return offset + 1;	}      }      return -1;    }  }  static class PropNotL extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (! (value == Character.LOWERCASE_LETTER	       || value == Character.MODIFIER_LETTER	       || value == Character.OTHER_LETTER	       || value == Character.TITLECASE_LETTER	       || value == Character.UPPERCASE_LETTER)) {	  return offset + 1;	}      }      return -1;    }  }  static class PropM extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (value == Character.COMBINING_SPACING_MARK	    || value == Character.ENCLOSING_MARK	    || value == Character.NON_SPACING_MARK) {	  return offset + 1;	}      }      return -1;    }  }  static class PropNotM extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (! (value == Character.COMBINING_SPACING_MARK	       || value == Character.ENCLOSING_MARK	       || value == Character.NON_SPACING_MARK)) {	  return offset + 1;	}      }      return -1;    }  }  static class PropN extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (value == Character.DECIMAL_DIGIT_NUMBER	    || value == Character.LETTER_NUMBER	    || value == Character.OTHER_NUMBER) {	  return offset + 1;	}      }      return -1;    }  }  static class PropNotN extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);                	if (! (value == Character.DECIMAL_DIGIT_NUMBER	       || value == Character.LETTER_NUMBER	       || value == Character.OTHER_NUMBER)) {	  return offset + 1;	}      }      return -1;    }  }  static class PropP extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (value == Character.CONNECTOR_PUNCTUATION	    || value == Character.DASH_PUNCTUATION	    || value == Character.END_PUNCTUATION	    || value == Character.FINAL_QUOTE_PUNCTUATION	    || value == Character.INITIAL_QUOTE_PUNCTUATION	    || value == Character.OTHER_PUNCTUATION	    || value == Character.START_PUNCTUATION) {	  return offset + 1;	}      }        return -1;    }  }  static class PropNotP extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (! (value == Character.CONNECTOR_PUNCTUATION	       || value == Character.DASH_PUNCTUATION	       || value == Character.END_PUNCTUATION	       || value == Character.FINAL_QUOTE_PUNCTUATION	       || value == Character.INITIAL_QUOTE_PUNCTUATION	       || value == Character.OTHER_PUNCTUATION	       || value == Character.START_PUNCTUATION)) {	  return offset + 1;	}      }      return -1;    }  }  static class PropS extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (value == Character.CURRENCY_SYMBOL	    || value == Character.MODIFIER_SYMBOL	    || value == Character.MATH_SYMBOL	    || value == Character.OTHER_SYMBOL) {	  return offset + 1;	}      }      return -1;    }  }  static class PropNotS extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (! (value == Character.CURRENCY_SYMBOL	       || value == Character.MODIFIER_SYMBOL	       || value == Character.MATH_SYMBOL	       || value == Character.OTHER_SYMBOL)) {	  return offset + 1;	}      }      return -1;    }  }  static class PropZ extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (value == Character.LINE_SEPARATOR	    || value == Character.PARAGRAPH_SEPARATOR	    || value == Character.SPACE_SEPARATOR) {	  return offset + 1;	}      }      return -1;    }  }  static class PropNotZ extends AbstractCharNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset < strlen) {	char ch = string.charAt(offset);		int value = Character.getType(ch);        	if (! (value == Character.LINE_SEPARATOR	       || value == Character.PARAGRAPH_SEPARATOR	       || value == Character.SPACE_SEPARATOR)) {	  return offset + 1;	}      }      return -1;    }  }      static class Set extends AbstractCharNode {    private final boolean []_asciiSet;    private final IntSet _range;    Set(boolean []set, IntSet range)    {      _asciiSet = set;      _range = range;    }    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (strlen <= offset)	return -1;      char ch = string.charAt(offset);      if (ch < 128)	return _asciiSet[ch] ? offset + 1 : -1;      else	return _range.contains(ch) ? offset + 1 : -1;    }  }      static class NotSet extends AbstractCharNode {    private final boolean []_asciiSet;    private final IntSet _range;    NotSet(boolean []set, IntSet range)    {      _asciiSet = set;      _range = range;    }    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (strlen <= offset)	return -1;      char ch = string.charAt(offset);      if (ch < 128)	return _asciiSet[ch] ? -1 : offset + 1;      else	return _range.contains(ch) ? -1 : offset + 1;    }  }    static class StringNode extends RegexpNode {    private final char []_buffer;    private final int _length;    StringNode(CharBuffer value)    {      _length = value.length();      _buffer = new char[_length];      if (_length == 0)	throw new IllegalStateException("empty string");            System.arraycopy(value.getBuffer(), 0, _buffer, 0, _buffer.length);    }    StringNode(char []buffer, int length)    {      _length = length;      _buffer = buffer;      if (_length == 0)	throw new IllegalStateException("empty string");    }    @Override    RegexpNode createLoop(Regcomp parser, int min, int max)    {      if (_length == 1)	return new CharLoop(this, min, max);      else {	char ch = _buffer[_length - 1];		RegexpNode head = new StringNode(_buffer, _length - 1);	return head.concat(new CharNode(ch).createLoop(parser, min, max));      }    }    @Override    RegexpNode createLoopUngreedy(Regcomp parser, int min, int max)    {      if (_length == 1)	return new CharUngreedyLoop(this, min, max);      else {	char ch = _buffer[_length - 1];		RegexpNode head = new StringNode(_buffer, _length - 1);	return head.concat(new CharNode(ch).createLoopUngreedy(parser, min, max));      }    }    @Override    RegexpNode createPossessiveLoop(int min, int max)    {      if (_length == 1)	return super.createPossessiveLoop(min, max);      else {	char ch = _buffer[_length - 1];		RegexpNode head = new StringNode(_buffer, _length - 1);	return head.concat(new CharNode(ch).createPossessiveLoop(min, max));      }    }    //    // optim functions    //    @Override    int minLength()    {      return _length;    }    @Override    int firstChar()    {      if (_length > 0)	return _buffer[0];      else	return -1;    }    @Override    boolean []firstSet(boolean []firstSet)    {      if (firstSet != null && _length > 0 && _buffer[0] < firstSet.length) {	firstSet[_buffer[0]] = true;	return firstSet;      }      else	return null;    }    @Override    String prefix()    {      return new String(_buffer, 0, _length);    }    //    // match function    //    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (string.regionMatches(offset, _buffer, 0, _length))	return offset + _length;      else	return -1;    }    @Override    public String toString()    {      return "StringNode[" + new String(_buffer, 0, _length) + "]";    }  }    static class StringIgnoreCase extends RegexpNode {    private final char []_buffer;    private final int _length;    StringIgnoreCase(CharBuffer value)    {      _length = value.length();      _buffer = new char[_length];      if (_length == 0)	throw new IllegalStateException("empty string");            System.arraycopy(value.getBuffer(), 0, _buffer, 0, _buffer.length);    }    StringIgnoreCase(char []buffer, int length)    {      _length = length;      _buffer = buffer;      if (_length == 0)	throw new IllegalStateException("empty string");    }    @Override    RegexpNode createLoop(Regcomp parser, int min, int max)    {      if (_length == 1)	return new CharLoop(this, min, max);      else {	char ch = _buffer[_length - 1];		RegexpNode head = new StringIgnoreCase(_buffer, _length - 1);	RegexpNode tail = new StringIgnoreCase(new char[] { ch }, 1);	return head.concat(tail.createLoop(parser, min, max));      }    }    @Override    RegexpNode createLoopUngreedy(Regcomp parser, int min, int max)    {      if (_length == 1)	return new CharUngreedyLoop(this, min, max);      else {	char ch = _buffer[_length - 1];		RegexpNode head = new StringIgnoreCase(_buffer, _length - 1);	RegexpNode tail = new StringIgnoreCase(new char[] { ch }, 1);	return head.concat(tail.createLoopUngreedy(parser, min, max));      }    }    @Override    RegexpNode createPossessiveLoop(int min, int max)    {      if (_length == 1)	return super.createPossessiveLoop(min, max);      else {	char ch = _buffer[_length - 1];		RegexpNode head = new StringIgnoreCase(_buffer, _length - 1);	RegexpNode tail = new StringIgnoreCase(new char[] { ch }, 1);	return head.concat(tail.createPossessiveLoop(min, max));      }    }    //    // optim functions    //    @Override    int minLength()    {      return _length;    }    @Override    int firstChar()    {      if (_length > 0	  && (Character.toLowerCase(_buffer[0])	      == Character.toUpperCase(_buffer[0])))	return _buffer[0];      else	return -1;    }    @Override    boolean []firstSet(boolean []firstSet)    {      if (_length > 0 && firstSet != null) {	char lower = Character.toLowerCase(_buffer[0]);	char upper = Character.toUpperCase(_buffer[0]);	if (lower < firstSet.length && upper < firstSet.length) {	  firstSet[lower] = true;	  firstSet[upper] = true;	  return firstSet;	}      }      return null;    }    @Override    String prefix()    {      return new String(_buffer, 0, _length);    }    //    // match function    //    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (string.regionMatchesIgnoreCase(offset, _buffer, 0, _length))	return offset + _length;      else	return -1;    }  }  static final StringBegin STRING_BEGIN = new StringBegin();  static final StringEnd STRING_END = new StringEnd();  static final StringFirst STRING_FIRST = new StringFirst();  static final StringNewline STRING_NEWLINE = new StringNewline();  private static class StringBegin extends RegexpNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset == state._start)	  return offset;	else	  return -1;    }  }  private static class StringEnd extends RegexpNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset == strlen)	  return offset;	else	  return -1;    }  }  private static class StringFirst extends RegexpNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset == state._first)	  return offset;	else	  return -1;    }  }  private static class StringNewline extends RegexpNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if (offset == strlen	  || string.charAt(offset) == '\n' && offset + 1 == string.length())	  return offset;	else	  return -1;    }  }  static final Word WORD = new Word();  static final NotWord NOT_WORD = new NotWord();  private static class Word extends RegexpNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if ((state._start < offset	   && RegexpSet.WORD.match(string.charAt(offset - 1)))	  != (offset < strlen	      && RegexpSet.WORD.match(string.charAt(offset))))	return offset;      else	return -1;    }  }  private static class NotWord extends RegexpNode {    @Override    int match(StringValue string, int strlen, int offset, RegexpState state)    {      if ((state._start < offset	   && RegexpSet.WORD.match(string.charAt(offset - 1)))	  == (offset < strlen	      && RegexpSet.WORD.match(string.charAt(offset))))	return offset;      else	return -1;    }  }  static {    ANY_CHAR = new AsciiNotSet();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -