This commit is contained in:
end-4
2024-02-22 15:35:06 +07:00
commit 8db26e9707
4220 changed files with 208544 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
#!/bin/python3
import sys
def limit_length(s, newlength):
# Use len() function to get number of characters in s
char_count = 0
newstr = ''
# Use unicodedata.east_asian_width() function to check for double-width characters
import unicodedata
for c in s:
char_count += 1
if unicodedata.east_asian_width(c) == 'W':
char_count += 1
if char_count <= newlength:
newstr += c
else:
newstr = newstr + '...'
break
# Add double-width count to character count to get display length
return newstr
original = sys.argv[1]
newlen = int(sys.argv[2])
newstr = limit_length(original, newlen)
print(newstr)