Parameter is null by default. No value is given. Code says it is not null.

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 9 05:50:42 PDT 2015


On Thursday, 9 April 2015 at 12:06:49 UTC, Daniel Kozák wrote:
>
> On Thu, 09 Apr 2015 11:45:30 +0000
> tcak via Digitalmars-d-learn 
> <digitalmars-d-learn at puremagic.com> wrote:
>
>
> Can you post full example somewhere, this code works ok for me:
>
> import std.stdio;
> import std.datetime;
>
> class Response
> {
>     public bool setCookie(
>             string name,
>             string value,
>             long maxAgeInSeconds = long.min,
>             string expiresOnGMTDate=null,
>             string path=null,
>             string domain=null,
>             bool secure=false
>     ) shared
>     {
>
>             // name cannot be empty
>             if( (name is null) || (name.length <= 0) ) return 
> false;
>
>             writeln(
>                     "Name: ", name,
>                     "  Max Age: ", maxAgeInSeconds,
>                     "  Expires null: ", (expiresOnGMTDate == 
> null),
>                     "  Path equals null: ", (path == null),
>                     "  Domain null: ", (domain is null)
>             );
>
>             return true;
>     }
> }
>
> void main()
> {
>     auto response = new shared Response();
>     response.setCookie( "A", "B" );
>     auto now = std.datetime.Clock.currTime().toSimpleString();
>     //writeln("Now |", now, "|");
>     response.setCookie( "Response Time", now );
> }

I have listed full code down below. It is written in test.d file 
and I run it with "rdmd test.d". Its result is as below for me:

tolga at tolga-H97M-D3H:~/Desktop$ rdmd test.d
Name: A 1  Expires null: true  Path equals null: true  Domain 
null: true
Name: A 2  Expires null: true  Path equals null: true  Domain 
null: false
Name: A 3  Expires null: true  Path equals null: true  Domain 
null: false
Name: A 4  Expires null: true  Path equals null: true  Domain 
null: false
Name: A 5  Expires null: true  Path equals null: true  Domain 
null: false
~~~~~~~~~
Name: A 6  Expires null: true  Path equals null: false  Domain 
null: false
Name: A 7  Expires null: true  Path equals null: true  Domain 
null: false
Name: A 8  Expires null: true  Path equals null: true  Domain 
null: false
Name: A 9  Expires null: true  Path equals null: true  Domain 
null: false
~~~~~~~~~
Name: A10  Expires null: true  Path equals null: false  Domain 
null: false
Name: A11  Expires null: true  Path equals null: true  Domain 
null: false
Name: A12  Expires null: true  Path equals null: true  Domain 
null: false
Name: A13  Expires null: true  Path equals null: true  Domain 
null: false


[[code]]

import std.stdio;
import std.datetime;

public class HttpResponse{
	public void setCookie(
		string name,
		string value,
		long maxAgeInSeconds = long.min,
		string expiresOnGMTDate=null,
		string path=null,
		string domain=null,
		bool secure=false
	) shared{
		writeln(
			"Name: ", name,
			"  Expires null: ", (expiresOnGMTDate == null),
			"  Path equals null: ", (path == null),
			"  Domain null: ", (domain is null)
		);
	}

	public void hellYeah(
		string name,
		string value,
		long maxAgeInSeconds = long.min,
		string expiresOnGMTDate=null,
		string path=null,
		string domain=null,
		bool secure=false
	) shared{
		writeln(
			"Name: ", name,
			"  Expires null: ", (expiresOnGMTDate == null),
			"  Path equals null: ", (path == null),
			"  Domain null: ", (domain is null)
		);
	}

	public void hellYeah2(
		string name,
		string value,
		long maxAgeInSeconds = long.min,
		string expiresOnGMTDate=null,
		string path=null,
		string domain=null,
		bool secure=false
	) shared{
		writeln(
			"Name: ", name,
			"  Expires null: ", (expiresOnGMTDate == null),
			"  Path equals null: ", (path == null),
			"  Domain null: ", (domain is null)
		);
	}
}

void main(){
	auto responseObject = new shared HttpResponse();

	responseObject.hellYeah( "A 1", "B1" );
	responseObject.hellYeah( "A 2", "B2" );
	responseObject.hellYeah( "A 3", "B3" );
	responseObject.hellYeah( "A 4", "B4" );
	responseObject.hellYeah( "A 5", "B5" );

	writeln("~~~~~~~~~");

	responseObject.setCookie( "A 6", "B6" );
	responseObject.setCookie( "A 7", "B7" );
	responseObject.setCookie( "A 8", "B8" );
	responseObject.setCookie( "A 9", "B9" );

	writeln("~~~~~~~~~");
	
	responseObject.hellYeah2( "A10", "B10" );
	responseObject.hellYeah2( "A11", "B11" );
	responseObject.hellYeah2( "A12", "B12" );
	responseObject.hellYeah2( "A13", "B13" );
}


More information about the Digitalmars-d-learn mailing list