Modulo:mpiksubstrind

Dokumentado por ĉi tiu modulo povas esti kreata ĉe Modulo:mpiksubstrind/dokumentado

local ooo = {}
local function lfipickcsv (strcsvline, numxindex)
  local strelemento = ''
  local numypos  = 0
  local numlymyt = 0
  local numoc9ct  = 0
  local boovalidsf = false -- valid so far
  local boospc     = false -- flag for whitespace reduction feature
  local boousch    = false -- flag for found useful char when skipping element
  numlymyt = string.len(strcsvline)
  while true do -- iterate over elements in order to skip them
    if (numxindex==0) then
      boovalidsf = true
      break -- exit the outer loop
    end--if
    numxindex = numxindex - 1 -- below either skip success or give up
    boovalidsf = false -- preASSume guilt
    boousch = false
    while true do -- iterate through whtspc & chars mix looking for comma
          if (numypos>=numlymyt) then
            break -- end of string -> exit the inner loop, NOT found, give up
          end--if
          numypos = numypos + 1
          numoc9ct = string.byte (strcsvline,numypos,numypos)
          if ((numoc9ct<32) and (numoc9ct~=9)) then
            break -- EOL -> exit the inner loop, NOT found, give up
          end--if
          if ((numoc9ct>32) and (numoc9ct~=44)) then
            boousch = true -- found a valid char (empty field is an error)
          end--if
          if (numoc9ct==44) then
            boovalidsf = boousch -- good or bad
            break -- exit the inner loop, found a comma, this is good or bad
          end--if
    end--while
    if (not boovalidsf) then
      break -- exit the outer loop too, NOT found or empty field, give up
    end--if
  end--while
  if (boovalidsf) then
    boovalidsf = false -- preASSume guilt
    while true do -- iterate over chars skipping whitespace
          if (numypos>=numlymyt) then
            break -- end of string -> exit the loop, NOT found, give up
          end--if
          numypos = numypos + 1
          numoc9ct = string.byte (strcsvline,numypos,numypos)
          if ((numoc9ct<32) and (numoc9ct~=9)) then
            break -- EOL -> exit the inner loop, NOT found, give up
          end--if
          if (numoc9ct>32) then
            boovalidsf = (numoc9ct~=44) -- comma is bad here (empty field)
            break -- good or bad
          end--if
    end--while
  end--if
  if (boovalidsf) then
    while true do -- iterate over chars copying the found element
          if ((numoc9ct==32) or (numoc9ct==9)) then
            boospc = true
          else
            if (boospc) then
              strelemento = strelemento .. string.char (32,numoc9ct)
              boospc = false
            else
              strelemento = strelemento .. string.char (numoc9ct)
            end--if
          end--if
          if (numypos>=numlymyt) then
            break -- done
          end--if
          numypos = numypos + 1
          numoc9ct = string.byte (strcsvline,numypos,numypos)
          if ((numoc9ct==44) or ((numoc9ct<32) and (numoc9ct~=9))) then
            break -- done
          end--if
    end--while
end
return strelemento
end
function ooo.ek (arxframent)
  local arxourown = 0
  arxourown = arxframent.args
  return lfipickcsv (arxourown[1],tonumber(arxourown[2]))
end
return ooo