How to avoid code duplication?

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 31 22:15:58 PDT 2015


The situation is next:

I have got the function that get arrays of lognames and 
logfullname:

void loginsert(string [] lognames, string [] logfullname)
{
	if(logfullname[i].endsWith("txt"))
	{
		auto file = File(logfullname[i], "r");
		foreach (line; file.byLine)
		{
			// long manupulation with strings
		}
	}

}

But now need add supporting passing to function not only txt 
files, but also zip archives.
The problem that now I see only one way to do adding zip -- add 
block: if(logfullname[i].endsWith("zip"))
And in it do everything with unpacking content of archive like:

	foreach(ArchiveMember am; zip.directory)
	{
		string file = cast(string)zip.expand(am);
		foreach (line; file.lineSplitter())
			{
				
			}
	}
	
and put inside it some same content that I am doing in "long 
manupulation with strings".


Maybe there is any better way? But I really can't understand it 
because auto file = File(logfullname[i], "r"); can't read 
unpacked content of archive.


More information about the Digitalmars-d-learn mailing list