-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCommonFunctions.cpp
More file actions
62 lines (54 loc) · 1.27 KB
/
CommonFunctions.cpp
File metadata and controls
62 lines (54 loc) · 1.27 KB
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
62
#include "CommonFunctions.h"
#include "OSCompatibilityLayer.h"
#include <algorithm>
#include <array>
std::string replaceCharacter(std::string fileName, const char character)
{
std::ranges::replace(fileName, character, '_');
return fileName;
}
std::string cardinalToOrdinal(const int cardinal)
{
const auto hundredRemainder = cardinal % 100;
const auto tenRemainder = cardinal % 10;
if (hundredRemainder - tenRemainder == 10)
{
return "th";
}
switch (tenRemainder)
{
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}
std::string cardinalToRoman(int number)
{
const std::array numbers{1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
const std::array symbols{"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"};
int i = static_cast<int>(numbers.size()) - 1;
std::string toReturn;
while (number > 0)
{
auto div = number / numbers[i];
number = number % numbers[i];
while (div-- > 0)
{
toReturn += symbols[i];
}
i--;
}
return toReturn;
}
std::string normalizeStringPath(const std::string& stringPath)
{
auto toReturn = commonItems::normalizeUTF8Path(stringPath);
toReturn = replaceCharacter(toReturn, '-');
toReturn = replaceCharacter(toReturn, ' ');
return toReturn;
}