<commit_before># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2006 <NAME> <<EMAIL>>
# Copyright 2008 <NAME> <<EMAIL>>
#
# This file is free software, which comes along with NIT.  This software 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.  You can modify it is you want,  provided this header
# is kept unaltered, and a notification of the changes is added.
# You  are  allowed  to  redistribute it and sell it, alone or is a part of
# another product.

# Access to the environment variables of the process
module environ

import string

# TODO prevoir une structure pour recup tout un environ, le modifier et le passer a process

redef class String
	# Return environment value for this symbol
	# If there is no such environment value, then return ""
	fun environ: String
	do
		var res = self.to_cstring.get_environ
		# FIXME: There is no proper way to handle NULL C string yet. What a pitty.
		var nulstr = once ("".to_cstring.get_environ)
		if res != nulstr then
			return res.to_s
		else
			return ""
		end
	end
	fun setenv( v : String ) do to_cstring.setenv( v.to_cstring )
end

redef class NativeString
	private fun get_environ: NativeString is extern "string_NativeString_NativeString_get_environ_0"
	private fun setenv( v : NativeString ) is extern "string_NativeString_NativeString_setenv_1"
end<commit_msg>lib/environ: more documentation and nitunit tests<commit_after># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2006 <NAME> <<EMAIL>>
# Copyright 2008 <NAME> <<EMAIL>.org>
#
# This file is free software, which comes along with NIT.  This software 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.  You can modify it is you want,  provided this header
# is kept unaltered, and a notification of the changes is added.
# You  are  allowed  to  redistribute it and sell it, alone or is a part of
# another product.

# Access to the environment variables of the process
module environ

import string

# TODO prevoir une structure pour recup tout un environ, le modifier et le passer a process

redef class String
	# Return environment value for the symbol.
	# If there is no such environment variable, then return ""
	#
	#     assert "PATH".environ     != ""
	#     assert "NIT %\n".environ  == ""
	fun environ: String
	do
		var res = self.to_cstring.get_environ
		# FIXME: There is no proper way to handle NULL C string yet. What a pitty.
		var nulstr = once ("".to_cstring.get_environ)
		if res != nulstr then
			return res.to_s
		else
			return ""
		end
	end

	# Set the enviroment value of a variable.
	#
	#     "NITis".setenv("fun")
	#     assert "NITis".environ  == "fun"
	fun setenv(v: String) do to_cstring.setenv( v.to_cstring )
end

redef class NativeString
	private fun get_environ: NativeString is extern "string_NativeString_NativeString_get_environ_0"
	private fun setenv( v : NativeString ) is extern "string_NativeString_NativeString_setenv_1"
end
{'fraction_non_alphanumeric': 0.06848884699968583, 'fraction_numerical': 0.006283380458686773, 'mean_word_length': 3.8984615384615386, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7427047', 'n_tokens_mistral': 981, 'n_tokens_neox': 968, 'n_words': 423}