Skip to content

Commit 16cfb35

Browse files
committed
Simplify implementation of truncate_bytes
1 parent fbfde16 commit 16cfb35

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lib/babosa/identifier.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,10 @@ def truncate!(max)
171171
# "üéøá".to_identifier.truncate_bytes(3) #=> "ü"
172172
# @return String
173173
def truncate_bytes!(max)
174-
return to_s if bytesize <= max
175-
176-
curr = 0
177-
new = []
178-
each_char do |char|
179-
break if curr > max
180-
181-
curr += char.bytesize
182-
new << char if curr <= max
174+
truncate!(max)
175+
until bytesize <= max do
176+
chop!
183177
end
184-
@wrapped_string = new.join
185178
end
186179

187180
# Replaces whitespace with dashes ("-").

0 commit comments

Comments
 (0)