Skip to content

Instantly share code, notes, and snippets.

@kmaed
Created September 29, 2012 20:28
Show Gist options
  • Save kmaed/3805112 to your computer and use it in GitHub Desktop.
Save kmaed/3805112 to your computer and use it in GitHub Desktop.
2012/09/17 の解答(!?)
%#! 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}
@kmaed
Copy link
Author

kmaed commented Sep 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment