Top 5

Benji Smith dlanguage at benjismith.net
Fri Oct 10 10:27:23 PDT 2008


cemiller wrote:
>>>> http://www.dprogramming.com/mtext.php
>>>>
>>>> Nearly as efficient as regular strings & same memory footprint as 
>>>> the type of the lagest character within (i.e. if it contains only 
>>>> ascii, 8 bits/char. If it contains things representable in UTF-16, 
>>>> 16 bits a character. If it contains cuneoform, 32 bits per char).
>>>  Looks interesting. I've downloaded it. I'll give it a whirl and let 
>>> you know what I think. But, upon first glance, you definitely need 
>>> some example code and a tutorial. Right now, I don't really know 
>>> where to start.
>>>  --benji
>>
>> I totally agree it needs more docs. I didn't write it; Chris Miller 
>> gets that credit.
> 
> 
> I tried to make it work like arrays (strings) as much as possible. It 
> has .length, concat operators, slicing, and other utility functions.
> The documentation is available at:  
> http://www.dprogramming.com/docs/mtext/mtext.html
> 
> Here's some older examples from the unittest:
>     mstring s = mstring("foo"c);
>     assert(s == "foo"c);
>     
>     assert(s.startsWith("f"c));
>     assert(s.startsWith("fo"w));
>     assert(s.startsWith("foo"c));
>     assert(!s.startsWith("fooo"c));
>     assert(!s.startsWith("F"c));
>     assert(s.startsWith("F"c, true));
>     assert(!s.startsWith("E"c, true));
>     assert(s.endsWith("o"c));
>     assert(s.endsWith("oo"d));
>     assert(s.endsWith("foo"c));
>     assert(!s.endsWith("fooo"c));
>     assert(!s.endsWith("ooo"c));
>     assert(s.endsWith("O"c, true));
>     assert(!s.endsWith("P"c, true));
>     
>     int i;
>     s = mstring("The quick brown fox jumped over the lazy dog."w);
>     i = s.find("Lazy"c, true);
>     assert(-1 != i);
>     assert(s[i .. i + 4] == "lazy"c);
>     i = s.find("Lazy"c, false);
>     assert(-1 == i);
>     i = s.find("."c, true);
>     assert(-1 != i);
>     i = s.find("dog."c, true);
>     assert(-1 != i);
>     
>     wchar[] ws = "Arrrrr!";
>     assert(ws == mstring(ws));
>     assert(!(ws > mstring(ws)));
>     assert(!(ws < mstring(ws)));
>     assert(ws == mstring(ws)[0 .. ws.length]);
>     assert(!(ws > mstring(ws)[0 .. ws.length]));
>     assert(!(ws < mstring(ws)[0 .. ws.length]));
>     
>     mstring s2;
>     s2 = s.dup;
>     assert(s.type != s2.type); // Compacted.
>     assert(s == s2); // Same value.
> 
> and with the newer opAssign,
>     import mtext;
>     void main()
>     {
>       mstring hi = "hello"c;
>       hi ~= ", world"c;
>     }
> 
> FAQ is on the main page:  http://www.dprogramming.com/mtext.php
> 
> I'll try to add better examples soon.
> 
> 
> - Chris Miller (cemiller)

Very nice. Thanks!

--benji



More information about the Digitalmars-d mailing list