Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
trim.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
14#ifndef SEEN_TRIM_H
15#define SEEN_TRIM_H
16
17#include <glibmm/ustring.h>
18#include <glibmm/regex.h>
19
20namespace Inkscape {
21namespace Util {
22
34inline void trim(Glib::ustring &input, Glib::ustring const &also_remove = "")
35{
36 auto const regex = Glib::Regex::create(Glib::ustring("^[\\s") + also_remove + "]*(.+?)[\\s"
37 + also_remove + "]*$");
38 Glib::MatchInfo match_info;
39 regex->match(input, match_info);
40 if (!match_info.matches()) {
41 input.clear();
42 return;
43 }
44 input = match_info.fetch(1);
45}
46
47} // namespace Util
48} // namespace Inkscape
49
50#endif // SEEN_TRIM_H
51/*
52 Local Variables:
53 mode:c++
54 c-file-style:"stroustrup"
55 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
56 indent-tabs-mode:nil
57 fill-column:99
58 End:
59*/
60// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Miscellaneous supporting code.
Definition document.h:93
void trim(Glib::ustring &input, Glib::ustring const &also_remove="")
Modifies a string in place, removing leading and trailing whitespace characters.
Definition trim.h:34
Helper class to stream background task notifications as a series of messages.