@@ -26,7 +26,7 @@ expectedHeader=(
2626 " *******************************************************************************/"
2727)
2828
29- normalize_line () {
29+ normalize_line_for_compare () {
3030 local line=" $1 "
3131 line=" ${line// \* / } "
3232 line=$( printf ' %s' " $line " | tr -s ' [:space:]' ' ' )
@@ -35,6 +35,46 @@ normalize_line() {
3535 printf ' %s' " $line "
3636}
3737
38+ count_asterisks () {
39+ local line=" $1 "
40+ local only
41+ only=" ${line// [^*]/ } "
42+ printf ' %s' " ${# only} "
43+ }
44+
45+ compare_header_line () {
46+ local expected=" $1 "
47+ local actual=" $2 "
48+ local expected_text
49+ local actual_text
50+ local expected_count
51+ local actual_count
52+ local diff
53+
54+ expected_text=" $( normalize_line_for_compare " $expected " ) "
55+ actual_text=" $( normalize_line_for_compare " $actual " ) "
56+ if [ " $expected_text " != " $actual_text " ]; then
57+ return 1
58+ fi
59+
60+ expected_count=" $( count_asterisks " $expected " ) "
61+ actual_count=" $( count_asterisks " $actual " ) "
62+
63+ if [ " $expected_count " -gt 10 ]; then
64+ diff=$(( expected_count - actual_count))
65+ diff=" ${diff# -} "
66+ if [ " $diff " -le 1 ]; then
67+ return 0
68+ fi
69+ return 1
70+ fi
71+
72+ if [ " $expected_count " -eq " $actual_count " ]; then
73+ return 0
74+ fi
75+ return 1
76+ }
77+
3878rewrite_header () {
3979 local file=" $1 "
4080 local year_line=" $2 "
@@ -72,25 +112,25 @@ read_header_lines() {
72112
73113compute_header_stats () {
74114 local year_line_normalized
75- local expected_normalized
76- local actual_normalized
115+ local year_asterisks
77116 local idx
78117 match_count=0
79118 has_valid_year_line=false
80119 aduna_year=" "
81120
82- year_line_normalized=" $( normalize_line " ${header_lines[1]} " ) "
83- if [[ " $year_line_normalized " =~ ^Copyright\ \( c\)\ ([0-9]{4})\ Eclipse\ RDF4J\ contributors\. $ ]]; then
84- has_valid_year_line=true
85- elif [[ " $year_line_normalized " =~ ^Copyright\ \( c\)\ ([0-9]{4})\ Eclipse\ RDF4J\ contributors,\ Aduna,\ and\ others\. $ ]]; then
86- has_valid_year_line=true
87- aduna_year=" ${BASH_REMATCH[1]} "
121+ year_line_normalized=" $( normalize_line_for_compare " ${header_lines[1]} " ) "
122+ year_asterisks=" $( count_asterisks " ${header_lines[1]} " ) "
123+ if [ " $year_asterisks " -eq 1 ]; then
124+ if [[ " $year_line_normalized " =~ ^Copyright\ \( c\)\ ([0-9]{4})\ Eclipse\ RDF4J\ contributors\. $ ]]; then
125+ has_valid_year_line=true
126+ elif [[ " $year_line_normalized " =~ ^Copyright\ \( c\)\ ([0-9]{4})\ Eclipse\ RDF4J\ contributors,\ Aduna,\ and\ others\. $ ]]; then
127+ has_valid_year_line=true
128+ aduna_year=" ${BASH_REMATCH[1]} "
129+ fi
88130 fi
89131
90132 for idx in 0 2 3 4 5 6 7 8 9; do
91- expected_normalized=" $( normalize_line " ${expectedHeader[$idx]} " ) "
92- actual_normalized=" $( normalize_line " ${header_lines[$idx]} " ) "
93- if [[ " $actual_normalized " == " $expected_normalized " ]]; then
133+ if compare_header_line " ${expectedHeader[$idx]} " " ${header_lines[$idx]} " ; then
94134 match_count=$(( match_count + 1 ))
95135 fi
96136 done
0 commit comments