Ignore whitespace when stripping sequence from filename #335
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
344c88b84c
commit
a6e06844f3
2 changed files with 23 additions and 1 deletions
|
@ -29,7 +29,7 @@ func Base(fileName string, stripSequence bool) string {
|
|||
}
|
||||
|
||||
// other common sequential naming schemes
|
||||
if end := strings.Index(basename, " ("); end != -1 {
|
||||
if end := strings.Index(basename, "("); end != -1 {
|
||||
// copies created by Chrome & Windows, example: IMG_1234 (2)
|
||||
basename = basename[:end]
|
||||
} else if end := strings.Index(basename, " copy"); end != -1 {
|
||||
|
@ -37,6 +37,8 @@ func Base(fileName string, stripSequence bool) string {
|
|||
basename = basename[:end]
|
||||
}
|
||||
|
||||
basename = strings.TrimSpace(basename)
|
||||
|
||||
return basename
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,26 @@ func TestBase(t *testing.T) {
|
|||
result := Base("/testdata/Test (3).jpg", false)
|
||||
assert.Equal(t, "Test (3)", result)
|
||||
})
|
||||
t.Run("20180506_091537_DSC02122.JPG", func(t *testing.T) {
|
||||
result := Base("20180506_091537_DSC02122.JPG", true)
|
||||
assert.Equal(t, "20180506_091537_DSC02122", result)
|
||||
})
|
||||
t.Run("20180506_091537_DSC02122 (+3.3).JPG", func(t *testing.T) {
|
||||
result := Base("20180506_091537_DSC02122 (+3.3).JPG", true)
|
||||
assert.Equal(t, "20180506_091537_DSC02122", result)
|
||||
})
|
||||
t.Run("20180506_091537_DSC02122 (-2.7).JPG", func(t *testing.T) {
|
||||
result := Base("20180506_091537_DSC02122 (-2.7).JPG", true)
|
||||
assert.Equal(t, "20180506_091537_DSC02122", result)
|
||||
})
|
||||
t.Run("20180506_091537_DSC02122(+3.3).JPG", func(t *testing.T) {
|
||||
result := Base("20180506_091537_DSC02122(+3.3).JPG", true)
|
||||
assert.Equal(t, "20180506_091537_DSC02122", result)
|
||||
})
|
||||
t.Run("20180506_091537_DSC02122(-2.7).JPG", func(t *testing.T) {
|
||||
result := Base("20180506_091537_DSC02122(-2.7).JPG", true)
|
||||
assert.Equal(t, "20180506_091537_DSC02122", result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRelativeBase(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue