<commit_before>package ezvcard.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.regex.Pattern;

import ezvcard.util.VCardStringUtils;

/*
 Copyright (c) 2012, <NAME>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met: 

 1. Redistributions of source code must retain the above copyright notice, this
 list of conditions and the following disclaimer. 
 2. Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution. 

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 The views and conclusions contained in the software and documentation are those
 of the authors and should not be interpreted as representing official policies, 
 either expressed or implied, of the FreeBSD Project.
 */

/**
 * Automatically unfolds lines of text as they are read.
 * @author <NAME>
 */
public class FoldedLineReader extends BufferedReader {
	/**
	 * Regular expression used for the incorrectly folded lines that Outlook can
	 * generate.
	 */
	private static final Pattern outlookQuirk = Pattern.compile("[^:]*?QUOTED-PRINTABLE.*?:.*?=", Pattern.CASE_INSENSITIVE);

	private String lastLine;

	/**
	 * @param reader the reader object to wrap
	 */
	public FoldedLineReader(Reader reader) {
		super(reader);
	}

	/**
	 * @param text the text to read
	 */
	public FoldedLineReader(String text) {
		this(new StringReader(text));
	}

	/**
	 * Reads the next non-empty line. Empty lines must be ignored because some
	 * vCards (i.e. iPhone) contain empty lines. These empty lines appear in
	 * between folded lines, which, if not ignored, will cause the parser to
	 * incorrectly parse the vCard.
	 * @return the next non-empty line or null of EOF
	 * @throws IOException
	 */
	private String readNonEmptyLine() throws IOException {
		String line;
		do {
			line = super.readLine();
		} while (line != null && line.length() == 0);
		return line;
	}

	/**
	 * Reads the next line, unfolding it if necessary.
	 * @return the next line or null if EOF
	 * @throws IOException if there's a problem reading from the reader
	 */
	@Override
	public String readLine() throws IOException {
		String wholeLine = (lastLine == null) ? readNonEmptyLine() : lastLine;
		lastLine = null;
		if (wholeLine == null) {
			return null;
		}

		//Outlook incorrectly folds lines that are QUOTED-PRINTABLE.
		//It does not prepend each additional line with whitespace
		//For example:
		//
		//NOTE;QUOTED-PRINTABLE: This is my=0D=0A=
		//badly formatted=0D=0A=
		//note
		boolean outlookCraziness = false;
		if (outlookQuirk.matcher(wholeLine).matches()) {
			outlookCraziness = true;
			wholeLine = wholeLine.substring(0, wholeLine.length() - 1); //chop off the ending "="
		}

		//long lines are folded
		while (true) {
			String line = readNonEmptyLine();
			if (line == null) {
				break;
			} else if (outlookCraziness) {
				line = VCardStringUtils.ltrim(line);

				boolean endsInEquals = line.endsWith("=");
				if (endsInEquals) {
					line = line.substring(0, line.length() - 1);
				}

				wholeLine += line;

				if (!endsInEquals) {
					break;
				}
			} else if (line.length() > 0 && Character.isWhitespace(line.charAt(0))) {
				//the line was folded

				int lastWhitespace = 1;
				//Evolution will include real whitespace chars alongside the folding char
				while (lastWhitespace < line.length() && Character.isWhitespace(line.charAt(lastWhitespace))) {
					lastWhitespace++;
				}
				wholeLine += line.substring(lastWhitespace);
			} else {
				lastLine = line;
				break;
			}
		}
		return wholeLine;
	}
}<commit_msg>Replaced string concatination with StringBuilder.<commit_after>package ezvcard.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.regex.Pattern;

import ezvcard.util.VCardStringUtils;

/*
 Copyright (c) 2012, <NAME>
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met: 

 1. Redistributions of source code must retain the above copyright notice, this
 list of conditions and the following disclaimer. 
 2. Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution. 

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 The views and conclusions contained in the software and documentation are those
 of the authors and should not be interpreted as representing official policies, 
 either expressed or implied, of the FreeBSD Project.
 */

/**
 * Automatically unfolds lines of text as they are read.
 * @author <NAME>
 */
public class FoldedLineReader extends BufferedReader {
	/**
	 * Regular expression used for the incorrectly folded lines that Outlook can
	 * generate.
	 */
	private static final Pattern outlookQuirk = Pattern.compile("[^:]*?QUOTED-PRINTABLE.*?:.*?=", Pattern.CASE_INSENSITIVE);

	private String lastLine;

	/**
	 * @param reader the reader object to wrap
	 */
	public FoldedLineReader(Reader reader) {
		super(reader);
	}

	/**
	 * @param text the text to read
	 */
	public FoldedLineReader(String text) {
		this(new StringReader(text));
	}

	/**
	 * Reads the next non-empty line. Empty lines must be ignored because some
	 * vCards (i.e. iPhone) contain empty lines. These empty lines appear in
	 * between folded lines, which, if not ignored, will cause the parser to
	 * incorrectly parse the vCard.
	 * @return the next non-empty line or null of EOF
	 * @throws IOException
	 */
	private String readNonEmptyLine() throws IOException {
		String line;
		do {
			line = super.readLine();
		} while (line != null && line.length() == 0);
		return line;
	}

	/**
	 * Reads the next line, unfolding it if necessary.
	 * @return the next line or null if EOF
	 * @throws IOException if there's a problem reading from the reader
	 */
	@Override
	public String readLine() throws IOException {
		String wholeLine = (lastLine == null) ? readNonEmptyLine() : lastLine;
		lastLine = null;
		if (wholeLine == null) {
			return null;
		}

		//Outlook incorrectly folds lines that are QUOTED-PRINTABLE.
		//It does not prepend each additional line with whitespace
		//For example:
		//
		//NOTE;QUOTED-PRINTABLE: This is my=0D=0A=
		//badly formatted=0D=0A=
		//note
		boolean outlookCraziness = false;
		if (outlookQuirk.matcher(wholeLine).matches()) {
			outlookCraziness = true;
			wholeLine = wholeLine.substring(0, wholeLine.length() - 1); //chop off the ending "="
		}

		//long lines are folded
		StringBuilder wholeLineSb = new StringBuilder(wholeLine);
		while (true) {
			String line = readNonEmptyLine();
			if (line == null) {
				break;
			} else if (outlookCraziness) {
				line = VCardStringUtils.ltrim(line);

				boolean endsInEquals = line.endsWith("=");
				if (endsInEquals) {
					line = line.substring(0, line.length() - 1);
				}

				wholeLineSb.append(line);

				if (!endsInEquals) {
					break;
				}
			} else if (line.length() > 0 && Character.isWhitespace(line.charAt(0))) {
				//the line was folded

				int lastWhitespace = 1;
				//Evolution will include real whitespace chars alongside the folding char
				while (lastWhitespace < line.length() && Character.isWhitespace(line.charAt(lastWhitespace))) {
					lastWhitespace++;
				}
				wholeLineSb.append(line.substring(lastWhitespace));
			} else {
				lastLine = line;
				break;
			}
		}
		return wholeLineSb.toString();
	}
}
{'fraction_non_alphanumeric': 0.08786927821664323, 'fraction_numerical': 0.003895682285466941, 'mean_word_length': 3.7737603305785123, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5822862', 'n_tokens_mistral': 2978, 'n_tokens_neox': 2519, 'n_words': 1040}