Re: Replacing tango.text.Ascii.isearch
On Wednesday, 5 October 2022 at 17:29:25 UTC, Steven Schveighoffer wrote: ```d bool isearch(S1, S2)(S1 haystack, S2 needle) { import std.uni; import std.algorithm; return haystack.asLowerCase.canFind(needle.asLowerCase); } ``` untested. -Steve I did some basic testing, and regex was two orders of magnitude faster. So now I know, I guess.
Re: Replacing tango.text.Ascii.isearch
On 10/5/22 13:40, torhu wrote: auto sw = StopWatch(); Either this: auto sw = StopWatch(AutoStart.yes); or this: auto sw = StopWatch(); sw.start(); Ali
Re: Replacing tango.text.Ascii.isearch
On Wednesday, 5 October 2022 at 20:45:55 UTC, torhu wrote: On Wednesday, 5 October 2022 at 20:40:46 UTC, torhu wrote: Am I doing something wrong here? Right, you can instantiate structs without arguments. It's been ten years since I last used D, I was thinking of structs like if they were classes. I think there should be sensible default here, seems like an easy trap to remove.
Re: Replacing tango.text.Ascii.isearch
On Wednesday, 5 October 2022 at 20:40:46 UTC, torhu wrote: Am I doing something wrong here? Right, you can instantiate structs without arguments. It's been ten years since I last used D, I was thinking of structs like if they were classes.
Re: Replacing tango.text.Ascii.isearch
On Wednesday, 5 October 2022 at 17:29:25 UTC, Steven Schveighoffer wrote: [...] I wanted to do some quick benchmarking to figure out what works. When I run this: ```d import std.stdio; import std.datetime.stopwatch; void main() { auto sw = StopWatch(); sw.stop(); writeln(sw.peek().toString()); } ``` It prints this: 2 weeks, 6 days, 9 hours, 34 minutes, 43 secs, 214 ms, 946 ╬╝s, and 7 hnsecs Am I doing something wrong here?
Re: Replacing tango.text.Ascii.isearch
On 10/5/22 12:59 PM, torhu wrote: I need a case-insensitive check to see if a string contains another string for a "quick filter" feature. It should preferrably be perceived as instant by the user, and needs to check a few thousand strings in typical cases. Is a regex the best option, or what would you suggest? https://dlang.org/phobos/std_uni.html#asLowerCase ```d bool isearch(S1, S2)(S1 haystack, S2 needle) { import std.uni; import std.algorithm; return haystack.asLowerCase.canFind(needle.asLowerCase); } ``` untested. -Steve
Re: Convert int to dchar
On Wednesday, 5 October 2022 at 17:16:29 UTC, H. S. Teoh wrote: For the former: dchar ch = '0' + intValue; This! Thanks Teoh.
Re: Convert int to dchar
Thanks Steve. I need to covert something like this: int myvar = 5; How would I convert myvar to a dchar?
Re: Convert int to dchar
On Wed, Oct 05, 2022 at 04:57:57PM +, Paul via Digitalmars-d-learn wrote: >I'm sure I'm making this more difficult than it needs to be. I'm > trying to convert an integer to a dchar. The solution below works but > seems like overkill. > > dstring dstrValue = to!dstring(5); > dchar dcharValue = to!dchar(dstrValue); > > ... this, > > dchar dcharValue = to!dchar(5); > > ... writes out '\x005' ..or something close to that. What exactly do you mean by "convert an integer to a dchar"? Do you mean converting an integer between 0 and 9 into a dchar representing its digit value, or do you mean creating a dchar containing the unicode code point represented by the int? For the former: dchar ch = '0' + intValue; (Though you will have to consider what should happen if intValue > 9.) For the latter: dchar ch = cast(dchar) intValue; T -- Those who've learned LaTeX swear by it. Those who are learning LaTeX swear at it. -- Pete Bleackley
Re: Convert int to dchar
On 10/5/22 12:57 PM, Paul wrote: I'm sure I'm making this more difficult than it needs to be. I'm trying to convert an integer to a dchar. The solution below works but seems like overkill. dstring dstrValue = to!dstring(5); dchar dcharValue = to!dchar(dstrValue); ... this, dchar dcharValue = to!dchar(5); ... writes out '\x005' ..or something close to that. dchar dstrValue = '5'; -Steve
Replacing tango.text.Ascii.isearch
I need a case-insensitive check to see if a string contains another string for a "quick filter" feature. It should preferrably be perceived as instant by the user, and needs to check a few thousand strings in typical cases. Is a regex the best option, or what would you suggest?
Convert int to dchar
I'm sure I'm making this more difficult than it needs to be. I'm trying to convert an integer to a dchar. The solution below works but seems like overkill. dstring dstrValue = to!dstring(5); dchar dcharValue = to!dchar(dstrValue); ... this, dchar dcharValue = to!dchar(5); ... writes out '\x005' ..or something close to that.