跳到內文 跳到搜尋
方法
C
D
T

常數

UNICODE_VERSION = RbConfig::CONFIG["UNICODE_VERSION"]
 

實作支援的 Unicode 版本

執行個體 public 方法

compose(codepoints)

將已分解的字元組合成已組合的形式。

# File activesupport/lib/active_support/multibyte/unicode.rb, line 21
def compose(codepoints)
  codepoints.pack("U*").unicode_normalize(:nfc).codepoints
end

decompose(type, codepoints)

將已組合的字元分解成已分解的形式。

# File activesupport/lib/active_support/multibyte/unicode.rb, line 12
def decompose(type, codepoints)
  if type == :compatibility
    codepoints.pack("U*").unicode_normalize(:nfkd).codepoints
  else
    codepoints.pack("U*").unicode_normalize(:nfd).codepoints
  end
end

tidy_bytes(string, force = false)

以其 UTF-8 等值取代所有 ISO-8859-1 或 CP1252 字元,以產生有效的 UTF-8 字串。

傳入 true 將強制整理所有位元組,認為字串的編碼完全是 CP1252 或 ISO-8859-1。

# File activesupport/lib/active_support/multibyte/unicode.rb, line 30
def tidy_bytes(string, force = false)
  return string if string.empty? || string.ascii_only?
  return recode_windows1252_chars(string) if force
  string.scrub { |bad| recode_windows1252_chars(bad) }
end