OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_utils.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2019 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef OCPN_UTILS_H_
25#define OCPN_UTILS_H_
26
27#include <string>
28#include <vector>
29
31namespace ocpn {
32
34bool endswith(const std::string& s, const std::string& suffix);
35
37bool startswith(const std::string& s, const std::string& prefix);
38
43std::string ltrim(const std::string& s);
44
49std::string rtrim(const std::string& s);
50
55std::string trim(std::string s);
56
61std::string join(std::vector<std::string> v, char c);
62
64std::string tolower(const std::string& s);
65
67std::vector<std::string> split(const char* s, const std::string& delimiter);
68
70std::vector<std::string> split(const std::string& s,
71 const std::string& delimiter);
72
74bool exists(const std::string& path);
75
77void mkdir(const std::string path);
78
83bool replace(std::string& str, const std::string& from, const std::string& to);
84
86void copy_file(const std::string& src_path, const std::string& dest_path);
87
93bool N0183CheckSumOk(const std::string& sentence);
94
96std::string printable(const std::string& str);
97
98} // namespace ocpn
99
100#endif // OCPN_UTILS_H_
Standard, mostly strings utilities.
Definition datetime.cpp:39
bool replace(std::string &str, const std::string &from, const std::string &to)
Perform in place substitution in str, replacing "from" with "to".
bool startswith(const std::string &str, const std::string &prefix)
Return true if s starts with given prefix.
std::string tolower(const std::string &input)
Return copy of s with all characters converted to lower case.
std::string printable(const std::string &str)
Return copy of str with non-printable chars replaced by hex like "<0D>".
std::vector< std::string > split(const char *token_string, const std::string &delimiter)
Return vector of items in s separated by delimiter.
std::string trim(std::string s)
Strip possibly trailing and/or leading space characters in s.
std::string rtrim(const std::string &arg)
Strip possibly trailing space characters in s.
bool endswith(const std::string &str, const std::string &suffix)
Return true if s ends with given suffix.
std::string ltrim(const std::string &arg)
Strip possibly leading space characters in s.
void copy_file(const std::string &src_path, const std::string &dest_path)
Copy file contents in path src_path to dest_path.
bool exists(const std::string &name)
bool N0183CheckSumOk(const std::string &sentence)
Check if checksum in a NMEA0183 sentence is correct.
std::string join(std::vector< std::string > v, char c)
Return a single string being the concatenation of all elements in v with character c in between.
void mkdir(const std::string path)