A scanner that succeeds and consumes all the characters until the {@code '\n'} character
if the current input starts with the string literal {@code begin}. The {@code '\n'} character
isn't consumed.
344367
public static Parser<Void> lineComment(String begin) {
    return Patterns.lineComment(begin).toScanner(begin);
  }
149764
function scanStringLiteral() {
        var str = '', quote, start, ch, octal = false;

        quote = source[index];
        assert((quote === '\'' || quote === '"'),
            'String literal must starts with a quote');

        start = index;
        ++index;

        while (index < length) {
            ch = source[index++];

            if (ch === quote) {
                quote = '';
                break;
            } else if (ch === '\\') {
                ch = source[index++];
                if (!ch || !isLineTerminator(ch.charCodeAt(0))) {
                    switch (ch) {
                    case 'n':
                        str += '\n';
                        break;
                    case 'r':
                        str += '\r';
                        break;
                    case 't':
                        str += '\t';
                        break;
                    case 'b':
                        str += '\b';
                        break;
                    case 'f':
                        str += '\f';
                        break;
                    case 'v':
                        str += '\x0B';
                        break;

                    default:
                        str += ch;
                        break;
                    }
                } else {
                    if (ch ===  '\r' && source[index] === '\n') {
                        ++index;
                    }
                }
            } else if (isLineTerminator(ch.charCodeAt(0))) {
                break;
            } else {
                str += ch;
            }
        }

        if (quote !== '') {
            throwError({}, Messages.UnexpectedToken, 'ILLEGAL');
        }

        return {
            type: Token.StringLiteral,
            value: str,
            octal: octal,
            range: [start, index]
        };
    }
1074309
function (checks) {
    this.from = this.char;

    // Move to the next non-space character.
    var start;
    if (/\s/.test(this.peek())) {
      start = this.char;

      while (/\s/.test(this.peek())) {
        this.from += 1;
        this.skip();
      }
    }

    // Methods that work with multi-line structures and move the
    // character pointer.

    var match = this.scanComments() ||
      this.scanStringLiteral(checks) ||
      this.scanTemplateLiteral();

    if (match) {
      return match;
    }

    // Methods that don't move the character pointer.

    match =
      this.scanRegExp() ||
      this.scanPunctuator() ||
      this.scanKeyword() ||
      this.scanIdentifier() ||
      this.scanNumericLiteral();

    if (match) {
      this.skip(match.value.length);
      return match;
    }

    // No token could be matched, give up.

    return null;
  }
249725
private static int findStart( char[] buffer, int start, int end )
    {
        int pos, cp;
        for ( pos = start; pos < end && isWhitespace( cp = codePointAt( buffer, pos ) ); pos += charCount( cp ) )
        {
            if ( cp == '\n' )
            {
                start = pos + 1;
            }
        }
        return pos >= end ? end : start;
    }
472963
@Override
    public boolean hasNext(int startPosition, int contentLength) {
        char ch = nextGoodChar();
        if (ch == ',') return true;
        if (ch == '}' || ch == ']' || ch == 0) return false;
        backChar(ch); // { [ 交由 readObjectB 或 readMapB 或 readArrayB 读取
        return true;
    }
1090856
private void parse(String input) {
        char[] data = input.toCharArray();
        int start = 0;
        int hard_stop = data.length - 1;
        while (start < data.length) {
            if (this.mySep == data[start]) {
                start++;
                continue;
            }
            // look for the '=', end of data, or the separator
            int end = start;
            String key = null;
            boolean insideQuotes = false;
            while (end < data.length) {
                boolean extract = false;
                if ('"' == data[end]) {
                    insideQuotes = !insideQuotes;
                } else if (this.mySep == data[end]) {
                    extract = true;
                    end--;
                } else if ('=' == data[end]) {
                    // found a key
                    key = extractString(data, start, end - 1);
                    end++; // past the '='
                    start = end;
                    continue;
                }
                // if we're on the last character then always extract and quit
                if (end == hard_stop) {
                    extract = true;
                }

                // if we need to, extract the value and continue
                if (extract) {
                    String value = extractString(data, start, end);
                    if (null == key) {
                        addElement(value);
                    } else {
                        addElement(key, value);
                    }
                    // at this point, end is pointing to the last char of the val
                    end = end + 2; // jump past delim
                    start = end;
                    if (!insideQuotes) {
                        break; // out of while
                    }
                    continue;
                }
                end++;
            }
        }
    }
