lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Austin Einter once stated:
> Hi All
> I have a string as below.
> 
> 
> 
> *INVITE\r\nContent-Length:\r\n*
> 
> *\r\n*
> 
> *v=0\r\n*
> I want to change it to as below
> 
> 
> 
> *INVITE\r\nContent-Length: 3\r\n*
> 
> *\r\n*
> 
> *v=0\r\n*
> You can see in line starts with Content-Length, I have added 5 at the end
> because after empty line I have only 5 characters (that is *v=0\r\n)*
> 
> I am looking for what is the best way to do that.
> The line *Content-Length:\r\n *can be of any form given below
> a)
> *Content-Length     :\r\n*
> *b) *
> *Content-Length:    \r\n*
> *c) **Content-Length     :      \r\n*
> 
> So you can any number of spaces can come anywhere around char *:* present
> in line
> 
> Can somebody kindly help what is the best way to do it in Lua 5.2

  It looks like you are doing similar stuff as to what I'm doing at work
(parsing SIP messages with SDP payloads).  I'm afraid I can't release that
code, but I can tell you I do the parsing with LPeg.

  I can also tell you that the header name *should* be parsed
case-insensitively---that is, all these are the same:

Content-Length: 2
Content-length: 2
CONTENT-LENGTH: 2
CoNtEnT-lEnGtH      :
	2
content-LENGTH   :    2

  -spc