Changeset 561

Show
Ignore:
Timestamp:
02/10/08 05:10:37 (5 months ago)
Author:
braddr
Message:

Fix out contract of toStringz

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/string.d

    r536 r561  
    213213    { 
    214214    if (result) 
    215     {   assert(strlen(result) == s.length); 
    216         assert(memcmp(result, s.ptr, s.length) == 0); 
     215    { 
     216        auto slen = s.length; 
     217        while (slen > 0 && s[slen-1] == 0) --slen; 
     218        assert(strlen(result) == slen); 
     219        assert(memcmp(result, s.ptr, slen) == 0); 
    217220    } 
    218221    } 
     
    256259    p = toStringz(test); 
    257260    assert(*p == 0); 
     261 
     262    test = "\0"; 
     263    p = toStringz(test); 
     264    assert(*p == 0); 
     265 
     266    test = "foo\0"; 
     267    p = toStringz(test); 
     268    assert(p[0] == 'f' && p[1] == 'o' && p[2] == 'o' && p[3] == 0); 
    258269} 
    259270