Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62d59787 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "strings.mk: Allow empty RHS values for inputs of collapse-pairs"

parents 3c4326f3 f6652f4f
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ $(word $(1),$(subst :,$(space),$(2)))
endef

###########################################################
## Convert "a=b c= d e = f" into "a=b c=d e=f"
## Convert "a=b c= d e = f = g h=" into "a=b c=d e= f=g h="
##
## $(1): list to collapse
## $(2): if set, separator word; usually "=", ":", or ":="
@@ -96,11 +96,29 @@ endef
###########################################################

define collapse-pairs
$(strip \
$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
$(strip $(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
    $(subst $(_cpSEP), $(_cpSEP) ,$(1)))$(space)))
$(eval _cpLHS :=)\
$(eval _cpRET :=)\
$(foreach w,$(subst $(space)$(_cpSEP),$(_cpSEP),$(strip \
            $(subst $(_cpSEP),$(space)$(_cpSEP)$(space),$(1)))),\
  $(if $(findstring $(_cpSEP),$(w)),\
    $(eval _cpRET += $(_cpLHS))$(eval _cpLHS := $(w)),\
    $(eval _cpRET += $(_cpLHS)$(w))$(eval _cpLHS :=)))\
$(if $(_cpLHS),$(_cpRET)$(space)$(_cpLHS),$(_cpRET))\
$(eval _cpSEP :=)\
$(eval _cpLHS :=)\
$(eval _cpRET :=))
endef

# Sanity check for collapse-pairs.
ifneq (a=b c=d e= f=g h=,$(call collapse-pairs,a=b c= d e = f = g h=))
  $(error collapse-pairs sanity check failure)
endif
ifneq (a:=b c:=d e:=f g:=h,$(call collapse-pairs,a:=b c:= d e :=f g := h,:=))
  $(error collapse-pairs sanity check failure)
endif

###########################################################
## Given a list of pairs, if multiple pairs have the same
## first components, keep only the first pair.