Created
September 29, 2012 20:28
-
-
Save kmaed/3805112 to your computer and use it in GitHub Desktop.
2012/09/17 の解答(!?)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%#! lualatex | |
\documentclass[a4paper]{article} | |
\def\length#1{% | |
\directlua{\unexpanded{ | |
require('lualibs-unicode') | |
local input = [[#1]] | |
local state = 'r' | |
% print(input) | |
for i = 1, utf.len(input) do | |
local r = utf.byte(utf.sub(input, i, i)) | |
if state == 'r' then | |
tex.write('*') | |
if tex.getcatcode(r) == 0 then state = 'csb' end | |
elseif state == 'csb' then | |
if tex.getcatcode(r) == 11 then state = 'cs' else state = 'r' end | |
elseif state == 'cs' then | |
if tex.getcatcode(r) == 10 then | |
state = 'r' | |
elseif tex.getcatcode(r) ~= 11 then | |
tex.write('*') | |
state = 'r' | |
end | |
end | |
end | |
}}} | |
\def\starxiii{*************} | |
\def\starxi{***********} | |
\begin{document} | |
\edef\result{\length{ \a {b\cd ef{g} }\h }} | |
\ifx\result\starxiii OK\else NG\fi | |
\edef\result{\length{{ }{ {}} {}}} | |
\ifx\result\starxi OK\else NG\fi | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://d.hatena.ne.jp/zrbabbler/20120917/1347856569