-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
truncate too long descriptions in SCs
- Loading branch information
lunfardo314
committed
Oct 2, 2020
1 parent
85eba8b
commit 2dd69a7
Showing
6 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package util | ||
|
||
const ( | ||
ending = "[..]" | ||
) | ||
|
||
func GentleCut(s string, length int) string { | ||
if len(s) <= length { | ||
return s | ||
} | ||
if length <= len(ending) { | ||
return ending | ||
} | ||
return s[:length-len(ending)] + ending | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package util | ||
|
||
import "testing" | ||
|
||
func TestCutGently(t *testing.T) { | ||
t.Log(GentleCut("kukukuku", 10)) | ||
t.Log(GentleCut("kukukuku", 8)) | ||
t.Log(GentleCut("kukukuku", 5)) | ||
t.Log(GentleCut("kukukukukuku", 5)) | ||
t.Log(GentleCut("kukukukukuku", 6)) | ||
t.Log(GentleCut("kukukukukuku", 7)) | ||
t.Log(GentleCut("kukukukukuku", 8)) | ||
t.Log(GentleCut("kukukukukuku", 9)) | ||
t.Log(GentleCut("kukukukukuku", 10)) | ||
t.Log(GentleCut("kukukukukuku", 11)) | ||
t.Log(GentleCut("kukukukukuku", 12)) | ||
t.Log(GentleCut("ku", 1)) | ||
t.Log(GentleCut("ku", 5)) | ||
t.Log(GentleCut("kuku", 1)) | ||
t.Log(GentleCut("kuku", 4)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters