summaryrefslogtreecommitdiff
path: root/lib/pleroma/formatter.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/formatter.ex')
-rw-r--r--lib/pleroma/formatter.ex21
1 files changed, 6 insertions, 15 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex
index 49f7075e6..63e0acb21 100644
--- a/lib/pleroma/formatter.ex
+++ b/lib/pleroma/formatter.ex
@@ -184,21 +184,12 @@ defmodule Pleroma.Formatter do
end)
end
- def truncate(text, opts \\ []) do
- max_length = opts[:max_length] || 200
- omission = opts[:omission] || "..."
-
- cond do
- not String.valid?(text) ->
- text
-
- String.length(text) < max_length ->
- text
-
- true ->
- length_with_omission = max_length - String.length(omission)
-
- "#{String.slice(text, 0, length_with_omission)}#{omission}"
+ def truncate(text, max_length \\ 200, omission \\ "...") do
+ if String.length(text) < max_length do
+ text
+ else
+ length_with_omission = max_length - String.length(omission)
+ String.slice(text, 0, length_with_omission) <> omission
end
end
end