Thread overview
Can D perform tilde expansion in paths?
Dec 29, 2005
Walter Bright
Dec 29, 2005
Thomas Kuehne
Jan 02, 2006
Walter Bright
Jan 04, 2006
Walter Bright
December 28, 2005
I'm trying to replicate the following python code under D:

	In [1]: import os
	In [2]: os.path.expanduser("~/test")
	Out[2]: '/home/gradha/test'

I searched phobos' std.conv, std.file, std.path, std.string and std.system, but haven't found anything useful there (unless I missed it) related to tilde expansion. How would I do the above in D?
December 29, 2005
"Grzegorz Adam Hankiewicz" <gradhanews@ya.com> wrote in message news:pan.2005.12.28.20.46.18.638574@ya.com...
> I'm trying to replicate the following python code under D:
>
> In [1]: import os
> In [2]: os.path.expanduser("~/test")
> Out[2]: '/home/gradha/test'
>
> I searched phobos' std.conv, std.file, std.path, std.string and std.system, but haven't found anything useful there (unless I missed it) related to tilde expansion. How would I do the above in D?

At the moment, it isn't supported in std.path, though it should be. Would you care to write it?


December 29, 2005
Walter Bright schrieb am 2005-12-29:
>
> "Grzegorz Adam Hankiewicz" <gradhanews@ya.com> wrote in message news:pan.2005.12.28.20.46.18.638574@ya.com...
>> I'm trying to replicate the following python code under D:
>>
>> In [1]: import os
>> In [2]: os.path.expanduser("~/test")
>> Out[2]: '/home/gradha/test'
>>
>> I searched phobos' std.conv, std.file, std.path, std.string and std.system, but haven't found anything useful there (unless I missed it) related to tilde expansion. How would I do the above in D?
>
> At the moment, it isn't supported in std.path, though it should be. Would you care to write it?

code for the Linux/BSD version below:

License: public domain

# private import std.path;
# private import std.c.stdlib;
#
# public char[] expandTilde(char[] path){
# 	static assert(std.path.sep.length == 1);
#
# 	if(path.length>0 && path[0]=='~' && (path.length==1 || path[1] == std.path.sep[0])){
# 		char* home = getenv("HOME");
# 		if(home != null){
# 			int end = 0;
# 			while(home[end] != '\u0000'){
# 				end++;
# 			}
#
# 			if(home[end-1] == std.path.sep[0]){
# 				return home[0 .. end-1] ~ path[1 .. $];
# 			}else{
# 				return home[0 .. end] ~ path[1 .. $];
# 			}
# 		}
# 	}
# 	return path;
# }

Thomas


December 29, 2005
El Wed, 28 Dec 2005 17:30:16 -0800, Walter Bright escribió:
>> In [1]: import os
>> In [2]: os.path.expanduser("~/test")
>> Out[2]: '/home/gradha/test'
>>
>> [...] How would I do the above in D?
> 
> At the moment, it isn't supported in std.path, though it should be. Would you care to write it?

I don't see on the web page any instructions/guidelines with regards to contributing code.  Do you have a public repository with source code or should I make patches against the sources I got with the dmd compiler?

From license.txt:

 If you send any messages to Digital Mars, on either the Digital Mars
 newsgroups, the Digital Mars mailing list, or via email, you agree not
 to make any claims of intellectual
 property rights over the contents of those messages.

So, by posting a diff on this newsgroup implementing the feature
would I have assigned copyright to you at the very moment
allowing you to do what you want with it, or is something else
required? What does the license mean by intellectual property rights
(see http://www.gnu.org/philosophy/not-ipr.xhtml)? I guess copyright.

What's up with those unittest blocks in the source (I presume I would add code to src/phobos/std/path.d)? I've gone again through the documentation and couldn't find much info about them.

January 02, 2006
"Grzegorz Adam Hankiewicz" <gradhanews@ya.com> wrote in message news:pan.2005.12.29.17.32.02.228378@ya.com...
> I don't see on the web page any instructions/guidelines with regards to contributing code.

This should help: www.digitalmars.com/d/contributions.html

> What's up with those unittest blocks in the source (I presume I would add code to src/phobos/std/path.d)? I've gone again through the documentation and couldn't find much info about them.

They contain the test code for the function.


January 02, 2006
El Sun, 01 Jan 2006 19:42:08 -0800, Walter Bright escribió:
>> I don't see on the web page any instructions/guidelines with regards to contributing code.
> 
> This should help: www.digitalmars.com/d/contributions.html

So there's no public repository? You are the only one in charge of the code? I send whole files when I want to make a few changes here and there?  To this newsgroup? To you personally?

January 04, 2006
"Grzegorz Adam Hankiewicz" <gradhanews@ya.com> wrote in message news:pan.2006.01.02.19.34.52.727423@ya.com...
> El Sun, 01 Jan 2006 19:42:08 -0800, Walter Bright escribió:
>>> I don't see on the web page any instructions/guidelines with regards to contributing code.
>>
>> This should help: www.digitalmars.com/d/contributions.html
>
> So there's no public repository? You are the only one in charge of the code? I send whole files when I want to make a few changes here and there?  To this newsgroup? To you personally?

You can post diffs here, or email them to me.