diff options
author | Hans Hagen <pragma@wxs.nl> | 2014-07-09 10:26:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2014-07-09 10:26:00 +0200 |
commit | 305f6529b5970f953803716fb0e475c7f52ff3b5 (patch) | |
tree | cb12e68f1c1aa8e22a7a3f06bd7bc91f63add0b8 /tex/context/base/core-con.lua | |
parent | 19e6c5feec9f26dd796a135d3f2924b9b15a998a (diff) | |
download | context-305f6529b5970f953803716fb0e475c7f52ff3b5.tar.gz |
beta 2014.07.09 10:26
Diffstat (limited to 'tex/context/base/core-con.lua')
-rw-r--r-- | tex/context/base/core-con.lua | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/tex/context/base/core-con.lua b/tex/context/base/core-con.lua index 99f8fc652..343485ed2 100644 --- a/tex/context/base/core-con.lua +++ b/tex/context/base/core-con.lua @@ -6,6 +6,8 @@ if not modules then modules = { } end modules ['core-con'] = { license = "see context related readme files" } +-- todo: split into char-lan.lua and core-con.lua + --[[ldx-- <p>This module implements a bunch of conversions. Some are more efficient than their <l n='tex'/> counterpart, some are even @@ -979,17 +981,28 @@ end -- These are just helpers but not really for the tex end. Do we have to -- use translate here? -local character = lpeg.patterns.utf8character local whitespace = lpeg.patterns.whitespace -local word = (character-whitespace) / characters.upper * (character-whitespace)^1 -local spacing = whitespace^1 -local pattern_one = Cs(word * P(1)^1) -local pattern_all = Cs((word + spacing)^1) - -function converters.word (s) return s end -function converters.words(s) return s end -function converters.Word (s) return lpegmatch(pattern_one,s) end -function converters.Words(s) return lpegmatch(pattern_all,s) end +local word = lpeg.patterns.utf8uppercharacter^-1 * (1-whitespace)^1 +local pattern_one = Cs(whitespace^0 * word^-1 * P(1)^1) +local pattern_all = Cs((whitespace^1 + word)^1) + +function converters.word (s) return s end -- dummies for typos +function converters.words(s) return s end -- dummies for typos +function converters.Word (s) return lpegmatch(pattern_one,s) or s end +function converters.Words(s) return lpegmatch(pattern_all,s) or s end + +converters.upper = characters.upper +converters.lower = characters.lower + +-- print(converters.Word("foo bar")) +-- print(converters.Word(" foo bar")) +-- print(converters.Word("123 foo bar")) +-- print(converters.Word(" 123 foo bar")) + +-- print(converters.Words("foo bar")) +-- print(converters.Words(" foo bar")) +-- print(converters.Words("123 foo bar")) +-- print(converters.Words(" 123 foo bar")) -- -- |