www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can D perform tilde expansion in paths?

reply Grzegorz Adam Hankiewicz <gradhanews ya.com> writes:
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?
Dec 28 2005
parent reply "Walter Bright" <newshound digitalmars.com> writes:
"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?
Dec 28 2005
next sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFDtCG93w+/yD4P9tIRAkiiAJkBRwHItL3Mx5oudh5HOlNuO7BuxgCfZLsd I4jgKqsgF1p6aaRfUCp1TZs= =gGiE -----END PGP SIGNATURE-----
Dec 29 2005
prev sibling parent reply Grzegorz Adam Hankiewicz <gradhanews ya.com> writes:
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.
Dec 29 2005
parent reply "Walter Bright" <newshound digitalmars.com> writes:
"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.
Jan 01 2006
parent reply Grzegorz Adam Hankiewicz <gradhanews ya.com> writes:
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?
Jan 02 2006
parent "Walter Bright" <newshound digitalmars.com> writes:
"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.
Jan 03 2006