[CMake] Iterating empty elements in a list

2013-08-06 Thread Robert Dailey
I've seen that list(LENGTH) will ignore empty elements in a list. Example:

1;2;;4;5

Length will be 4 here instead of 5. I was trying to come up with a way
to modify the list as a string prior to iterating it to give empty
elements some dummy value, so that the above example would appear as:

1;2;empty;4;5

However, this isn't going to work with string( REGEX REPLACE ) as the
modifications are not included in the continuation of the regex search
(I think positive lookbehind is needed here?). Basically this case
cannot be converted:

;;;

to:

empty;empty;empty

Anyone know how I can iterate empty elements in a list?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Iterating empty elements in a list

2013-08-06 Thread Robert Dailey
Just to be clear, I can't use foreach():

foreach( var IN LISTS list )

I am doing a yielded approach to looping by using list( GET ) and
list( LENGTH ) in combination. So I would need the list() functions to
acknowledge empty elements.

On Tue, Aug 6, 2013 at 3:04 PM, Robert Dailey rcdailey.li...@gmail.com wrote:
 I've seen that list(LENGTH) will ignore empty elements in a list. Example:

 1;2;;4;5

 Length will be 4 here instead of 5. I was trying to come up with a way
 to modify the list as a string prior to iterating it to give empty
 elements some dummy value, so that the above example would appear as:

 1;2;empty;4;5

 However, this isn't going to work with string( REGEX REPLACE ) as the
 modifications are not included in the continuation of the regex search
 (I think positive lookbehind is needed here?). Basically this case
 cannot be converted:

 ;;;

 to:

 empty;empty;empty

 Anyone know how I can iterate empty elements in a list?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Iterating empty elements in a list

2013-08-06 Thread Robert Dailey
Sorry for the spam, after posting a solution dawned on me. Here is
what I did for anyone else that might need a solution (or care to
propose a better one):


function( replace_empty_elements out_list in_list )
foreach( item IN LISTS in_list )
if( item STREQUAL  )
set( item_val EMPTY )
else()
set( item_val ${item} )
endif()

list( APPEND formatted_list ${item_val} )
endforeach()

set( ${out_list} ${formatted_list} PARENT_SCOPE )
endfunction()


Use it like so:

set( inlist ;;test; )
replace_empty_elements( outlist ${inlist} )
message( outlist: ${outlist} )

Output:

outlist: EMPTY;EMPTY;test;EMPTY

On Tue, Aug 6, 2013 at 3:10 PM, Robert Dailey rcdailey.li...@gmail.com wrote:
 Just to be clear, I can't use foreach():

 foreach( var IN LISTS list )

 I am doing a yielded approach to looping by using list( GET ) and
 list( LENGTH ) in combination. So I would need the list() functions to
 acknowledge empty elements.

 On Tue, Aug 6, 2013 at 3:04 PM, Robert Dailey rcdailey.li...@gmail.com 
 wrote:
 I've seen that list(LENGTH) will ignore empty elements in a list. Example:

 1;2;;4;5

 Length will be 4 here instead of 5. I was trying to come up with a way
 to modify the list as a string prior to iterating it to give empty
 elements some dummy value, so that the above example would appear as:

 1;2;empty;4;5

 However, this isn't going to work with string( REGEX REPLACE ) as the
 modifications are not included in the continuation of the regex search
 (I think positive lookbehind is needed here?). Basically this case
 cannot be converted:

 ;;;

 to:

 empty;empty;empty

 Anyone know how I can iterate empty elements in a list?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake