aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-15 13:15:00 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-15 13:15:00 +0200
commit7bec0b1f134d213e7505fc2ac03ffea26f2193cc (patch)
treee263cccd84406843eacbc6bd184acdacb25a49d1 /util
parentb478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (diff)
downloadgit-bug-7bec0b1f134d213e7505fc2ac03ffea26f2193cc.tar.gz
bug: add a data validation process to avoid merging incorrect operations
Diffstat (limited to 'util')
-rw-r--r--util/text/validate.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/util/text/validate.go b/util/text/validate.go
new file mode 100644
index 00000000..68bdf48b
--- /dev/null
+++ b/util/text/validate.go
@@ -0,0 +1,33 @@
+package text
+
+import (
+ "strings"
+ "unicode"
+)
+
+// Empty tell if the string is considered empty once space
+// and not graphics characters are removed
+func Empty(s string) bool {
+ trim := strings.TrimFunc(s, func(r rune) bool {
+ return unicode.IsSpace(r) || !unicode.IsGraphic(r)
+ })
+
+ return trim == ""
+}
+
+// Safe will tell if a character in the string is considered unsafe
+// Currently trigger on unicode control character except \n, \t and \r
+func Safe(s string) bool {
+ for _, r := range s {
+ switch r {
+ case '\t', '\r', '\n':
+ continue
+ }
+
+ if unicode.IsControl(r) {
+ return false
+ }
+ }
+
+ return true
+}