| 1 |
# @FUNCTION: tribits_strip_quotes_from_str() |
| 2 |
# |
| 3 |
# Remove one set of quotes from the outside of a string if they exist. |
| 4 |
# |
| 5 |
# Usage:: |
| 6 |
# |
| 7 |
# tribits_strip_quotes_from_str(<str_in> <str_var_out>) |
| 8 |
# |
| 9 |
# If ``<str_in>`` does not contain a quote char ``'"'`` as the first and last |
| 10 |
# char, then the original ``<str_in>`` is returned in ``<str_var_out>``. |
| 11 |
# |
| 12 |
function(tribits_strip_quotes_from_str str_in str_var_out) |
| 13 |
#print_var(str_in) |
| 14 |
string(LENGTH "${str_in}" str_len) |
| 15 |
#print_var(str_len) |
| 16 |
if (str_len LESS 2) |
| 17 |
# Can't have two parath \" chars of does not have 2 chars! |
| 18 |
set(${str_var_out} "${str_in}" PARENT_SCOPE) |
| 19 |
return() |
| 20 |
endif() |
| 21 |
math(EXPR str_len_less_1 "${str_len} - 1") |
| 22 |
math(EXPR str_len_less_2 "${str_len} - 2") |
| 23 |
#print_var(str_len_less_1) |
| 24 |
#print_var(str_len_less_2) |
| 25 |
string(SUBSTRING "${str_in}" 0 1 str_first_char) |
| 26 |
#print_var(str_first_char) |
| 27 |
if (str_len_less_1 GREATER 0) |
| 28 |
string(SUBSTRING "${str_in}" ${str_len_less_1} 1 str_last_char) |
| 29 |
#print_var(str_last_char) |
| 30 |
if (str_first_char STREQUAL "\"" AND str_last_char STREQUAL "\"") |
| 31 |
string(SUBSTRING "${str_in}" 1 ${str_len_less_2} str_parath_removed) |
| 32 |
#print_var(str_parath_removed) |
| 33 |
set(${str_var_out} "${str_parath_removed}" PARENT_SCOPE) |
| 34 |
return() |
| 35 |
endif() |
| 36 |
endif() |
| 37 |
# If we get here, there were not \" chars as the first and last char so |
| 38 |
# return the entire input string! |
| 39 |
set(${str_var_out} "${str_in}" PARENT_SCOPE) |
| 40 |
endfunction() |