diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-11-02 14:38:24 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-11-02 14:39:23 -0700 |
| commit | 307dea18815ba4a06a3098edb170d7ad90708815 (patch) | |
| tree | bce78eb28fa03c9939a92e08e47564afc984c988 /string2.moon | |
| parent | d0c3c57f7b25c8d912c426e48cb5ab09cd738f65 (diff) | |
Changed stub convention to (foo 1 baz 2) -> foo_1_baz instead of
foo_1_baz_2, removed "smext", made some cleanup changes.
Diffstat (limited to 'string2.moon')
| -rw-r--r-- | string2.moon | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/string2.moon b/string2.moon index d70abe6..e4ee482 100644 --- a/string2.moon +++ b/string2.moon @@ -26,6 +26,7 @@ string2 = { capitalized: => gsub(@, '%l', upper, 1) byte: byte, bytes: (i, j)=> {byte(@, i or 1, j or -1)} split: (sep)=> [chunk for i,chunk in isplit(@, sep)] + starts_with: (s)=> sub(@, 1, #s) == s lines: => [line for i,line in isplit(@, '\n')] line: (line_num)=> for i, line, start in isplit(@, '\n') @@ -41,10 +42,10 @@ string2 = { lines = {} for line in *@lines! while #line > maxlen - chunk = line\sub(1, maxlen) - split = chunk\find(' ', maxlen-buffer, true) or maxlen - chunk = line\sub(1, split) - line = line\sub(split+1, -1) + chunk = sub(line, 1, maxlen) + split = find(chunk, ' ', maxlen-buffer, true) or maxlen + chunk = sub(line, 1, split) + line = sub(line, split+1, -1) lines[#lines+1] = chunk lines[#lines+1] = line return table.concat(lines, "\n") @@ -77,15 +78,15 @@ string2 = { if c == ' ' then '_' else format("x%02X", byte(c)) - unless is_lua_id(str\match("^_*(.*)$")) + unless is_lua_id(match(str, "^_*(.*)$")) str = "_"..str return str -- from_lua_id(as_lua_id(str)) == str, but behavior is unspecified for inputs that -- did not come from as_lua_id() from_lua_id: (str)-> - unless is_lua_id(str\match("^_*(.*)$")) - str = str\sub(2,-1) + unless is_lua_id(match(str, "^_*(.*)$")) + str = sub(str,2,-1) str = gsub(str, "_", " ") str = gsub(str, "x([0-9A-F][0-9A-F])", (hex)-> char(tonumber(hex, 16))) return str |
