Project

General

Profile

User story #4439 » remove_duplicate_lines.st

Alex Tkachenko, 2014-02-04 00:19

 
# Sanitizes the file by ensuring that all the lines from the list passed
# are present in the file and their duplicate occurences are removed.
#
# Usage:
#
# vars "the_list" slist => expression...
# ...
# files:
# "$(somefile)"
# handle => "somefile_remove_duplicates",
# comment => "Remove duplicate lines from $(somefile)",
# edit_line => remove_duplicate_lines($(the_list));
#
# By Alex Tkachenko <atkachenko@carrieriq.com>
bundle edit_line remove_duplicate_lines(list)
{
vars:
# The lines normally contain all sorts of chars, including those not suitable for class name
"clist" string => canonify("$(list)");

classes:
"$(clist)_duplicated"
scope => "bundle",
comment => "Raise dynamic class if more than one matching line found",
expression => isgreaterthan(countlinesmatching("$(list)", "$(edit.filename)"),1);

delete_lines:
"$(list)"
comment => "Delete all the occurences if more than one found",
ifvarclass => "$(clist)_duplicated";

insert_lines:
"$(list)"
comment => "Add the lines (append) back if they have been deleted",
ifvarclass => "$(clist)_duplicated";
}
(3-3/7)