module Pangu

Constants

CJK_BRACKETFIX_RE
CJK_BRACKET_L_RE
CJK_BRACKET_RE
CJK_BRACKET_R_RE
CJK_HASH_L_RE
CJK_HASH_R_RE
CJK_L_RE
CJK_QUOTE_FIX_RE
CJK_QUOTE_L_RE
CJK_QUOTE_R_RE
CJK_R_RE
VERSION

Public Class Methods

spacing(text) click to toggle source
# File lib/pangu.rb, line 19
def self.spacing(text)
  text = text.dup

  text.gsub!(CJK_QUOTE_L_RE, "\\1 \\2")
  text.gsub!(CJK_QUOTE_R_RE, "\\1 \\2")
  text.gsub!(CJK_QUOTE_FIX_RE, "\\1\\3\\5")

  old_text = text
  new_text = old_text.gsub(CJK_BRACKET_RE, "\\1 \\2 \\4")
  text = new_text

  if old_text == new_text
    text.gsub!(CJK_BRACKET_L_RE, "\\1 \\2")
    text.gsub!(CJK_BRACKET_R_RE, "\\1 \\2")
  end

  text.gsub!(CJK_BRACKETFIX_RE, "\\1\\3\\5")

  text.gsub!(CJK_HASH_L_RE, "\\1 \\2")
  text.gsub!(CJK_HASH_R_RE, "\\1 \\3")

  text.gsub!(CJK_L_RE, "\\1 \\2")
  text.gsub!(CJK_R_RE, "\\1 \\2")

  text
end