743460
public static String readLine(ByteBuffer buffer, Charset charset) {
		final int startPosition = buffer.position();
		final int endPosition = lineEnd(buffer);

		if (endPosition > startPosition) {
			byte[] bs = readBytes(buffer, startPosition, endPosition);
			return StrUtil.str(bs, charset);
		} else if (endPosition == startPosition) {
			return StrUtil.EMPTY;
		}

		return null;
	}
844170
private boolean processChar(char c) {
		if(inTextArea) {
			if(
				c==TrimFilterWriter.textarea_close[readCharMatchCount]
				|| c==TrimFilterWriter.TEXTAREA_CLOSE[readCharMatchCount]
			) {
				readCharMatchCount++;
				if(readCharMatchCount>=TrimFilterWriter.textarea_close.length) {
					inTextArea=false;
					readCharMatchCount=0;
				}
			} else {
				readCharMatchCount=0;
			}
			return true;
		} else if(inPre) {
			if(
				c==TrimFilterWriter.pre_close[preReadCharMatchCount]
				|| c==TrimFilterWriter.PRE_CLOSE[preReadCharMatchCount]
			) {
				preReadCharMatchCount++;
				if(preReadCharMatchCount>=TrimFilterWriter.pre_close.length) {
					inPre=false;
					preReadCharMatchCount=0;
				}
			} else {
				preReadCharMatchCount=0;
			}
			return true;
		} else {
			if(c=='\r') {
				readCharMatchCount = 0;
				preReadCharMatchCount = 0;
				// Carriage return only output when no longer at the beginning of the line
				return !atLineStart;
			} else if(c=='\n') {
				readCharMatchCount = 0;
				preReadCharMatchCount = 0;
				// Newline only output when no longer at the beginning of the line
				if(!atLineStart) {
					atLineStart = true;
					return true;
				} else {
					return false;
				}
			} else if(c==' ' || c=='\t') {
				readCharMatchCount = 0;
				preReadCharMatchCount = 0;
				// Space and tab only output when no longer at the beginning of the line
				return !atLineStart;
			} else {
				atLineStart = false;
				if(
					c==TrimFilterWriter.textarea[readCharMatchCount]
					|| c==TrimFilterWriter.TEXTAREA[readCharMatchCount]
				) {
					readCharMatchCount++;
					if(readCharMatchCount>=TrimFilterWriter.textarea.length) {
						inTextArea=true;
						readCharMatchCount=0;
					}
				} else {
					readCharMatchCount=0;
				}
				if(
					c==TrimFilterWriter.pre[preReadCharMatchCount]
					|| c==TrimFilterWriter.PRE[preReadCharMatchCount]
				) {
					preReadCharMatchCount++;
					if(preReadCharMatchCount>=TrimFilterWriter.pre.length) {
						inPre=true;
						preReadCharMatchCount=0;
					}
				} else {
					preReadCharMatchCount=0;
				}
				return true;
			}
		}
	}
616476
public static List<StartEndPair> scan(String input, String splitStart,
			String splitEnd, boolean useEscaping) {
		List<StartEndPair> result = new ArrayList<StartEndPair>();
		int fromIndex = 0;
		while (true) {
			int exprStart = input.indexOf(splitStart, fromIndex);
			if (exprStart == -1) {
				break;
			}
			if (useEscaping && Util.isEscaped(input, exprStart)) {
				fromIndex = exprStart + splitStart.length();
				continue;
			}

			exprStart += splitStart.length();
			int exprEnd = input.indexOf(splitEnd, exprStart);
			if (exprEnd == -1) {
				break;
			}
			while (useEscaping && Util.isEscaped(input, exprEnd)) {
				exprEnd = input.indexOf(splitEnd, exprEnd + splitEnd.length());
			}

			fromIndex = exprEnd + splitEnd.length();

			StartEndPair startEndPair = new StartEndPair(exprStart, exprEnd);
			result.add(startEndPair);
		}
		return result;
	}
