deltaFlow
Utils.H
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Saud Zahir
3 *
4 * This file is part of deltaFlow.
5 *
6 * deltaFlow is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * deltaFlow is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with deltaFlow. If not, see
18 * <https://www.gnu.org/licenses/>.
19 */
20
26#ifndef UTILS_H
27#define UTILS_H
28
29#include <filesystem>
30#include <string>
31
36namespace Utilities {
37
43 inline bool isCommonDataFormat(const std::string& filePath) {
44 auto ext = std::filesystem::path(filePath).extension();
45 return ext == ".cdf" || ext == ".txt";
46 }
47
53 inline bool isRawFormat(const std::string& filePath) {
54 return std::filesystem::path(filePath).extension() == ".raw";
55 }
56
62 inline std::string strip(const std::string& s) {
63 auto start = s.find_first_not_of(" \t\r\n");
64 if (start == std::string::npos) return "";
65 auto end = s.find_last_not_of(" \t\r\n");
66 return s.substr(start, end - start + 1);
67 }
68
74 inline std::string stripQuotes(const std::string& s) {
75 std::string t = strip(s);
76 if (t.size() >= 2 && t.front() == '\'' && t.back() == '\'')
77 return strip(t.substr(1, t.size() - 2));
78 return t;
79 }
80}
81
82#endif
Collection of utility functions.
bool isCommonDataFormat(const std::string &filePath)
Check if filepath is IEEE Common Data Format.
Definition Utils.H:43
std::string stripQuotes(const std::string &s)
Strip surrounding single quotes and whitespace from a string.
Definition Utils.H:74
bool isRawFormat(const std::string &filePath)
Check if filepath is PSS/E Raw format.
Definition Utils.H:53
std::string strip(const std::string &s)
Strip leading and trailing whitespace from a string.
Definition Utils.H:62