OSDN Git Service

fix
[luatex-ja/luatexja.git] / src / ltj-inputbuf.lua
1 --
2 -- ltj-inputbuf.lua
3 --
4
5 luatexja.load_module('base');      local ltjb = luatexja.base
6 luatexja.load_module('charrange'); local ltjc = luatexja.charrange
7
8 require("unicode")
9 local utflen = utf.len
10 local utfbyte = utf.byte
11 local utfchar = utf.char
12 local node_new = node.new
13 local node_free = node.free
14 local id_glyph = node.id('glyph')
15 local getcatcode, getcount = tex.getcatcode, tex.getcount
16 local ltjc_is_japanese_char_curlist = ltjc.is_japanese_char_curlist
17
18 --- the following function is modified from jafontspec.lua (by K. Maeda).
19 --- Instead of "%", we use U+FFFFF for suppressing spaces.
20 --DEBUG require"socket"
21 local time_line = 0
22 local start_time_measure, stop_time_measure
23    = ltjb.start_time_measure, ltjb.stop_time_measure
24 local function add_comment(buffer)
25    start_time_measure('inputbuf')
26    local i = utflen(buffer)
27    while (i>0) and (getcatcode(utfbyte(buffer, i))==1
28                  or getcatcode(utfbyte(buffer, i))==2) do
29       i=i-1
30    end
31    if i>0 then
32       local c = utfbyte(buffer, i)
33       if c>=0x80 then
34          local te = tex.endlinechar
35          -- Is the catcode of endline character is 5 (end-of-line)?
36          if (te ~= -1) and (getcatcode(te)==5) then
37             local ct = getcatcode(c)
38             if (ct==11) or (ct==12) then
39                local lec = getcount('ltjlineendcomment')
40                -- Is the catcode of \ltjlineendcomment (new comment char) is 14 (comment)?
41                if ltjc_is_japanese_char_curlist(c) and (getcatcode(lec)==14) then
42                   stop_time_measure('inputbuf')
43                   return buffer .. utfchar(lec)
44                end
45             end
46          end
47       end
48    end
49    stop_time_measure('inputbuf')
50    return buffer
51 end
52
53 luatexbase.add_to_callback('process_input_buffer',
54    add_comment,'ltj.process_input_buffer')
55
56 --EOF