Removes spaces in URL titles.

This is mainly used for Imgur.
This commit is contained in:
Fabien Freling 2014-12-12 23:20:51 +01:00
parent ff6b555372
commit 062fd87bf5
2 changed files with 22 additions and 2 deletions

View file

@ -11,10 +11,19 @@ let is_youtube_url url =
string_match regexp url 0
let remove_spaces str =
match str with
| Some s ->
let spaces = regexp "\\( *\\\n\\)+ *" in
Some (global_replace spaces "" s)
| None -> None
(* Maybe have a list of functions and
* iter on all the items in the list *)
let evaluate str =
match str with
| str when is_url str ->
SimpleHttp.get_http_title (SimpleHttp.get_body str)
SimpleHttp.get_http_title (SimpleHttp.get_body str) |> remove_spaces
| _ -> None

View file

@ -15,11 +15,22 @@ let test_get_title test_ctxt =
let title = SimpleHttp.get_http_title body in
assert_equal (Some "Fabien") title
let test_remove_spaces test_ctxt =
let str = "
foo bar baz
" in
let cleaned_str = Evaluate.remove_spaces str in
assert_equal "foo bar baz" cleaned_str
(* Name the test cases and group them together *)
let suite =
"suite">:::
["test get_title">:: test_get_title]
["test get_title">:: test_get_title;
"test remove_spaces">:: test_remove_spaces]
let () =
run_test_tt_main suite