Text read from a stream often needs whitespace cleanup before parsing.

normalization Normalize text near the read boundary so later logic can compare stable values.

Trim Record

line
trim_record.lua
Replay: real traced execution (multi-file project)
local line = "  name  "
local trimmed = string.match(line, "^%s*(.-)%s*$")

print("line=" .. line)
print("trimmed=" .. trimmed)
local line = "  role  "
local trimmed = string.match(line, "^%s*(.-)%s*$")

print("line=" .. line)
print("trimmed=" .. trimmed)
local line = "  city  "
local trimmed = string.match(line, "^%s*(.-)%s*$")

print("line=" .. line)
print("trimmed=" .. trimmed)
  1. line ← name , trimmed ← name

    1local line→   name   = "  name  " --@line="  role  ", "  city  "2local trimmed→ name = string.match(line  name  , "^%s*(.-)%s*$")34print("line=" .. line  name  )5print("trimmed=" .. trimmedname)
    outputline=  name
    trimmed=name
  1. line ← role , trimmed ← role

    1local line→   role   = "  role  "2local trimmed→ role = string.match(line  role  , "^%s*(.-)%s*$")34print("line=" .. line  role  )5print("trimmed=" .. trimmedrole)
    outputline=  role
    trimmed=role
  1. line ← city , trimmed ← city

    1local line→   city   = "  city  "2local trimmed→ city = string.match(line  city  , "^%s*(.-)%s*$")34print("line=" .. line  city  )5print("trimmed=" .. trimmedcity)
    outputline=  city
    trimmed=city