No commit activity in last 3 years
No release in over 3 years
helper method for truncate chinese string. 1 chinese word = 2 byte.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

chinese_truncate

helper method for truncate chinese string. 1 chinese word = 2 byte.

Install

$ gem install chinese_truncate

Usage

require 'chinese_truncate'

str = "中文 a和d english"

puts str.chinese_size                         # => 9

puts str.chinese_bytesize                     # => 17

puts str.is_chinese_shorter(8)                # => false

puts str.is_chinese_longer(8)                 # => 13 (not true)

puts str.chinese_truncate(8)                  # => 中文 a和d eng...

puts str.chinese_truncate(8, omission:'???')  # => 中文 a和d eng???

puts str.chinese_truncate(8, omission:false)  # => 中文 a和d englis

puts str.chinese_truncate(9)                  # => 中文 a和d english

puts str.chinese_truncate(10)                 # => 中文 a和d english