File: sosi2osm.lua

package info (click to toggle)
sosi2osm 1.0.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 240 kB
  • sloc: cpp: 442; makefile: 26; sh: 11
file content (52 lines) | stat: -rw-r--r-- 1,299 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function tokens(state, i)
	i = i+1
	local line = info[i]

	if line == nil then return end

    local indent = 0
    while line:byte() == 46 do
        line = line:sub(2)
        indent = indent +1
    end
    
    if indent == 1 then line = line:sub(1, -2) end
    
    local tokens = {}
    for x in string.gmatch(line, "(%S+)") do
        if #tokens > 0 and string.byte(tokens[#tokens]) == 34 then
            tokens[#tokens] = table.concat({tokens[#tokens], x}, " ")
        else
            tokens[#tokens+1] = x
        end
        
        if #tokens[#tokens] > 1
            and string.byte(tokens[#tokens], 1) == 34
            and string.byte(tokens[#tokens], -1) == 34 then
            tokens[#tokens] = tokens[#tokens]:sub(2, -2)
        end
    end
    return i, indent, tokens
end

-- Lower with q&d support for norwegian letters
function norwegian_lower(text)
	text = string.lower(text)
	text = string.gsub(text, "Æ", "æ")
	text = string.gsub(text, "Ø", "ø")
	text = string.gsub(text, "Å", "å")
	return text
end

function initcase(text)
	text = string.gsub(text, "(([^%s-][\128-\191]*)([^%s-]*))", function (word,initial,rest)
		if word == "I" or word == "PÅ" then
			return norwegian_lower(word)
		else
			return initial .. norwegian_lower(rest)
		end
	end)

	return text
end