<commit_before>/*******************************************************************************
 * Copyright (c) 2007, 2009 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.wikitext.core.parser.markup.token;

import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;

/**
 * A token that detects hyperlinks in the markup and emits them as a link. hyperlinks must use the HTTP or HTTPS
 * protocols to be detected.
 * 
 * Url detection is based on RFC 3986.
 * 
 * @author <NAME>
 * @since 1.0
 */
public class ImpliedHyperlinkReplacementToken extends PatternBasedElement {

	@Override
	protected String getPattern(int groupOffset) {
		// based on RFC 3986
		// even though it's valid we don't want to detect URLs that end with '.', ',', ';', ':' or ')'
		return "(https?://[a-zA-Z0-9%._~!$&?#'()*+,;:@/=-]*[a-zA-Z0-9_~!$&?#'(*+@/=-])"; //$NON-NLS-1$
	}

	@Override
	protected int getPatternGroupCount() {
		return 1;
	}

	@Override
	protected PatternBasedElementProcessor newProcessor() {
		return new HyperlinkReplacementTokenProcessor();
	}

	private static class HyperlinkReplacementTokenProcessor extends PatternBasedElementProcessor {
		@Override
		public void emit() {
			String target = group(1);
			getBuilder().link(target, target);
		}
	}
}<commit_msg>change visibility to public for testing purposes<commit_after>/*******************************************************************************
 * Copyright (c) 2007, 2009 <NAME> and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylyn.wikitext.core.parser.markup.token;

import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;

/**
 * A token that detects hyperlinks in the markup and emits them as a link. hyperlinks must use the HTTP or HTTPS
 * protocols to be detected.
 * 
 * Url detection is based on RFC 3986.
 * 
 * @author <NAME>
 * @since 1.0
 */
public class ImpliedHyperlinkReplacementToken extends PatternBasedElement {

	@Override
	public String getPattern(int groupOffset) {
		// based on RFC 3986
		// even though it's valid we don't want to detect URLs that end with '.', ',', ';', ':' or ')'
		return "(https?://[a-zA-Z0-9%._~!$&?#'()*+,;:@/=-]*[a-zA-Z0-9_~!$&?#'(*+@/=-])"; //$NON-NLS-1$
	}

	@Override
	public int getPatternGroupCount() {
		return 1;
	}

	@Override
	protected PatternBasedElementProcessor newProcessor() {
		return new HyperlinkReplacementTokenProcessor();
	}

	private static class HyperlinkReplacementTokenProcessor extends PatternBasedElementProcessor {
		@Override
		public void emit() {
			String target = group(1);
			getBuilder().link(target, target);
		}
	}
}
{'fraction_non_alphanumeric': 0.20379281064251345, 'fraction_numerical': 0.016416643079535807, 'mean_word_length': 4.6544, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6446292', 'n_tokens_mistral': 1113, 'n_tokens_neox': 993, 'n_words': 296}