Removes spaces in URL titles.
This is mainly used for Imgur.
This commit is contained in:
parent
ff6b555372
commit
062fd87bf5
|
@ -11,10 +11,19 @@ let is_youtube_url url =
|
||||||
string_match regexp url 0
|
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
|
(* Maybe have a list of functions and
|
||||||
* iter on all the items in the list *)
|
* iter on all the items in the list *)
|
||||||
let evaluate str =
|
let evaluate str =
|
||||||
match str with
|
match str with
|
||||||
| str when is_url str ->
|
| str when is_url str ->
|
||||||
SimpleHttp.get_http_title (SimpleHttp.get_body str)
|
SimpleHttp.get_http_title (SimpleHttp.get_body str) |> remove_spaces
|
||||||
| _ -> None
|
| _ -> None
|
||||||
|
|
|
@ -15,11 +15,22 @@ let test_get_title test_ctxt =
|
||||||
let title = SimpleHttp.get_http_title body in
|
let title = SimpleHttp.get_http_title body in
|
||||||
assert_equal (Some "Fabien") title
|
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 *)
|
(* Name the test cases and group them together *)
|
||||||
let suite =
|
let suite =
|
||||||
"suite">:::
|
"suite">:::
|
||||||
["test get_title">:: test_get_title]
|
["test get_title">:: test_get_title;
|
||||||
|
"test remove_spaces">:: test_remove_spaces]
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
run_test_tt_main suite
|
run_test_tt_main suite
|
||||||
|
|
Loading…
Reference in a new issue