forked from ParadoxGameConverters/commonItems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommonFunctions.h
61 lines (31 loc) · 2.07 KB
/
CommonFunctions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef COMMON_FUNCTIONS_H
#define COMMON_FUNCTIONS_H
// A handful of helpful commonly-used functions.
#include <string>
namespace commonItems
{
constexpr auto utf8BOM = "\xEF\xBB\xBF";
} // namespace commonItems
// Given a file with path included (such as '/this/is/a/path.txt' or 'c:\this\is\a\path.txt'), returns the part that's just the filename ('path.txt')
std::string trimPath(const std::string& fileName);
// Given a file with path included (such as '/this/is/a/path.txt' or 'c:\this\is\a\path.txt'), returns the part that's just the path ('/this/is/a/' or
// 'c:\this\is\a\')
std::string getPath(const std::string& fileName);
// Given a filename with an extension (such as 'file.extension' or 'file.name.with.extension'), returns the extension ('extension')
std::string trimExtension(const std::string& fileName);
// Given a filename with an extension (such as 'file.extension' or 'file.name.with.extension'), returns the filename ('file' or 'file.name.with')
std::string getExtension(const std::string& fileName);
// Given a string (such as 'a file name.eu4'), replaces all instances of the specified character (such as ' ') with underscores (resulting in 'a_file_name.eu4')
std::string replaceCharacter(std::string fileName, char character);
// Given a cardinal number (1, 2, 15), returns the equivalent ordinal word ending ('st', 'nd', 'th') for appending to the numbers ('1st', '2nd', '15th')
std::string cardinalToOrdinal(int cardinal);
[[deprecated("Use cardinalToOrdinal (lower case 'c')")]] inline std::string CardinalToOrdinal(const int cardinal)
{
return cardinalToOrdinal(cardinal);
}
// Given a number (3, 12, 2020), returns the number in roman numerals ('III', 'XII', 'MMXX')
std::string cardinalToRoman(int number);
// Given a path, normalizes it in a standard way for all converters that all supported Paradox games will recognize (by replacing all spaces, dashes, and other
// weird characters (<, >, :, ?...) with underscores, and by converting entire string into ASCII)
std::string normalizeStringPath(const std::string& stringPath);
#endif // COMMON_FUNCTIONS_H