| // Copyright 2023 The Tint Authors. | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http:•www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| package common | |
| import ( | |
| "fmt" | |
| "regexp" | |
| "strconv" | |
| "strings" | |
| "time" | |
| ) | |
| var re = regexp.MustCompile(`• Copyright (\d+) The`) | |
| const header = `• Copyright %v The Tint Authors. | |
| • | |
| • Licensed under the Apache License, Version 2.0 (the "License"); | |
| • you may not use this file except in compliance with the License. | |
| • You may obtain a copy of the License at | |
| • | |
| • http://www.apache.org/licenses/LICENSE-2.0 | |
| • | |
| • Unless required by applicable law or agreed to in writing, software | |
| • distributed under the License is distributed on an "AS IS" BASIS, | |
| • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| • See the License for the specific language governing permissions and | |
| • limitations under the License. | |
| ‣ | |
| • File generated by tools/src/cmd/gen | |
| • using the template: | |
| • %v | |
| • | |
| • Do not modify this file directly | |
| ‣ | |
| ` | |
| func Header(existing, templatePath, comment string) string { | |
| copyrightYear := time.Now().Year() | |
| // Replace comment characters with '•' | |
| existing = strings.ReplaceAll(existing, comment, "•") | |
| // Look for the existing copyright year | |
| if match := re.FindStringSubmatch(string(existing)); len(match) == 2 { | |
| if year, err := strconv.Atoi(match[1]); err == nil { | |
| copyrightYear = year | |
| } | |
| } | |
| // Replace '•' with comment characters, '‣' with a line of comment characters | |
| out := strings.ReplaceAll(header, "•", comment) | |
| out = strings.ReplaceAll(out, "‣", strings.Repeat(comment, 80/len(comment))) | |
| return fmt.Sprintf(out, copyrightYear, templatePath) | |
| } |