GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - moteus/lua-split: Implement functions to split strings

BranchesTags
Open more actions menu

Latest commit

 

History

16 Commits
16 Commits

Folders and files

NameName
Last commit message
Last commit date
.travis
.travis
 
 
rockspecs
rockspecs
 
 
src
src
 
 
test
test
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

Lua-Split

Build Status Coverage Status Licence


Functions

split(str, [sep, [plain])

Split string and returns array

t = split('aaa;bbb', ';', true)
-- t = {'aaa', 'bbb'}

unpack(str, [sep, [plain])

Split string and returns result as multiple values

a, b = split.unpack('aaa;bbb', ';', true)
-- a = 'aaa' b = 'bbb'

first(str, [sep, [plain])

Split first substring result as 2 values

key, val = split.first('pass=hello=world', '=', true)
-- key = 'pass' val = 'hello=world'

each(str, [sep, [plain])

Create iterator to iterate over substrings

for word in split.each('hello world', '%s') do
  print(word)
end

Example

-- decode header value like:
-- `value1;key1=1;key2=2,value2;key1=1;key2=2`
-- result:
-- {
--   {value1,{key=1,key2=2}};
--   {value2,{key=1,key2=2}};
-- }
function decode_header(str)
  local res = {}
  for ext in split.each(str, "%s*,%s*") do
    local name, tail = split.first(ext, '%s*;%s*')
    if #name > 0 then
      local opt  = {}
      if tail then
        for param in split.each(tail, '%s*;%s*') do
          local k, v = split.first(param, '%s*=%s*')
          opt[k] = v
        end
      end
      res[#res + 1] = {name, opt}
    end
  end
  return res
end

About

Implement functions to split strings

Topics

luasplit-stringstring

Resources

Readme
MIT license
Activity

Stars

13 stars

Watchers

1 watching

Forks

4 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.