Merge remote-tracking branch 'origin/topic/johanna/string_vec_null'

* origin/topic/johanna/string_vec_null:
  Make join_string_vec work with vectors containing empty elements.

BIT-1495 #merged
This commit is contained in:
Robin Sommer 2015-10-23 13:12:42 -07:00
commit ecc09c11ca
3 changed files with 12 additions and 1 deletions

View file

@ -216,7 +216,13 @@ function join_string_vec%(vec: string_vec, sep: string%): string
if ( i > 0 ) if ( i > 0 )
d.Add(sep->CheckString(), 0); d.Add(sep->CheckString(), 0);
v->Lookup(i)->Describe(&d); Val* e = v->Lookup(i);
// If the element is empty, skip it.
if ( ! e )
continue;
e->Describe(&d);
} }
BroString* s = new BroString(1, d.TakeBytes(), d.Len()); BroString* s = new BroString(1, d.TakeBytes(), d.Len());

View file

@ -4,3 +4,4 @@ mytest
this__is__another__test this__is__another__test
thisisanothertest thisisanothertest
Test Test
...hi..there

View file

@ -10,6 +10,9 @@ event bro_init()
local b: string_array = { [1] = "mytest" }; local b: string_array = { [1] = "mytest" };
local c: string_vec = vector( "this", "is", "another", "test" ); local c: string_vec = vector( "this", "is", "another", "test" );
local d: string_vec = vector( "Test" ); local d: string_vec = vector( "Test" );
local e: string_vec = vector();
e[3] = "hi";
e[5] = "there";
print join_string_array(" * ", a); print join_string_array(" * ", a);
print join_string_array("", a); print join_string_array("", a);
@ -18,4 +21,5 @@ event bro_init()
print join_string_vec(c, "__"); print join_string_vec(c, "__");
print join_string_vec(c, ""); print join_string_vec(c, "");
print join_string_vec(d, "-"); print join_string_vec(d, "-");
print join_string_vec(e, ".");
} }