| 112 | } |
| 113 | |
| 114 | std::string functions_to_elm_code(const std::vector<function_help> functions) |
| 115 | { |
| 116 | auto escape_backslashes = [](const std::string& str) -> std::string { |
| 117 | return fplus::replace_tokens( |
| 118 | std::string("\\"), std::string("\\\\"), str); |
| 119 | }; |
| 120 | auto escape_quotation_marks = [](const std::string& str) -> std::string { |
| 121 | return fplus::replace_tokens( |
| 122 | std::string("\""), std::string("\\\""), str); |
| 123 | }; |
| 124 | auto escape_newlines = [](const std::string& str) { |
| 125 | return fplus::replace_tokens( |
| 126 | std::string("\n"), std::string("\\n"), str); |
| 127 | }; |
| 128 | auto escape_special_characters = fplus::compose( |
| 129 | escape_backslashes, |
| 130 | escape_quotation_marks, |
| 131 | escape_newlines); |
| 132 | auto show_function = [&](const function_help& f) -> std::string { |
| 133 | std::string str; |
| 134 | str += std::string("{ name = \"") + f.name + "\""; |
| 135 | str += std::string(", signature = \"") + f.signature + "\""; |
| 136 | str += std::string(", documentation = \"") + escape_special_characters(f.documentation) + "\""; |
| 137 | str += std::string(", declaration = \"") + escape_special_characters(f.declaration) + "\" }"; |
| 138 | return str; |
| 139 | }; |
| 140 | |
| 141 | auto function_strings = fplus::transform(show_function, functions); |
| 142 | |
| 143 | const auto chunks = fplus::split_every(64, function_strings); |
| 144 | |
| 145 | std::string result; |
| 146 | result += "module Database exposing (..)\n\n\n"; |
| 147 | result += "type alias Function =\n"; |
| 148 | result += " { name : String\n"; |
| 149 | result += " , signature : String\n"; |
| 150 | result += " , documentation : String\n"; |
| 151 | result += " , declaration : String\n"; |
| 152 | result += " }\n\n\n"; |
| 153 | result += "functions : List Function\n"; |
| 154 | result += "functions =\n"; |
| 155 | |
| 156 | const auto show_chunk = [](const string_vec& strs) -> std::string { |
| 157 | std::string res; |
| 158 | res += " [ "; |
| 159 | res += fplus::join(std::string("\n , "), strs); |
| 160 | res += "\n ]"; |
| 161 | return res; |
| 162 | }; |
| 163 | |
| 164 | result += fplus::join( |
| 165 | std::string("\n ++\n"), |
| 166 | fplus::transform(show_chunk, chunks)); |
| 167 | return result; |
| 168 | } |
| 169 | |
| 170 | void print_duplicates(const string_vec& strs) |
| 171 | { |
no test coverage detected