Skip to content

Commit

Permalink
Use more utf8 and binaries.
Browse files Browse the repository at this point in the history
Added z_html:truncate function.
Issue #9
  • Loading branch information
mworrell committed Jun 3, 2014
1 parent c929149 commit 7a045bd
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 473 deletions.
4 changes: 2 additions & 2 deletions src/z_convert.erl
Expand Up @@ -57,8 +57,8 @@


%% @doc Convert to lower case, strip surrounding whitespace.
-spec clean_lower(term()) -> string().
clean_lower(L) -> string:strip(z_string:to_lower(to_list(L))).
-spec clean_lower(binary()|list()|atom()) -> binary().
clean_lower(L) -> z_string:trim(z_string:to_lower(L)).


%% @doc Convert (almost) any value to a list.
Expand Down
4 changes: 2 additions & 2 deletions src/z_html.erl
Expand Up @@ -855,12 +855,12 @@ nl2br_bin(<<C, Post/binary>>, Acc) ->
%% @doc Given a HTML list, scrape all `<link>' elements and return their attributes. Attribute names are lowercased.
%% @spec scrape_link_elements(string()) -> [LinkAttributes]
scrape_link_elements(Html) ->
case re:run(Html, "<link[^>]+>", [global, caseless, {capture,all,list}]) of
case re:run(Html, "<link[^>]+>", [global, caseless, {capture,all,binary}]) of
{match, Elements} ->
F = fun(El) ->
H = iolist_to_binary(["<p>", El, "</p>"]),
{<<"p">>, [], [{_, Attrs, []}]} = mochiweb_html:parse(H),
[{z_string:to_lower(binary_to_list(K)),binary_to_list(V)} || {K,V} <- lists:flatten(Attrs)]
[{z_string:to_lower(K),V} || {K,V} <- lists:flatten(Attrs)]
end,
[F(El) || [El] <- Elements];
nomatch ->
Expand Down

0 comments on commit 7a045bd

Please sign in to comment.