wxMaxima
Loading...
Searching...
No Matches
UrlDetection.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2026 Gunter Königsmann <wxMaxima@physikbuch.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
35#ifndef URLDETECTION_H
36#define URLDETECTION_H
37
38#include <wx/string.h>
39#include <functional>
40#include <vector>
41
42namespace wxm {
43
45struct UrlSpan {
46 size_t start;
47 size_t length;
48 bool operator==(const UrlSpan &o) const {
49 return start == o.start && length == o.length;
50 }
51};
52
69std::vector<UrlSpan> FindUrls(const wxString &text);
70
78bool IsLaunchableUrl(const wxString &url);
79
89wxString ProtectUrls(const wxString &text, std::vector<wxString> &urls);
90
92wxString RestoreUrls(const wxString &text, const std::vector<wxString> &urls,
93 const std::function<wxString(const wxString &)> &format);
94
95} // namespace wxm
96
97#endif // URLDETECTION_H
wxString RestoreUrls(const wxString &text, const std::vector< wxString > &urls, const std::function< wxString(const wxString &)> &format)
Undoes ProtectUrls(), writing each link as format(url) returns it.
Definition: UrlDetection.cpp:166
bool IsLaunchableUrl(const wxString &url)
Is this a link wxMaxima may hand to the web browser?
Definition: UrlDetection.cpp:140
wxString ProtectUrls(const wxString &text, std::vector< wxString > &urls)
Replaces every link in a text by a placeholder an exporter won't touch.
Definition: UrlDetection.cpp:148
std::vector< UrlSpan > FindUrls(const wxString &text)
Finds every http://, https:// and mailto: link in a piece of text.
Definition: UrlDetection.cpp:103
Where a link sits in a string: the index of its first character and its length.
Definition: UrlDetection.h:45