<commit_before>/***************************************************************************
 *   Copyright (C) by <NAME> <<EMAIL>>               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   For details about the authors of this software, see the AUTHORS file. *
 ***************************************************************************/

package joliex.util;


import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jolie.runtime.JavaService;
import jolie.runtime.Value;
import jolie.runtime.ValuePrettyPrinter;
import jolie.runtime.ValueVector;

public class StringUtils extends JavaService
{
	public Integer length( String request )
	{
		return request.length();
	}
	
	public Value sort( Value request )
	{
		String[] list = new String[ request.getChildren( "item" ).size() ];
		int i = 0;
		for( Value v : request.getChildren( "item" ) ) {
			list[ i++ ] = v.strValue();
		}
		Arrays.sort( list );
		Value ret = Value.create();
		ValueVector items = ret.getChildren( "item" );
		for( String s : list ) {
			items.add( Value.create( s ) );
		}
		return ret;
	}

	public static class ReplaceAllRequest implements ValueConverter
	{
		private String self, regex, replacement;
		private ReplaceAllRequest() {}
		public static ReplaceAllRequest fromValue( Value value )
		{
			ReplaceAllRequest ret = new ReplaceAllRequest();
			ret.self = value.strValue();
			ret.regex = value.getFirstChild( "regex" ).strValue();
			ret.replacement = value.getFirstChild( "replacement" ).strValue();
			return ret;
		}
		public static Value toValue( ReplaceAllRequest p )
		{
			Value ret = Value.create();
			ret.setValue( p.self );
			ret.getFirstChild( "regex" ).setValue( p.regex );
			ret.getFirstChild( "replacement" ).setValue( p.replacement );
			return ret;
		}
	}

	public String replaceAll( ReplaceAllRequest request )
	{
		return request.self.replaceAll( request.regex, request.replacement );
	}
	
	public static class StartsWithRequest implements ValueConverter
	{
		private String self, prefix;
		private StartsWithRequest() {}
		public static StartsWithRequest fromValue( Value value )
		{
			StartsWithRequest ret = new StartsWithRequest();
			ret.self = value.strValue();
			ret.prefix = value.getFirstChild( "prefix" ).strValue();
			return ret;
		}
		public static Value toValue( StartsWithRequest p )
		{
			Value ret = Value.create();
			ret.setValue( p.self );
			ret.getFirstChild( "prefix" ).setValue( p.prefix );
			return ret;
		}
	}

	public Boolean startsWith( StartsWithRequest request )
	{
		return request.self.startsWith( request.prefix );
	}

	public static class JoinRequest implements ValueConverter
	{
		private String delimiter;
		private ValueVector pieces;
		private JoinRequest() {}
		public static JoinRequest fromValue( Value value )
		{
			JoinRequest ret = new JoinRequest();
			ret.delimiter = value.getFirstChild( "delimiter" ).strValue();
			ret.pieces = value.getChildren( "piece" );
			return ret;
		}
		public static Value toValue( JoinRequest p )
		{
			Value ret = Value.create();
			ret.getFirstChild( "delimiter" ).setValue( p.delimiter );
			ret.children().put( "piece", p.pieces );
			return ret;
		}
	}

	public String join( JoinRequest request )
	{
		int size = request.pieces.size() - 1;
		StringBuilder builder = new StringBuilder();
		if ( size >= 0 ) {
			int i;
			for( i = 0; i < size; i++ ) {
				builder.append( request.pieces.get( i ).strValue() ).append( request.delimiter );
			}
			builder.append( request.pieces.get( i ).strValue() );
		}
		return builder.toString();
	}
	
	public String trim( String s )
	{
		return s.trim();
	}

	public String substring( Value request )
	{
		String subst = "";
		if ( request.strValue().length() < request.getFirstChild( "end" ).intValue() ) {
			subst = request.strValue().substring(
			request.getFirstChild( "begin" ).intValue(),
			request.strValue().length() );
		} else {
			subst = request.strValue().substring(
				request.getFirstChild( "begin" ).intValue(),
				request.getFirstChild( "end" ).intValue()
			);
		}
		return subst;
	}<commit_msg>Code cleaning.<commit_after>/***************************************************************************
 *   Copyright (C) by <NAME> <<EMAIL>>               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   For details about the authors of this software, see the AUTHORS file. *
 ***************************************************************************/

package joliex.util;


import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jolie.runtime.JavaService;
import jolie.runtime.Value;
import jolie.runtime.ValuePrettyPrinter;
import jolie.runtime.ValueVector;

public class StringUtils extends JavaService
{
	public Integer length( String request )
	{
		return request.length();
	}
	
