Module: ReVIEW::TextUtils

Included in:
Book::Compilable, Builder, HTMLBuilder, IDGXMLBuilder, LATEXBuilder, Repository, TOPBuilder
Defined in:
lib/review/textutils.rb

Instance Method Summary collapse

Instance Method Details

#convert_inencoding(str, enc) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/review/textutils.rb', line 38

def convert_inencoding(str, enc)
  case enc
  when /^EUC$/i
    NKF.nkf("-E -w -m0x", str)
  when /^SJIS$/i
    NKF.nkf("-S -w -m0x", str)
  when /^JIS$/i
    NKF.nkf("-J -w -m0x", str)
  when /^UTF-8$/i
    NKF.nkf("-W -w -m0x", str)
  else
    NKF.nkf("-w -m0 -m0x", str)
  end
end

#convert_outencoding(str, enc) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/review/textutils.rb', line 53

def convert_outencoding(str, enc)
  case enc
  when /^EUC$/i
    NKF.nkf("-W -e -m0x", str)
  when /^SJIS$/i
    NKF.nkf("-W -s -m0x", str)
  when /^JIS$/i
    NKF.nkf("-W -j -m0x", str)
  else
    str
  end
end

#detab(str, ts = 8) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/review/textutils.rb', line 6

def detab(str, ts = 8)
  add = 0
  len = nil
  str.gsub(/\t/) {
    len = ts - ($`.size + add) % ts
    add += len - 1
    ' ' * len
  }
end

#split_paragraph(lines) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/review/textutils.rb', line 16

def split_paragraph(lines)
  pre = pre_paragraph
  post = post_paragraph

  blocked_lines = [[]]
  lines.each {|element|
    if element == ""
      if blocked_lines.last != []
        blocked_lines << []
      end
    else
      blocked_lines.last << element
    end
  }

  if !pre.nil? and !post.nil?
    blocked_lines.map!{|i| [pre] + i + [post] }
  end

  blocked_lines.map{|l| l.join("")}
end