<commit_before>#------------------------------------------------------------------------------
package Tags2::Utils;
#------------------------------------------------------------------------------

# Pragmas.
use base qw(Exporter);
use strict;
use warnings;

# Modules.
use Readonly;

# Constants.
Readonly::Array our @EXPORT_OK => qw(encode_newline);

# Version.
our $VERSION = 0.01;

#------------------------------------------------------------------------------
sub encode_newline {
#------------------------------------------------------------------------------
# Encode newline in data to '\n' in output.

	my $string = shift;
	$string =~ s/\n/\\n/gms;
	return $string;
}

1;<commit_msg>Implement encode_base_entities() subroutine.<commit_after>#------------------------------------------------------------------------------
package Tags2::Utils;
#------------------------------------------------------------------------------

# Pragmas.
use base qw(Exporter);
use strict;
use warnings;

# Modules.
use Readonly;
use HTML::Entities;

# Constants.
Readonly::Array our @EXPORT_OK => qw(encode_newline encode_base_entities);

# Version.
our $VERSION = 0.01;

#------------------------------------------------------------------------------
sub encode_newline {
#------------------------------------------------------------------------------
# Encode newline in data to '\n' in output.

	my $string = shift;
	$string =~ s/\n/\\n/gms;
	return $string;
}

#------------------------------------------------------------------------------
sub encode_base_entities {
#------------------------------------------------------------------------------
# Encode '<>&' base entities.

	my $data = shift;
	if (ref $data eq 'SCALAR') {
		${$data} = encode_entities(${$data}, '<>&');
		return;
	} else {
		return encode_entities($data, '<>&');
	}
}

1;
{'fraction_non_alphanumeric': 0.5201305767138193, 'fraction_numerical': 0.00544069640914037, 'mean_word_length': 0.8632218844984803, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '1402108', 'n_tokens_mistral': 443, 'n_tokens_neox': 436, 'n_words': 105}