I
Iñaki Baz Castillo
Hi, I receive headers (the protocol syntax allows them being lowcase,
upcase or a mix). For example, the following header names are
equivalent:
a) Record-Route
b) record-route
c) RECORD-ROUTE
d) Record-ROUTE
I'm trying to do a method to convert all of them to:
Record-Route
Basically what I need is to capitalize all the header name parts after
splitting it using "-" as separator. I can do it as follows:
------------
hname =3D "Record-ROUTE"
hname.split("-").map {|w| w.capitalize }.join("-") } =3D> "Record-Route"
------------
Benchmark.realtime { hname.split("-").map {|w| w.capitalize }.join("-") }
1.69277191162109e-05
Is there any option even faster? I think it would be faster if I
operate directly in the original string instead of doing "split" and
"join" (since these last methods create more strings so allocate
memory for them and so). I would prefer to do the modification "in
place".
BTW, could I know how to convert "a" char into "A"? I expected
something as in c:
'a' + 1 =3D> 'b'
'a' + =C2=BFX? =3D> 'A'
but in Ruby#String I just find String#next which just increment the
char in one unit ("a".next =3D> "b").
Any suggestion? Thanks a lot.
Thanks a lot.
--=20
I=C3=B1aki Baz Castillo
<[email protected]>
upcase or a mix). For example, the following header names are
equivalent:
a) Record-Route
b) record-route
c) RECORD-ROUTE
d) Record-ROUTE
I'm trying to do a method to convert all of them to:
Record-Route
Basically what I need is to capitalize all the header name parts after
splitting it using "-" as separator. I can do it as follows:
------------
hname =3D "Record-ROUTE"
hname.split("-").map {|w| w.capitalize }.join("-") } =3D> "Record-Route"
------------
Benchmark.realtime { hname.split("-").map {|w| w.capitalize }.join("-") }
1.69277191162109e-05
Is there any option even faster? I think it would be faster if I
operate directly in the original string instead of doing "split" and
"join" (since these last methods create more strings so allocate
memory for them and so). I would prefer to do the modification "in
place".
BTW, could I know how to convert "a" char into "A"? I expected
something as in c:
'a' + 1 =3D> 'b'
'a' + =C2=BFX? =3D> 'A'
but in Ruby#String I just find String#next which just increment the
char in one unit ("a".next =3D> "b").
Any suggestion? Thanks a lot.
Thanks a lot.
--=20
I=C3=B1aki Baz Castillo
<[email protected]>