	public Value sort( Value request )
	{
		String[] list = new String[ request.getChildren( "item" ).size() ];
		int i = 0;
		for( Value v : request.getChildren( "item" ) ) {
			list[ i++ ] = v.strValue();
		}
		Arrays.sort( list );
		Value ret = Value.create();
		ValueVector items = ret.getChildren( "item" );
		for( String s : list ) {
			items.add( Value.create( s ) );
		}
		return ret;
	}

	public static class ReplaceAllRequest implements ValueConverter
	{
		private String self, regex, replacement;
		private ReplaceAllRequest() {}
		public static ReplaceAllRequest fromValue( Value value )
		{
			ReplaceAllRequest ret = new ReplaceAllRequest();
			ret.self = value.strValue();
			ret.regex = value.getFirstChild( "regex" ).strValue();
			ret.replacement = value.getFirstChild( "replacement" ).strValue();
			return ret;
		}
		public static Value toValue( ReplaceAllRequest p )
		{
			Value ret = Value.create();
			ret.setValue( p.self );
			ret.getFirstChild( "regex" ).setValue( p.regex );
			ret.getFirstChild( "replacement" ).setValue( p.replacement );
			return ret;
		}
	}

	public String replaceAll( ReplaceAllRequest request )
	{
		return request.self.replaceAll( request.regex, request.replacement );
	}
	
	public static class StartsWithRequest implements ValueConverter
	{
		private String self, prefix;
		private StartsWithRequest() {}
		public static StartsWithRequest fromValue( Value value )
		{
			StartsWithRequest ret = new StartsWithRequest();
			ret.self = value.strValue();
			ret.prefix = value.getFirstChild( "prefix" ).strValue();
			return ret;
		}
		public static Value toValue( StartsWithRequest p )
		{
			Value ret = Value.create();
			ret.setValue( p.self );
			ret.getFirstChild( "prefix" ).setValue( p.prefix );
			return ret;
		}
	}

	public Boolean startsWith( StartsWithRequest request )
	{
		return request.self.startsWith( request.prefix );
	}

	public static class JoinRequest implements ValueConverter
	{
		private String delimiter;
		private ValueVector pieces;
		private JoinRequest() {}
		public static JoinRequest fromValue( Value value )
		{
			JoinRequest ret = new JoinRequest();
			ret.delimiter = value.getFirstChild( "delimiter" ).strValue();
			ret.pieces = value.getChildren( "piece" );
			return ret;
		}
		public static Value toValue( JoinRequest p )
		{
			Value ret = Value.create();
			ret.getFirstChild( "delimiter" ).setValue( p.delimiter );
			ret.children().put( "piece", p.pieces );
			return ret;
		}
	}

	public String join( JoinRequest request )
	{
		int size = request.pieces.size() - 1;
		StringBuilder builder = new StringBuilder();
		if ( size >= 0 ) {
			int i;
			for( i = 0; i < size; i++ ) {
				builder.append( request.pieces.get( i ).strValue() ).append( request.delimiter );
			}
			builder.append( request.pieces.get( i ).strValue() );
		}
		return builder.toString();
	}
	
	public String trim( String s )
	{
		return s.trim();
	}

	public String substring( Value request )
	{
		String subst;
		if ( request.strValue().length() < request.getFirstChild( "end" ).intValue() ) {
			subst = request.strValue().substring(
				request.getFirstChild( "begin" ).intValue(),
				request.strValue().length()
			);
		} else {
			subst = request.strValue().substring(
				request.getFirstChild( "begin" ).intValue(),
				request.getFirstChild( "end" ).intValue()
			);
		}
		return subst;
	}
{'fraction_non_alphanumeric': 0.1324009324009324, 'fraction_numerical': 0.003543123543123543, 'mean_word_length': 2.577718478985991, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4043072', 'n_tokens_mistral': 3259, 'n_tokens_neox': 2929, 'n_words': 903}