-------------------------------------------------------------------------------- -- Title: MIMEHeader.lua -- Description: Like a square peg in a round hole -- Author: Raphaël Szwarc http://alt.textdrive.com/lua/ -- Creation Date: February 1, 2005 -- Legal: Copyright (C) 2005 Raphaël Szwarc -------------------------------------------------------------------------------- -- import dependencies local LUObject = require( "LUObject" ) local LUMap = require( "LUMap" ) local LUString = require( "LUString" ) -- define the class local super = LUObject local self = super() function self:init( aContent ) self = super.init( self ) self._content = aContent return self end function self:content() return self._content end function self:key() if self._key == nil then local aContent = self:content() local anIndex = aContent:find( ":", 1, true ) or ( aContent:len() + 1 ) self._key = LUString:trim( aContent:sub( 1, anIndex - 1 ):lower() ) end return self._key end function self:value() if self._value == nil then local aContent = self:content() .. ";" local anIndex = aContent:find( ":", 1, true ) or 1 local anotherIndex = aContent:find( ";%s*([^%s=]+)%s*=(.-);" ) or aContent:len() self._value = LUString:trim( aContent:sub( anIndex + 1, anotherIndex - 1 ) ) end return self._value end function self:parameters() if self._parameters == nil then local aContent = self:content() .. ";" local someParameters = LUMap() for aKey, aValue in aContent:gmatch( "%s*([^%s=]+)%s*=(.-);" ) do aKey = LUString:trim( aKey ):lower() aValue = LUString:trim( aValue ) if aValue:sub( 1, 1 ) == "\"" then aValue = aValue:sub( 2, aValue:len() - 1 ) end someParameters:put( aKey, aValue ) end self._parameters = someParameters end return self._parameters end return self