summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/core-con.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2010-05-24 14:05:02 +0000
committerTaco Hoekwater <taco@elvenkind.com>2010-05-24 14:05:02 +0000
commit57ea7dad48fbf2541c04e434c31bde655ada3ac4 (patch)
tree1f8b43bc7cb92939271e1f5bec610710be69097f /Master/texmf-dist/tex/context/base/core-con.lua
parent6ee41e1f1822657f7f23231ec56c0272de3855e3 (diff)
here is context 2010.05.24 13:05
git-svn-id: svn://tug.org/texlive/trunk@18445 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/core-con.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/core-con.lua176
1 files changed, 138 insertions, 38 deletions
diff --git a/Master/texmf-dist/tex/context/base/core-con.lua b/Master/texmf-dist/tex/context/base/core-con.lua
index e13f68456b4..dca1c7d10cc 100644
--- a/Master/texmf-dist/tex/context/base/core-con.lua
+++ b/Master/texmf-dist/tex/context/base/core-con.lua
@@ -1,6 +1,6 @@
-if not modules then modules = { } end modules ['char-con'] = {
+if not modules then modules = { } end modules ['core-con'] = {
version = 1.001,
- comment = "companion to core-con.tex",
+ comment = "companion to core-con.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
@@ -16,7 +16,7 @@ slower but look nicer this way.</p>
local utf = unicode.utf8
-local floor, mod, date, time, concat = math.floor, math.mod, os.date, os.time, table.concat
+local floor, date, time, concat = math.floor, os.date, os.time, table.concat
local lower, format, rep = string.lower, string.format, string.rep
local texsprint, utfchar = tex.sprint, utf.char
local tonumber, tostring = tonumber, tostring
@@ -147,42 +147,64 @@ converters.chr = chr
converters.chrs = chrs
converters.maxchrs = maxchrs
-local function do_alphabetic(n,max,chr)
- if n > max then
- do_alphabetic(floor((n-1)/max),max,chr)
- n = (n-1)%max+1
- end
- characters.flush(chr(n))
-end
-
--~ more efficient but needs testing
--~
--~ local escapes = utffilters.private.escapes
--~
---~ local function do_alphabetic(n,max,chr)
+--~ local function do_alphabetic(n,mapping,chr)
+--~ local max = #mapping
--~ if n > max then
--~ do_alphabetic(floor((n-1)/max),max,chr)
--~ n = (n-1)%max+1
--~ end
---~ n = chr(n)
+--~ n = chr(n,mapping)
--~ texsprint(ctxcatcodes,escapes[n] or utfchar(n))
--~ end
--~ local lccodes, uccodes = characters.lccode, characters.uccode
-local function lowercased(n) return characters.lccode(code[n] or fallback) end
-local function uppercased(n) return characters.uccode(code[n] or fallback) end
+--~ local function do_alphabetic(n,mapping,chr)
+--~ local max = #mapping
+--~ if n > max then
+--~ do_alphabetic(floor((n-1)/max),mapping,chr)
+--~ n = (n-1)%max+1
+--~ end
+--~ characters.flush(chr(n,mapping))
+--~ end
+--~
+--~ local function lowercased(n,mapping) return characters.lccode(mapping[n] or fallback) end
+--~ local function uppercased(n,mapping) return characters.uccode(mapping[n] or fallback) end
+--~
+--~ function converters.alphabetic(n,code)
+--~ do_alphabetic(n,counters[code] or counters['**'],lowercased) -- lccode catches wrong tables
+--~ end
+--~
+--~ function converters.Alphabetic(n,code)
+--~ do_alphabetic(n,counters[code] or counters['**'],uppercased)
+--~ end
+
+--
+
+local function do_alphabetic(n,mapping,mapper)
+ local chr = mapper(mapping[n] or fallback)
+ local max = #mapping
+ if n > max then
+ do_alphabetic(floor((n-1)/max),mapping,mapper)
+ n = (n-1)%max+1
+ end
+ characters.flush(chr)
+end
function converters.alphabetic(n,code)
- local code = counters[code] or counters['**']
- do_alphabetic(n,#code,lowercased) -- lccode catches wrong tables
+ do_alphabetic(n,counters[code] or counters['**'],characters.lccode)
end
function converters.Alphabetic(n,code)
- local code = counters[code] or counters['**']
- do_alphabetic(n,#code,uppercased)
+ do_alphabetic(n,counters[code] or counters['**'],characters.uccode)
end
+--
+
function converters.character (n) chr (n,96) end
function converters.Character (n) chr (n,64) end
function converters.characters(n) chrs(n,96) end
@@ -274,10 +296,10 @@ function converters.toabjad(n,what)
return medium[n]
else
local a, b, c, d
- a, n = floor(n/1000), mod(n,1000)
- b, n = floor(n/ 100), mod(n, 100)
- c, n = floor(n/ 10), mod(n, 10)
- d, n = floor(n/ 1), mod(n, 1)
+ a, n = floor(n/1000), n % 1000 -- mod(n,1000)
+ b, n = floor(n/ 100), n % 100 -- mod(n, 100)
+ c, n = floor(n/ 10), n % 10 -- mod(n, 10)
+ d, n = floor(n/ 1), n % 1 -- mod(n, 1)
return (large[4][a] or "") .. (large[3][b] or "") .. (large[2][c] or "") .. (large[1][d] or "")
end
end
@@ -287,7 +309,7 @@ function converters.abjadnodotnumerals(n) return texsprint(converters.toabjad(n,
local vector = {
normal = {
- [0] = "○",
+ [0] = "〇",
[1] = "一",
[2] = "二",
[3] = "三",
@@ -321,7 +343,7 @@ local vector = {
[100000000] = "亿",
},
all = {
- [0] = "○",
+ [0] = "〇",
[1] = "一",
[2] = "二",
[3] = "三",
@@ -341,7 +363,63 @@ local vector = {
}
}
+--~ function tochinese(n,name) -- normal, caps, all
+--~ local result = { }
+--~ local vector = vector[name] or vector.normal
+--~ while true do
+--~ if n == 0 then
+--~ break
+--~ elseif n >= 100000000 then
+--~ local m = floor(n/100000000)
+--~ if m > 1 then result[#result+1] = tochinese(m) end
+--~ result[#result+1] = vector[100000000]
+--~ n = n % 100000000
+--~ elseif n >= 10000000 then
+--~ result[#result+1] = tochinese(floor(n/10000))
+--~ result[#result+1] = vector[10000]
+--~ n = n % 10000
+--~ elseif n >= 1000000 then
+--~ result[#result+1] = tochinese(floor(n/10000))
+--~ result[#result+1] = vector[10000]
+--~ n = n % 10000
+--~ elseif n >= 100000 then
+--~ result[#result+1] = tochinese(floor(n/10000))
+--~ result[#result+1] = vector[10000]
+--~ n = n % 10000
+--~ elseif n >= 10000 then
+--~ local m = floor(n/10000)
+--~ if m > 1 then result[#result+1] = vector[m] end
+--~ result[#result+1] = vector[10000]
+--~ n = n % 10000
+--~ elseif n >= 1000 then
+--~ local m = floor(n/1000)
+--~ if m > 1 then result[#result+1] = vector[m] end
+--~ result[#result+1] = vector[1000]
+--~ n = n % 1000
+--~ elseif n >= 100 then
+--~ local m = floor(n/100)
+--~ if m > 1 then result[#result+1] = vector[m] end
+--~ result[#result+1] = vector[100]
+--~ n = n % 100
+--~ elseif n >= 10 then
+--~ local m = floor(n/10)
+--~ if vector[m*10] then
+--~ result[#result+1] = vector[m*10]
+--~ else
+--~ result[#result+1] = vector[m]
+--~ result[#result+1] = vector[10]
+--~ end
+--~ n = n % 10
+--~ else
+--~ result[#result+1] = vector[n]
+--~ break
+--~ end
+--~ end
+--~ return concat(result)
+--~ end
+
function tochinese(n,name) -- normal, caps, all
+ -- improved version by Li Yanrui
local result = { }
local vector = vector[name] or vector.normal
while true do
@@ -349,39 +427,56 @@ function tochinese(n,name) -- normal, caps, all
break
elseif n >= 100000000 then
local m = floor(n/100000000)
- if m > 1 then result[#result+1] = tochinese(m) end
+ result[#result+1] = tochinese(m,name)
result[#result+1] = vector[100000000]
+ local z = n - m * 100000000
+ if z > 0 and z < 10000000 then result[#result+1] = vector[0] end
n = n % 100000000
elseif n >= 10000000 then
- result[#result+1] = tochinese(floor(n/10000))
+ local m = floor(n/10000)
+ result[#result+1] = tochinese(m,name)
result[#result+1] = vector[10000]
+ local z = n - m * 10000
+ if z > 0 and z < 1000 then result[#result+1] = vector[0] end
n = n % 10000
elseif n >= 1000000 then
- result[#result+1] = tochinese(floor(n/10000))
+ local m = floor(n/10000)
+ result[#result+1] = tochinese(m,name)
result[#result+1] = vector[10000]
+ local z = n - m * 10000
+ if z > 0 and z < 1000 then result[#result+1] = vector[0] end
n = n % 10000
elseif n >= 100000 then
- result[#result+1] = tochinese(floor(n/10000))
+ local m = floor(n/10000)
+ result[#result+1] = tochinese(m,name)
result[#result+1] = vector[10000]
+ local z = n - m * 10000
+ if z > 0 and z < 1000 then result[#result+1] = vector[0] end
n = n % 10000
- elseif n >= 10000 then
+ elseif n >= 10000 then
local m = floor(n/10000)
- if m > 1 then result[#result+1] = vector[m] end
+ result[#result+1] = vector[m]
result[#result+1] = vector[10000]
+ local z = n - m * 10000
+ if z > 0 and z < 1000 then result[#result+1] = vector[0] end
n = n % 10000
- elseif n >= 1000 then
+ elseif n >= 1000 then
local m = floor(n/1000)
- if m > 1 then result[#result+1] = vector[m] end
+ result[#result+1] = vector[m]
result[#result+1] = vector[1000]
+ local z = n - m * 1000
+ if z > 0 and z < 100 then result[#result+1] = vector[0] end
n = n % 1000
- elseif n >= 100 then
+ elseif n >= 100 then
local m = floor(n/100)
- if m > 1 then result[#result+1] = vector[m] end
+ result[#result+1] = vector[m]
result[#result+1] = vector[100]
+ local z = n - m * 100
+ if z > 0 and z < 10 then result[#result+1] = vector[0] end
n = n % 100
- elseif n >= 10 then
+ elseif n >= 10 then
local m = floor(n/10)
- if vector[m*10] then
+ if m > 1 and vector[m*10] then
result[#result+1] = vector[m*10]
else
result[#result+1] = vector[m]
@@ -393,10 +488,15 @@ function tochinese(n,name) -- normal, caps, all
break
end
end
+ if (result[1] == vector[1] and result[2] == vector[10]) then
+ result[1] = ""
+ end
return concat(result)
end
---~ for k, v in ipairs { 1,10,15,25,35,45,11,100,111,1111,10000,11111,100000,111111,1111111,11111111,111111111,100000000,1111111111,11111111111,111111111111,1111111111111 } do
+--~ local t = { 1,10,15,25,35,45,11,100,111,1111,10000,11111,100000,111111,1111111,11111111,111111111,100000000,1111111111,11111111111,111111111111,1111111111111 }
+--~ for k=1,#t do
+--~ local v = t[k]
--~ print(v,tochinese(v),tochinese(v,"all"),tochinese(v,"cap"))
--~ end