Re: Email validation

2017-11-28 Thread Dmitry via Digitalmars-d-learn

On Wednesday, 29 November 2017 at 03:49:56 UTC, codephantom wrote:

string domainRequired = "@hotmail.com";

string emailAddress = "vino.bhee...@hotmail.com";

emailAddress.endsWith(domainRequired) ? writeln("domain ok")
 : writeln("invalid domain");

Also you need check that only one @ used.


Re: Tried C++ to D. Wrong result.

2017-11-28 Thread Dmitry via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 09:01:47 UTC, Temtaime wrote:

https://pastebin.com/xJXPBh0n
Converted it and it works as expected.

What did you use for it?
In future I'll be needed to convert some more C++ code.

P.S. /And it works wrong, because uses unsafe pointer (ubyte 
*image). So, it takes wrong values (Blue of the next pixel 
instead of Alpha of the current pixel). Same with original code./


P.P.S. Anyway, I already found all things I did wrong. But also I 
found in your code that there is `swap` function, didn't know it. 
Thank you!





Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn

On Monday, 27 November 2017 at 19:01:28 UTC, Ali Çehreli wrote:
P.S. I think you have an unnecessary 'ref' on the D version 
because a slice is already a reference to elements:

Fixed, thank you.



Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn

On Monday, 27 November 2017 at 18:40:41 UTC, Ali Çehreli wrote:

So, it looks like the original code was accessing out of bounds 
and probably that's why you inserted the ((index + 3) < N) 
check in the D version because D was catching that error at 
runtime.

Yes, it is.

Which of course would skip the body of the if block, causing a 
difference from the original result.
Yes. I fixed it in C++ version also and now both versions works 
same.




Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn

On Monday, 27 November 2017 at 17:21:05 UTC, Dmitry wrote:
It fixed a delay (you can see it on video I posted before), but 
result is same.


It seems I found the problem.

C++ version (line 93):
if (image[index + 3] != 0)

I changed to
if (image[index] != 0)

and it works.

I don't understand why there was used "+ 3" (and why it works in 
C++ version).


Thank you all for help.


Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn

On Monday, 27 November 2017 at 17:01:29 UTC, Adam D. Ruppe wrote:

In the C++ version they are declared

std::vector pending;
std::vector pendingNext;

Ah, indeed. I thought that

pending.reserve(N);
pendingNext.reserve(N);

initializes them (last time I used C++ about 17 years ago...)


I suspect you will get better results by just making the D decls
and leave the rest of the code the same and see what happens.
It fixed a delay (you can see it on video I posted before), but 
result is same.


Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn

On Monday, 27 November 2017 at 14:35:39 UTC, Stefan Koch wrote:
First I'd make sure that what you get out of dlib load is the 
same as the c++ version gets.

Just use standard debugging techniques.


Yes, it's same. As you can see, the top-middle area of the result 
is same.


I wrote a video of process (D version, every 100-th frame)
https://www.dropbox.com/s/hcw1x4cwjou69su/video.mpg

C++ version:
https://www.dropbox.com/s/i7xpa5mzddpz6nu/video_orig.mpg



Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn
On Monday, 27 November 2017 at 14:14:12 UTC, rikki cattermole 
wrote:

Did you confirm that the image was loaded originally correctly?


Yes.

This image was used:
https://github.com/urraka/alpha-bleeding/blob/master/media/original.png




Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn

I tried translate C++ programm to D, but result is different.

original:
https://github.com/urraka/alpha-bleeding/blob/master/src/alpha-bleeding.cpp
result (with removed alpha):
https://github.com/urraka/alpha-bleeding/blob/master/media/alpha-bleeding-opaque.png

my:
https://pastebin.com/GzZQ7WHt
result (with removed alpha):
https://www.dropbox.com/s/xbjphlievboslv2/original-2.png

What did I wrong?

P.S. Also on an one image it was crashed at line 63 (range 
violation)

https://pastebin.com/TenGusw0
so I added ((index + 3) < N) into condition.



Re: debugging in vs code on Windows

