Stdlib: Removed all references to String constructors in nit stdlib and tests.
[nit.git] / lib / standard / environ.nit
index d8ab867..fb83040 100644 (file)
 # You  are  allowed  to  redistribute it and sell it, alone or is a part of
 # another product.
 
-import symbol
+# 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 Symbol
-       # Return environement valued for this symbol
-       meth environ: String
+redef class String
+       # Return environment value for this symbol
+       # If there is no such environment value, then return ""
+       fun environ: String
        do
-               environ_default = "" # FIXME: Why this ?!?
-               return new String.from_cstring(to_s.to_cstring.get_environ)
+               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 environement value for this symbol
-       meth environ=(v: String) do to_s.to_cstring.set_environ(v.to_cstring, 1)
-       
-       # set default environement value for this symbol
-       meth environ_default=(v: String) do to_s.to_cstring.set_environ(v.to_cstring, 0)
-               
-       # Unset the environement value of this symbol
-       meth unset do to_s.to_cstring.unset_environ
+       fun setenv( v : String ) do to_cstring.setenv( v.to_cstring )
 end
 
 redef class NativeString
-# Refinned to add environement bindings
-       private meth get_environ: NativeString is extern "string_NativeString_NativeString_get_environ_0"
-       private meth put_environ is extern "string_NativeString_NativeString_put_environ_0" # this one is a bit compilcated to use ... so we dosen't use
-       private meth unset_environ is extern "string_NativeString_NativeString_unset_environ_0"
-       private meth set_environ(value : NativeString, overwrite : Int) is extern "string_NativeString_NativeString_set_environ_2"
+       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