diff options
Diffstat (limited to 'src/cowboy_bstr.erl')
-rw-r--r-- | src/cowboy_bstr.erl | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/src/cowboy_bstr.erl b/src/cowboy_bstr.erl index 0c1f66a..98d2cf7 100644 --- a/src/cowboy_bstr.erl +++ b/src/cowboy_bstr.erl @@ -1,4 +1,4 @@ -%% Copyright (c) 2011-2013, Loïc Hoguin <[email protected]> +%% Copyright (c) 2011-2014, Loïc Hoguin <[email protected]> %% %% Permission to use, copy, modify, and/or distribute this software for any %% purpose with or without fee is hereby granted, provided that the above @@ -12,7 +12,6 @@ %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -%% @doc Binary string manipulation. -module(cowboy_bstr). %% Binary strings. @@ -24,11 +23,9 @@ -export([char_to_lower/1]). -export([char_to_upper/1]). -%% @doc Capitalize a token. -%% %% The first letter and all letters after a dash are capitalized. %% This is the form seen for header names in the HTTP/1.1 RFC and -%% others. Note that using this form isn't required, as header name +%% others. Note that using this form isn't required, as header names %% are case insensitive, and it is only provided for use with eventual %% badly implemented clients. -spec capitalize_token(B) -> B when B::binary(). @@ -43,19 +40,14 @@ capitalize_token(<< C, Rest/bits >>, true, Acc) -> capitalize_token(<< C, Rest/bits >>, false, Acc) -> capitalize_token(Rest, false, << Acc/binary, (char_to_lower(C)) >>). -%% @doc Convert a binary string to lowercase. -spec to_lower(B) -> B when B::binary(). to_lower(B) -> << << (char_to_lower(C)) >> || << C >> <= B >>. -%% @doc Convert a binary string to uppercase. -spec to_upper(B) -> B when B::binary(). to_upper(B) -> << << (char_to_upper(C)) >> || << C >> <= B >>. -%% @doc Convert [A-Z] characters to lowercase. -%% @end -%% We gain noticeable speed by matching each value directly. -spec char_to_lower(char()) -> char(). char_to_lower($A) -> $a; char_to_lower($B) -> $b; @@ -85,7 +77,6 @@ char_to_lower($Y) -> $y; char_to_lower($Z) -> $z; char_to_lower(Ch) -> Ch. -%% @doc Convert [a-z] characters to uppercase. -spec char_to_upper(char()) -> char(). char_to_upper($a) -> $A; char_to_upper($b) -> $B; @@ -118,9 +109,7 @@ char_to_upper(Ch) -> Ch. %% Tests. -ifdef(TEST). - capitalize_token_test_() -> - %% {Header, Result} Tests = [ {<<"heLLo-woRld">>, <<"Hello-World">>}, {<<"Sec-Websocket-Version">>, <<"Sec-Websocket-Version">>}, @@ -131,5 +120,4 @@ capitalize_token_test_() -> {<<"Sec-WebSocket---Version">>, <<"Sec-Websocket---Version">>} ], [{H, fun() -> R = capitalize_token(H) end} || {H, R} <- Tests]. - -endif. |