1000197
private Choice parseChoice(CharSequenceScanner scanner) {

    Filter<Object> condition = parseCondition(scanner);
    List<Segment> segments = new ArrayList<>();
    while (scanner.hasNext()) {
      int index = scanner.getCurrentIndex();
      char c = scanner.peek();
      String literal = null;
      if ((c == '"') || (c == '\'')) {
        scanner.next();
        literal = scanner.readUntil(c, false, c);
        if (literal == null) {
          throw new IllegalArgumentException(scanner.substring(index, scanner.getCurrentIndex()));
        }
        c = scanner.peek();
      }
      NlsArgument argument = null;
      if (c == NlsArgumentParser.START_EXPRESSION) {
        scanner.next();
        argument = this.nlsDependencies.getArgumentParser().parse(scanner);
      }
      if ((argument != null) || (literal != null)) {
        segments.add(new Segment(literal, argument));
      } else {
        break;
      }
    }
    return new Choice(condition, segments);
  }
1329124
@Requires("nextToken == null")
  @Ensures("result == (nextToken != null)")
  protected boolean lex() throws IOException {
    int startOffset = currentOffset;
    StringBuilder buffer = new StringBuilder();
    int c = readChar(true);
    if (c == -1) {
      return false;
    }
    buffer.append((char) c);
    switch (c) {
      case '/':
        /* Comments. */
        c = readChar(true);
        switch (c) {
          case '/':
            buffer.append((char) c);
            do {
              c = readChar(false);
              buffer.append((char) c);
            } while (c != '\n');
            nextToken = new Token(TokenKind.COMMENT, buffer.toString(),
                                  startOffset);
            break;
          case '*':
            buffer.append((char) c);
            for (;;) {
              c = readChar(false);
              buffer.append((char) c);
              if (c == '*') {
                c = readChar(false);
                buffer.append((char) c);
                if (c == '/') {
                  break;
                }
              }
            }
            nextToken = new Token(TokenKind.COMMENT, buffer.toString(),
                                  startOffset);
            break;
          default:
            unreadChar(c);
            nextToken = new Token(TokenKind.SYMBOL, buffer.toString(),
                                  startOffset);
        }
        break;

      case '\'':
      case '"':
        /* Quoted strings. */
        int delim = c;
        for (;;) {
          c = readChar(false);
          buffer.append((char) c);
          if (c == delim) {
            break;
          }
          if (c == '\\') {
            buffer.append((char) readChar(false));
          }
        }
        nextToken = new Token(TokenKind.QUOTE, buffer.toString(), startOffset);
        break;

      default:
        if (Character.isJavaIdentifierStart(c)) {
          /* Identifiers. */
          while ((c = readChar(true)) != -1
                 && Character.isJavaIdentifierPart(c)) {
            buffer.append((char) c);
          }
          unreadChar(c);
          nextToken = new Token(TokenKind.WORD, buffer.toString(), startOffset);
        } else if (Character.isWhitespace(c)) {
          /* White space. */
          while ((c = readChar(true)) != -1 && Character.isWhitespace(c)) {
            buffer.append((char) c);
          }
          unreadChar(c);
          nextToken = new Token(TokenKind.SPACE, buffer.toString(),
                                startOffset);
        } else {
          /* Symbol. */
          nextToken = new Token(TokenKind.SYMBOL, buffer.toString(),
                                startOffset);
        }
    }
    return true;
  }