2017-10-18 Thread Dmitry via Digitalmars-d-learn

On Tuesday, 17 October 2017 at 10:09:12 UTC, Dmitry wrote:

On Tuesday, 17 October 2017 at 08:38:20 UTC, Arjan wrote:
Before this will work, one must install the Microsoft C/C++ 
Addin i.e. ms-vscode.cpptools.

Start debugging and select the C++ debugger.


Yep 
https://forum.dlang.org/post/xwsvxphjtzgwjyrgd...@forum.dlang.org


Yesterday I found that C/C++ debugger is not very usable for D. 
For example, it doesn't show some structs and associative arrays 
(shows it just as pointer), pointer+length+chunk of memory 
instead of string, etc. So, I had to use VisualStudio + Mago for 
debugging.


Re: debugging in vs code on Windows

2017-10-17 Thread Dmitry via Digitalmars-d-learn

On Tuesday, 17 October 2017 at 08:38:20 UTC, Arjan wrote:
Before this will work, one must install the Microsoft C/C++ 
Addin i.e. ms-vscode.cpptools.

Start debugging and select the C++ debugger.


Yep 
https://forum.dlang.org/post/xwsvxphjtzgwjyrgd...@forum.dlang.org




Re: debugging in vs code on Windows

2017-10-16 Thread Dmitry via Digitalmars-d-learn

On Tuesday, 17 October 2017 at 02:32:49 UTC, Domain wrote:

Can you share your tasks.json and launch.json?


tasks.json - I don't have this file.
launch.json:
{
"version": "0.2.0",
"configurations": [

{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}\\parser.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true
}
]
}

Also I have changed preferences:
"debug.allowBreakpointsEverywhere": true,

Status bar:
x86_64 debug dmd



Re: debugging in vs code on Windows

2017-10-15 Thread Dmitry via Digitalmars-d-learn

On Friday, 13 October 2017 at 12:55:09 UTC, piotrklos wrote:
Has anyone been able to debug in VS code on Windows? What am I 
doing wrong?


Yep, it work for me.
How do you start debugging?
I noticed that the bottom button (small bug) at status bar 
doesn't work for me. But when I use Debug → Start Debugging (F5), 
it works.


Re: CSV crash: "Quote located in unquoted token"

2017-10-13 Thread Dmitry via Digitalmars-d-learn

On Friday, 13 October 2017 at 18:53:37 UTC, Jesse Phillips wrote:
You can use Malformed.ignore[1], but your data will come out 
like:


You are about to remove ""{0}"" from view ""{1}""

This would leave you needing to modify the "".

1. https://dlang.org/phobos/std_csv.html#.Malformed


I'll look into it. Thank you!


Re: CSV crash: "Quote located in unquoted token"

2017-10-13 Thread Dmitry via Digitalmars-d-learn
On Friday, 13 October 2017 at 10:11:39 UTC, rikki cattermole 
wrote:

Something along the lines of:
.byLine.map!(a => a.fixQuotes).joiner("\n").csvReader!...

Yep, it works.


Either way, you're using ranges!
Its even the same amount of code, if not less.

I see. Thank you!


Re: CSV crash: "Quote located in unquoted token"

2017-10-13 Thread Dmitry via Digitalmars-d-learn
On Friday, 13 October 2017 at 09:00:52 UTC, rikki cattermole 
wrote:
Write a purpose built csv parser using ranges. It should take 
only about half an hour.
I know, I know not very helpful. But a custom built parser will 
work better for you I think.
Yep, I can parse it myself, but I want to try to avoid this 
(reduce amount of source code).


Maybe there is posiible something like this:
foreach(record; file.byLine.fixQuotes.joiner("\n").csvReader!...
?

What types should get/return the function (fixQuotes) if I want 
change the line after .byLine?

When compiler says:
"candidates are:
src\phobos\std\array.d(2534,5): std.array.replaceFirst(E, R1, 
R2)(E[] subject, R1 from, R2 to) if (isDynamicArray!(E[]) && 
isForwardRange!R1 && is(typeof(appender!(E[])().put(from[0..1]))) 
&& isForwardRange!R2 && 
is(typeof(appender!(E[])().put(to[0..1]"


it's scares me and I hiding under the table.

I thought about something like
auto fixQuotes(string text)
{
if (text.canFind("\"\""))
{
// some magic
}

return text;
}

but obviously, it won't compiled


CSV crash: "Quote located in unquoted token"

2017-10-13 Thread Dmitry via Digitalmars-d-learn

Hi there.
When I load csv, it crashes ("Quote located in unquoted token") 
on lines with quotes, like this:


ResourceNode_RemoveFromView_Confirm,You are about to remove 
""{0}"" from view ""{1}"". Continue?,You are about to remove 
""{0}"" from view ""{1}"". Continue?,,Resource Tree - 
confirmation of removal from the current view


There are 5 records:
ResourceNode_RemoveFromView_Confirm,
You are about to remove ""{0}"" from view ""{1}"". Continue?,
You are about to remove ""{0}"" from view ""{1}"". Continue?,
,
Resource Tree - confirmation of removal from the current view

If I add quotes at begin and end of the 2 and 3 records, then it 
works. But I can't change original file.


How I can avoid the error?

I read file using this code:
foreach(record; 
file.byLine.joiner("\n").csvReader!(Tuple!(string, string, 
string, string, string)))

{
...
}



Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-18 Thread Dmitry via Digitalmars-d-learn

On Tuesday, 18 April 2017 at 13:48:57 UTC, Stanislav Blinov wrote:
There's a much more concise workaround, both in code written 
and generated ;)


import std.stdio;

template func(string file = __FILE__, int line = __LINE__)
{
auto func(T...)(auto ref T args)
{
writeln("called func with ", T.length, " args at ",
file, ":", line);
}
}

void main()
{
func();
func(1, 2, 3);
}


Very nice. Thank you!


Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Dmitry via Digitalmars-d-learn

On Monday, 17 April 2017 at 14:23:50 UTC, Jonathan M Davis wrote:
So, if you're okay with explicitly instantiating your variadic 
function template instead of having the types inferred, then it
Yes, it's my case. That's a game engine, so some kilobytes isn't 
a problem.

Moreover, possible that function will be used only in debug mode.

Thank you for explaining, I appreciate it.


Re: hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Dmitry via Digitalmars-d-learn

On Monday, 17 April 2017 at 10:55:30 UTC, Jonathan M Davis wrote:
They works, but it results in a new template being instantiated 
for every call, so you really shouldn't use __FILE__ or 
__LINE__ as template arguments if you can avoid it.

Does it matter if I anyway use template (S...) ?
And what problem with that new templates for every call? 
Increases .exe size? Needs more memory (runtime? compile-time?)? 
Something else?


Usually, the better way to handle it is to use runtime 
arguments, e.g.
void error(string msg, string file = __FILE__, size_t line = 
__LINE__)
Is possible use this with (S...)? In some cases I use many 
arguments (5-10, mixed strings and numbers) and I tried to avoid 
the concatenation them into string.


What will be better? Concatenation or templates? Or maybe an 
another way?


hidden passing of __FILE__ and __LINE__ into function

2017-04-17 Thread Dmitry via Digitalmars-d-learn

Hi there.

Currently for messages about errors I use code like this:

void add(string name, ref Scene scene)
{
if (name in listOfScenes)
{
EError(__FILE__, __LINE__, "scene already exists".L, 
quoted(name));

}
...
}

Is there way for avoid using (avoid writing) `__FILE__` and 
`__LINE__` in each call? I.e. I want use simple


EError("scene already exists".L, quoted(name));

but function `EError` must print info (file and line) of where 
was called.


P.S. `EError` just prints info into console, result for this 
example is:


[Error] (source\core\EScene.d, 35) Scene already exists: "Scene 
1"


and code is:

void EError(S...)(S args)
{
write("[Error] (", args[0], ", ", args[1], ") ", 
args[2..$], '\n');}

}



Re: Natural sorted list of files

2017-02-07 Thread Dmitry via Digitalmars-d-learn

On Wednesday, 8 February 2017 at 07:41:29 UTC, Ali Çehreli wrote:
test.naturalSort would sort the array in place before calling 
writeln and 'test' would appear naturally sorted as well. I've 
fixed it like this:


Great! Thank you!



Re: Natural sorted list of files

2017-02-06 Thread Dmitry via Digitalmars-d-learn

On Monday, 6 February 2017 at 18:57:17 UTC, Ali Çehreli wrote:

I think  it's now std.algorithm.chunkBy. Please fix Rosetta


Thank you!
I fixed, but anyway it works incorrect (it doesn't any changes):

Code: https://rosettacode.org/wiki/Natural_sorting#D
Result: http://pastebin.com/hhSB4Vpn

like this:
["foo1000bar99baz10.txt", "foo1000bar99baz9.txt", 
"foo100bar10baz0.txt", "foo100bar99baz0.txt"]
["foo1000bar99baz10.txt", "foo1000bar99baz9.txt", 
"foo100bar10baz0.txt", "foo100bar99baz0.txt"]


but must be this:
["foo100bar99baz0.txt", "foo100bar10baz0.txt", 
"foo1000bar99baz10.txt", "foo1000bar99baz9.txt"]
["foo100bar10baz0.txt", "foo100bar99baz0.txt", 
"foo1000bar99baz9.txt", "foo1000bar99baz10.txt"]


Re: Natural sorted list of files

2017-02-06 Thread Dmitry via Digitalmars-d-learn
On Monday, 6 February 2017 at 17:35:02 UTC, Jonathan M Davis 
wrote:

You have to import std.range to use groupBy.

Of course, "import std.range" already done.

I tested it also with full rosetta's code:

import std.stdio, std.string, std.algorithm, std.array, std.conv, 
std.ascii, std.range;


string[] naturalSort(string[] arr) /*pure @safe*/ {
static struct Part {
string s;

int opCmp(in ref Part other) const pure {
return (s[0].isDigit && other.s[0].isDigit) ?
   cmp([s.to!ulong], [other.s.to!ulong]) :
   cmp(s, other.s);
}
}

static mapper(in string txt) /*pure nothrow @safe*/ {
auto r = txt
 .strip
 .tr(whitespace, " ", "s")
 .toLower
 .groupBy!isDigit
 .map!(p => Part(p.text))
 .array;
return (r.length > 1 && r[0].s == "the") ? r.dropOne : r;
}

return arr.schwartzSort!mapper.release;
}

void main() /*@safe*/ {
auto tests = [
// Ignoring leading spaces.
["ignore leading spaces: 2-2", " ignore leading spaces: 2-1", 
"

 ignore leading spaces: 2+1", "  ignore leading spaces: 2+0"],

// Ignoring multiple adjacent spaces (m.a.s).
["ignore m.a.s spaces: 2-2", "ignore m.a.s  spaces: 2-1",
 "ignore m.a.s   spaces: 2+0", "ignore m.a.sspaces: 2+1"],

// Equivalent whitespace characters.
["Equiv. spaces: 3-3", "Equiv.\rspaces: 3-2",
 "Equiv.\x0cspaces: 3-1", "Equiv.\x0bspaces: 3+0",
 "Equiv.\nspaces: 3+1", "Equiv.\tspaces: 3+2"],

// Case Indepenent sort.
["cASE INDEPENENT: 3-2", "caSE INDEPENENT: 3-1",
 "casE INDEPENENT: 3+0", "case INDEPENENT: 3+1"],

// Numeric fields as numerics.
["foo100bar99baz0.txt", "foo100bar10baz0.txt",
 "foo1000bar99baz10.txt", "foo1000bar99baz9.txt"],

// Title sorts.
["The Wind in the Willows", "The 40th step more",
 "The 39 steps", "Wanda"]];

foreach (test; tests)
writeln(test, "\n", test.naturalSort, "\n");
}

result:
$ dub
Performing "debug" build using dmd for x86_64.
sort_test ~master: building configuration "application"...
source/app.d(19,18): Error: no property 'groupBy' for type 
'string'

dmd failed with exit code 1.



Natural sorted list of files

2017-02-06 Thread Dmitry via Digitalmars-d-learn
Hi. I'm need get list of files in the directory, with natural 
sort, like:

file_2
file_8
file_10
file_11
file_20
file_100
etc.

Found this https://rosettacode.org/wiki/Natural_sorting#D
but there is error on ".groupBy!isDigit" (Error: no property 
'groupBy' for type 'string').


with deleted line it works, but order is incorrect, like:
file_1
file_10
file_11
file_100
file_2
file_20
etc.

How can I do this?


Re: Programming a Game in D? :D

2014-05-25 Thread Dmitry via Digitalmars-d-learn

On Saturday, 24 May 2014 at 18:00:05 UTC, evilrat wrote:
there is a plugin for linux for GDB i believe, and another 
plugin for Windows which i can't remember the name, the latter 
one disappeared from XS 5.0 by some reason. search the 
extensions for it.
I use Windows. Thanks, I think I found it: 
https://github.com/llucenic/MonoDevelop.Debugger.Gdb.D

But now I cant install it, here is error:
The package 'MonoDevelop.Core v4.0' could not be found in any 
repository
The package 'MonoDevelop.Ide v4.0' could not be found in any 
repository

I dont know where is this repository.

unfortunatelly if you are on Windows best option is to use 
Mono-D for writing code, and VisualD to debug it. (there is 
also DCD/DScanner but i never tried it myself).
Currently it is not way for me. I already wrote about it - I cant 
build my project with DSFML in VisualStudio. Maybe in future I 
can resolve it. But not now.


Re: Programming a Game in D? :D

2014-05-25 Thread Dmitry via Digitalmars-d-learn

On Sunday, 25 May 2014 at 09:44:18 UTC, evilrat wrote:
sorry, forgot to add - Mono-D is moving to XS 5.0 (alpha), so 
if XS 4.0 not working for you, try to switch on alpha channel 
updates.

on the contrary, I have now XS 5.0

and I have a reply:

aBothe commented an hour ago
It's not there for 5.0 yet, unfortunately -- mostly due my 
lazyness,

but it's under a larger reconstruction.

https://github.com/llucenic/MonoDevelop.Debugger.Gdb.D/issues/4


Re: Programming a Game in D? :D

2014-05-24 Thread Dmitry via Digitalmars-d-learn

On Saturday, 24 May 2014 at 09:49:30 UTC, evilrat wrote:

why not just use Xamarin Studio with Mono-D?
But only the trial of Xamarin Studio is for free, and I used 
eclipse for Java before and really like it :P
actually not. you don't even need to register at all. just go 
to http://monodevelop.com and get ur XS without all this fancy 
mobile stuff.

Hi. How I can debug in Xamarin?
What I need do for activate debugger?
I have this option is disabled:
http://goo.gl/cDGIk1


Video playback

2014-05-18 Thread Dmitry via Digitalmars-d-learn

Hi everyone!
I want to play video in my D-application (maybe WebM or Theora). 
However didn't find any library for operation with video in D. I 
am a beginner in D, experience of transfer of libraries with 
C/C++, certainly isn't present.

Maybe somebody will prompt something?

P.S. My application uses SFML (DSFML).


Re: Video playback

2014-05-18 Thread Dmitry via Digitalmars-d-learn

On Sunday, 18 May 2014 at 07:37:33 UTC, Rikki Cattermole wrote:
My suggestion would be to go the direction of libvlc[0]. I did 
find a forum post from SFML that may help you.
It is a c library so it shouldn't be too hard to create a 
binding to. Perhaps something along the lines of 
Derelict-Util[2] will help with it.


If you need shared libraries and don't want to build your own, 
you should be able to extract them after installing Vlc itself.


Thank you, Rikki! I try.