aboutsummaryrefslogtreecommitdiff
path: root/strings.go
diff options
context:
space:
mode:
Diffstat (limited to 'strings.go')
-rw-r--r--strings.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/strings.go b/strings.go
new file mode 100644
index 0000000..555f5dd
--- /dev/null
+++ b/strings.go
@@ -0,0 +1,35 @@
+package kagus
+
+import (
+ "strings"
+ "unicode"
+)
+
+// StringConsistsOf tests, if f returns true for all runes in s
+func StringConsistsOf(s string, f func(rune) bool) bool {
+ for _, r := range s {
+ if !f(r) {
+ return false
+ }
+ }
+ return true
+}
+
+// IsASCII tests, if a Rune is in the ASCII set
+func IsASCII(r rune) bool {
+ return (r <= unicode.MaxASCII)
+}
+
+// Indent a string s by prefixing each line with ind.
+func Indent(s string, ind string) (rv string) {
+ ls := strings.Split(s, "\n")
+ first := true
+ for _, l := range ls {
+ if !first {
+ rv += "\n"
+ }
+ rv += ind + l
+ first = false
+ }
+ return
+}