Add ability to tweet published reports
When a report is automatically published, if a Twitter access token is
set, a Tweet will be published with the title of the report and a link
to the full report.
Change-Id: Ife68d49c4d04a40b1a41a964225fd47dd514d819
diff --git a/stringUtils.go b/stringUtils.go
new file mode 100644
index 0000000..791600e
--- /dev/null
+++ b/stringUtils.go
@@ -0,0 +1,23 @@
+package main
+
+func truncateStringWithEllipsis(s string, maxChars int) string {
+ if len(s) <= maxChars {
+ return s
+ }
+
+ // Find the last space within the maximum character limit
+ i := maxChars - 1
+ for ; i >= 0; i-- {
+ if s[i] == ' ' {
+ break
+ }
+ }
+
+ // If no space found, truncate to the maximum length minus the ellipsis length
+ if i < 0 {
+ return s[:maxChars-1] + "…"
+ }
+
+ // Truncate at the last space found
+ return s[:i] + "…"
+}