MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ClassifyHyperlink

Function ClassifyHyperlink

src/textfile_gui.cpp:165–177  ·  view source on GitHub ↗

* Classify the type of hyperlink the destination describes. * * @param destination The hyperlink destination. * @param trusted Whether we trust the content of this file. * @return HyperlinkType The classification of the link. */

Source from the content-addressed store, hash-verified

163 * @return HyperlinkType The classification of the link.
164 */
165static HyperlinkType ClassifyHyperlink(const std::string &destination, bool trusted)
166{
167 if (destination.empty()) return HyperlinkType::Unknown;
168 if (destination.starts_with("#")) return HyperlinkType::Internal;
169
170 /* Only allow external / internal links for sources we trust. */
171 if (!trusted) return HyperlinkType::Unknown;
172
173 if (destination.starts_with("http://")) return HyperlinkType::Web;
174 if (destination.starts_with("https://")) return HyperlinkType::Web;
175 if (destination.starts_with("./")) return HyperlinkType::File;
176 return HyperlinkType::Unknown;
177}
178
179/**
180 * Create a valid slug for the anchor.

Callers 2

OnHyperlinkClickMethod · 0.85

Calls 1

emptyMethod · 0.45

Tested by

no test coverage detected