rustgym/leetcode/
_1410_html_entity_parser.rs1struct Solution;
2
3impl Solution {
4 fn entity_parser(text: String) -> String {
5 text.replace(""", "\"")
6 .replace("'", "'")
7 .replace("⁄", "/")
8 .replace("<", "<")
9 .replace(">", ">")
10 .replace("&", "&")
11 }
12}
13
14#[test]
15fn test() {
16 let text = "& is an HTML entity but &ambassador; is not.".to_string();
17 let res = "& is an HTML entity but &ambassador; is not.".to_string();
18 assert_eq!(Solution::entity_parser(text), res);
19 let text = "and I quote: "..."".to_string();
20 let res = "and I quote: \"...\"".to_string();
21 assert_eq!(Solution::entity_parser(text), res);
22 let text = "Stay home! Practice on Leetcode :)".to_string();
23 let res = "Stay home! Practice on Leetcode :)".to_string();
24 assert_eq!(Solution::entity_parser(text), res);
25 let text = "x > y && x < y is always false".to_string();
26 let res = "x > y && x < y is always false".to_string();
27 assert_eq!(Solution::entity_parser(text), res);
28 let text = "leetcode.com⁄problemset⁄all".to_string();
29 let res = "leetcode.com/problemset/all".to_string();
30 assert_eq!(Solution::entity_parser(text), res);
31}