3221
protected void consumeChar(ImapRequestLineReader request, char expected)
            throws ProtocolException {
        char consumed = request.consume();
        if (consumed != expected) {
            throw new ProtocolException("Expected:'" + expected + "' found:'" + consumed + '\'');
        }
    }
957178
private Token consumeString(char quote) {
    StringBuilder sb = new StringBuilder();
    int l = line;
    int c = column;
    Token T;
    nextChar();
    while(moreChars() && ch != quote) {
      if(ch == '\\') {
        nextChar();
        switch(ch) {
          case '"':
          case '\\':
          case '/':
            sb.append(ch);
            nextChar();
            break;
          case 'b':
            sb.append('\b');
            nextChar();
            break;
          case 'f':
            sb.append('\f');
            nextChar();
            break;
          case 'n':
            sb.append('\n');
            nextChar();
            break;
          case 'r':
            sb.append('\r');
            nextChar();
            break;
          case 't':
            sb.append('\t');
            nextChar();
            break;
          case 'u':
            nextChar();
            int u = 0;
            for(int i = 0; i < 4; i++) {
              if(isHexDigit(ch)) {
                u = u * 16 + ch - '0';
                if(ch >= 'A') { // handle hex numbers: 'A' = 65, '0' = 48. 'A'-'0' = 17, 17 - 7 = 10
                  u = u - 7;
                }
              } else {
                T = new Token(TokenType.ERROR, sb.toString(), line, column);
                nextChar();
                return T;
              }
              nextChar();
            }
            sb.append((char) u);
            break;
          default:
            T = new Token(TokenType.ERROR, sb.toString(), line, column);
            nextChar();
            return T;
        }
      } else {
        sb.append(ch);
        nextChar();
      }
    }
    if(ch == quote) {
      T = new Token(TokenType.STRING, sb.toString(), l, c);
    } else {
      T = new Token(TokenType.ERROR, sb.toString(), line, column);
    }
    nextChar();
    return T;
  }
610722
@Override
	public boolean startsWithCurrentPrefix(final String key) {
		lock.readLock().lock();
		try {
			if (getPrefix() != null && key != null) {
				return key.startsWith(getPrefix() + getPrefixDelimiter());
			}
		} finally {
			lock.readLock().unlock();
		}
		return false;
	}
292089
public Token scanCharacterLiteral() {
		int start = pos;
		pos++;
		char c = input.charAt(pos++);
		if (c == '\\') {
			// escape code
			switch (input.charAt(pos++)) {
			case 'b':
				c = '\b';
				break;
			case 't':
				c = '\t';
				break;
			case 'n':
				c = '\n';
				break;
			case 'f':
				c = '\f';
				break;
			case 'r':
				c = '\r';
				break;
			case '"':
				c = '\"';
				break;
			case '\'':
				c = '\'';
				break;
			case '\\':
				c = '\\';
				break;
			default:
				syntaxError("unrecognised escape character", pos);
			}
		}
		if (input.charAt(pos) != '\'') {
			syntaxError("unexpected end-of-character", pos);
		}
		pos = pos + 1;
		return new Token(Token.Kind.CharLiteral, input.substring(start, pos),
				start);
	}
1130044
public boolean startsWith(Text pattern) {
    	if (pattern == null) {
    		return false;
    	}
    	return this.subSequence(0, pattern.len).equals(pattern);
    }
1254384
@Override
  public boolean ready () throws IOException
  {
    _ensureOpen ();

    /*
     * If newline needs to be skipped and the next char to be read is a newline
     * character, then just skip it right away.
     */
    if (m_bSkipLF)
    {
      /*
       * Note that in.ready() will return true if and only if the next read on
       * the stream will not block.
       */
      if (m_nNextCharIndex >= m_nChars && m_aReader.ready ())
        _fill ();
      if (m_nNextCharIndex < m_nChars)
      {
        if (m_aBuf[m_nNextCharIndex] == '\n')
          m_nNextCharIndex++;
        m_bSkipLF = false;
      }
    }
    return m_nNextCharIndex < m_nChars || m_aReader.ready ();
  }