hasEpochTimestamp returns true if the string ends with a POSIX-formatted timestamp for the UNIX epoch after a tab character. According to git, this is used by GNU diff to mark creations and deletions.
(s string)
| 516 | // timestamp for the UNIX epoch after a tab character. According to git, this |
| 517 | // is used by GNU diff to mark creations and deletions. |
| 518 | func hasEpochTimestamp(s string) bool { |
| 519 | const posixTimeLayout = "2006-01-02 15:04:05.9 -0700" |
| 520 | |
| 521 | start := strings.IndexRune(s, '\t') |
| 522 | if start < 0 { |
| 523 | return false |
| 524 | } |
| 525 | |
| 526 | ts := strings.TrimSuffix(s[start+1:], "\n") |
| 527 | |
| 528 | // a valid timestamp can have optional ':' in zone specifier |
| 529 | // remove that if it exists so we have a single format |
| 530 | if len(ts) >= 3 && ts[len(ts)-3] == ':' { |
| 531 | ts = ts[:len(ts)-3] + ts[len(ts)-2:] |
| 532 | } |
| 533 | |
| 534 | t, err := time.Parse(posixTimeLayout, ts) |
| 535 | if err != nil { |
| 536 | return false |
| 537 | } |
| 538 | if !t.Equal(time.Unix(0, 0)) { |
| 539 | return false |
| 540 | } |
| 541 | return true |
| 542 | } |
| 543 | |
| 544 | func isSpace(c byte) bool { |
| 545 | return c == ' ' || c == '\t' || c == '\n' |
no outgoing calls