@@ -393,7 +393,7 @@ private static ImmutableList<Token> optionalizeSpacesAfterLinks(List<Token> inpu
393393 ImmutableList .Builder <Token > output = ImmutableList .builder ();
394394
395395 for (PeekingIterator <Token > tokens = peekingIterator (input .iterator ()); tokens .hasNext (); ) {
396- if (tokens .peek ().getType () == LITERAL && tokens .peek ().getValue ().matches ("^ href=[^>]*>" )) {
396+ if (tokens .peek ().getType () == LITERAL && tokens .peek ().getValue ().matches ("href=[^>]*>" )) {
397397 output .add (tokens .next ());
398398
399399 if (tokens .peek ().getType () == WHITESPACE ) {
@@ -519,18 +519,18 @@ private static boolean hasMultipleNewlines(String s) {
519519 * We'd remove the trailing whitespace later on (in JavaCommentsHelper.rewrite), but I feel safer
520520 * stripping it now: It otherwise might confuse our line-length count, which we use for wrapping.
521521 */
522- private static final Pattern NEWLINE_PATTERN = compile ("^ [ \t ]*\n [ \t ]*[*]?[ \t ]?" );
522+ private static final Pattern NEWLINE_PATTERN = compile ("[ \t ]*\n [ \t ]*[*]?[ \t ]?" );
523523
524524 // We ensure elsewhere that we match this only at the beginning of a line.
525525 // Only match tags that start with a lowercase letter, to avoid false matches on unescaped
526526 // annotations inside code blocks.
527527 // Match "@param <T>" specially in case the <T> is a <P> or other HTML tag we treat specially.
528- private static final Pattern FOOTER_TAG_PATTERN = compile ("^ @(param\\ s+<\\ w+>|[a-z]\\ w*)" );
528+ private static final Pattern FOOTER_TAG_PATTERN = compile ("@(param\\ s+<\\ w+>|[a-z]\\ w*)" );
529529 private static final Pattern MOE_BEGIN_STRIP_COMMENT_PATTERN =
530- compile ("^ <!--\\ s*M" + "OE:begin_intracomment_strip\\ s*-->" );
530+ compile ("<!--\\ s*M" + "OE:begin_intracomment_strip\\ s*-->" );
531531 private static final Pattern MOE_END_STRIP_COMMENT_PATTERN =
532- compile ("^ <!--\\ s*M" + "OE:end_intracomment_strip\\ s*-->" );
533- private static final Pattern HTML_COMMENT_PATTERN = fullCommentPattern ( );
532+ compile ("<!--\\ s*M" + "OE:end_intracomment_strip\\ s*-->" );
533+ private static final Pattern HTML_COMMENT_PATTERN = compile ( "<!--.*?-->" , DOTALL );
534534 private static final Pattern PRE_OPEN_PATTERN = openTagPattern ("pre" );
535535 private static final Pattern PRE_CLOSE_PATTERN = closeTagPattern ("pre" );
536536 private static final Pattern CODE_OPEN_PATTERN = openTagPattern ("code" );
@@ -548,8 +548,8 @@ private static boolean hasMultipleNewlines(String s) {
548548 private static final Pattern BLOCKQUOTE_OPEN_PATTERN = openTagPattern ("blockquote" );
549549 private static final Pattern BLOCKQUOTE_CLOSE_PATTERN = closeTagPattern ("blockquote" );
550550 private static final Pattern BR_PATTERN = openTagPattern ("br" );
551- private static final Pattern SNIPPET_TAG_OPEN_PATTERN = compile ("^ [{]@snippet\\ b" );
552- private static final Pattern INLINE_TAG_OPEN_PATTERN = compile ("^ [{]@\\ w*" );
551+ private static final Pattern SNIPPET_TAG_OPEN_PATTERN = compile ("[{]@snippet\\ b" );
552+ private static final Pattern INLINE_TAG_OPEN_PATTERN = compile ("[{]@\\ w*" );
553553 /*
554554 * We exclude < so that we don't swallow following HTML tags. This lets us fix up "foo<p>" (~400
555555 * hits in Google-internal code). We will join unnecessarily split "words" (like "foo<b>bar</b>")
@@ -560,18 +560,14 @@ private static boolean hasMultipleNewlines(String s) {
560560 * with matching only one character here. That would eliminate the need for the regex entirely.
561561 * That might be faster or slower than what we do now.
562562 */
563- private static final Pattern LITERAL_PATTERN = compile ("^.[^ \t \n @<{}*]*" , DOTALL );
564-
565- private static Pattern fullCommentPattern () {
566- return compile ("^<!--.*?-->" , DOTALL );
567- }
563+ private static final Pattern LITERAL_PATTERN = compile (".[^ \t \n @<{}*]*" , DOTALL );
568564
569565 private static Pattern openTagPattern (String namePattern ) {
570- return compile (format ("^ <(?:%s)\\ b[^>]*>" , namePattern ), CASE_INSENSITIVE );
566+ return compile (format ("<(?:%s)\\ b[^>]*>" , namePattern ), CASE_INSENSITIVE );
571567 }
572568
573569 private static Pattern closeTagPattern (String namePattern ) {
574- return compile (format ("^ </(?:%s)\\ b[^>]*>" , namePattern ), CASE_INSENSITIVE );
570+ return compile (format ("</(?:%s)\\ b[^>]*>" , namePattern ), CASE_INSENSITIVE );
575571 }
576572
577573 static class LexException extends Exception {}
0 commit comments