Skip to content

Commit 0e23c29

Browse files
authored
Add translations (#40)
2 parents 1ddbb46 + d782ce4 commit 0e23c29

File tree

107 files changed

+3271
-636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+3271
-636
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
*.jpeg filter=lfs diff=lfs merge=lfs -text
22
*.svg filter=lfs diff=lfs merge=lfs -text
3+
4+
# Steppable translations
5+
res/translations/*.stp_strings linguist-generated=true linguist-language=Bash
6+
res/translations/**/*.stp_localized linguist-generated=true linguist-language=Bash

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"files.associations": {
3+
".cmake-format": "python",
34
"array": "cpp",
45
"string_view": "cpp",
56
"any": "cpp",
@@ -57,7 +58,8 @@
5758
"streambuf": "cpp",
5859
"typeinfo": "cpp",
5960
"variant": "cpp",
60-
"fstream": "cpp"
61+
"fstream": "cpp",
62+
"__node_handle": "cpp"
6163
},
6264
"copyrightInserter.holder": "NWSOFT",
6365
"copyrightInserter.license": "mit",
@@ -68,7 +70,6 @@
6870
"editor.cursorBlinking": "smooth",
6971
"editor.cursorSmoothCaretAnimation": "on",
7072
"editor.cursorStyle": "line",
71-
"clangd.path": "/usr/bin/clangd",
7273
"C_Cpp.clang_format_path": "clang-format-17",
7374
"C_Cpp.codeAnalysis.clangTidy.path": "clang-tidy-17",
7475
"files.exclude": {

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ COMPONENTS Development Interpreter
3737
REQUIRED)
3838

3939
SET(CMAKE_CXX_STANDARD 20)
40+
SET(CMAKE_C_STANDARD 20)
4041
SET(CMAKE_CXX_EXTENSIONS OFF)
4142
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
4243

@@ -104,7 +105,7 @@ SET(COMPONENTS
104105
# NEW_COMPONENT: PATCH Do NOT remove the previous comment.
105106

106107
SET(TARGETS ${COMPONENTS} util)
107-
SET(TEST_TARGETS_TEMP util fraction number factors ${COMPONENTS})
108+
SET(TEST_TARGETS_TEMP util fraction number factors format ${COMPONENTS})
108109

109110
FOREACH(TEST_TARGET IN LISTS TEST_TARGETS_TEMP)
110111
SET(TARGET_NAME "test")

include/argParse.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
#include <map>
4141
#include <regex>
42-
#include <string_view>
42+
#include <string>
4343
#include <unordered_map>
4444
#include <vector>
4545

@@ -50,15 +50,15 @@
5050
namespace steppable::__internals::utils
5151
{
5252
/// @brief This is the type of the positional arguments. It is equivalent to a vector of string_views.
53-
using PosArgs = std::vector<std::string_view>;
53+
using PosArgs = std::vector<std::string>;
5454

5555
/// @brief This is the correct format of a keyword argument.
5656
// language=RegExp
57-
[[maybe_unused]] const std::regex KEYWORD_ARG_REGEX(R"(^-([a-zA-Z]*):(-?[0-9]+)$)");
57+
[[maybe_unused]] const std::regex KEYWORD_ARG_REGEX(R"(^-([a-zA-Z]*):(-?[0-9]+)$)"); // NOLINT(cert-err58-cpp)
5858

5959
/// @brief This is the correct format of a switch.
6060
// language=RegExp
61-
[[maybe_unused]] const std::regex SWITCH_REGEX(R"(^([-+])([a-zA-Z]*)$)");
61+
[[maybe_unused]] const std::regex SWITCH_REGEX(R"(^([-+])([a-zA-Z]*)$)"); // NOLINT(cert-err58-cpp)
6262

6363
/**
6464
* @class ProgramArgs
@@ -82,33 +82,33 @@ namespace steppable::__internals::utils
8282
/** @brief This map is used to store the information of all switches specified. Keys are switch names, and
8383
* values are whether the switch is enabled.
8484
*/
85-
std::unordered_map<std::string_view, bool> switches;
85+
std::unordered_map<std::string, bool> switches;
8686
/// @brief This map is used to store the descriptions of all switches specified.
87-
std::map<std::string_view, std::string_view> switchDescriptions;
87+
std::map<std::string, std::string> switchDescriptions;
8888

8989
/// @brief This vector is used to store the values of all positional arguments specified.
90-
std::vector<std::string_view> posArgs; // Names are used for error messages only.
90+
std::vector<std::string> posArgs; // Names are used for error messages only.
9191
/// @brief This map is used to store the descriptions of all positional arguments specified.
92-
std::map<char, std::string_view> posArgDescriptions;
92+
std::map<char, std::string> posArgDescriptions;
9393
/// @brief This map stores whether the positional arguments are required to be numbers.
9494
std::vector<bool> posArgIsNumber;
9595

9696
/**
9797
* @brief This map is used to store the values of all keyword arguments specified. Keys are keyword argument
9898
* names and values are the values of the keyword arguments.
9999
*/
100-
std::unordered_map<std::string_view, int> keywordArgs;
100+
std::unordered_map<std::string, int> keywordArgs;
101101
/// @brief This map is used to store the descriptions of all keyword arguments specified.
102-
std::map<std::string_view, std::string_view> keywordArgDescriptions;
102+
std::map<std::string, std::string> keywordArgDescriptions;
103103

104104
/// @brief This stores the number of arguments passed to the program.
105105
int argc;
106106

107107
/// @brief This stores the arguments passed to the program.
108-
std::vector<std::string_view> argv;
108+
std::vector<std::string> argv;
109109

110110
/// @brief This stores the name of the program.
111-
std::string_view programName;
111+
std::string programName;
112112

113113
public:
114114
/**
@@ -133,7 +133,7 @@ namespace steppable::__internals::utils
133133
* @param[in] defaultValue The default value of the switch. True = enabled, False = disabled.
134134
* @param[in] description The description of the switch.
135135
*/
136-
void addSwitch(const std::string_view& name, bool defaultValue, const std::string_view& description = "");
136+
void addSwitch(const std::string& name, bool defaultValue, const std::string& description = "");
137137

138138
/**
139139
* @brief This function is used to add a positional argument to the class.
@@ -145,7 +145,7 @@ namespace steppable::__internals::utils
145145
* @note the command-line arguments.
146146
*/
147147
void addPosArg(char name,
148-
const std::string_view& description = "",
148+
const std::string& description = "",
149149
bool requiresNumber = true); // Positional arguments are always required and ordered
150150

151151
/**
@@ -154,7 +154,7 @@ namespace steppable::__internals::utils
154154
* @param[in] defaultValue The default value of the keyword argument. The value is stored as an integer.
155155
* @param[in] description The description of the keyword argument.
156156
*/
157-
void addKeywordArg(const std::string_view& name, int defaultValue, std::string_view description = "");
157+
void addKeywordArg(const std::string& name, int defaultValue, const std::string& description = "");
158158

159159
/**
160160
* @brief This function is used to get the value of a positional argument.
@@ -164,7 +164,7 @@ namespace steppable::__internals::utils
164164
* @note If the positional argument is not specified, the function will print an error message and exit the
165165
* program.
166166
*/
167-
[[nodiscard]] std::string_view getPosArg(size_t index) const;
167+
[[nodiscard]] std::string getPosArg(size_t index) const;
168168

169169
/**
170170
* @brief This function is used to get the value of a keyword argument.
@@ -174,7 +174,7 @@ namespace steppable::__internals::utils
174174
* @note If the keyword argument is not specified, the function will print an error message and exit the
175175
* program.
176176
*/
177-
int getKeywordArgument(const std::string_view& name);
177+
int getKeywordArgument(const std::string& name);
178178

179179
/**
180180
* @brief This function is used to get the value of a switch.
@@ -183,7 +183,7 @@ namespace steppable::__internals::utils
183183
*
184184
* @note If the switch is not specified, the function will print an error message and exit the program.
185185
*/
186-
bool getSwitch(const std::string_view& name);
186+
bool getSwitch(const std::string& name);
187187

188188
/**
189189
* @brief This function is used to print the possible command-line arguments. Usually called when the user
@@ -193,6 +193,6 @@ namespace steppable::__internals::utils
193193
*
194194
* @note The function will print the usage of the program and exit the program.
195195
*/
196-
void printUsage(const std::string_view& reason = "") const;
196+
void printUsage(const std::string& reason = "") const;
197197
};
198198
} // namespace steppable::__internals::utils

include/fn/basicArithm.hpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "output.hpp"
4040

4141
#include <string>
42-
#include <string_view>
4342

4443
using namespace std::literals;
4544

@@ -65,7 +64,7 @@ namespace steppable::__internals::arithmetic
6564
* @param[in] steps The number of steps to perform the calculation.
6665
* @return The absolute value of the number as a string.
6766
*/
68-
std::string abs(const std::string_view& _number, int steps);
67+
std::string abs(const std::string& _number, int steps);
6968

7069
/**
7170
* @brief Adds two string representations of numbers, and performs with the column method.
@@ -78,8 +77,8 @@ namespace steppable::__internals::arithmetic
7877
* @param[in] properlyFormat Flag indicating whether to properly format the output. Default true.
7978
* @return The sum of the two numbers as a string.
8079
*/
81-
std::string add(const std::string_view& a,
82-
const std::string_view& b,
80+
std::string add(const std::string& a,
81+
const std::string& b,
8382
int steps = 2,
8483
bool negative = false,
8584
bool properlyFormat = true);
@@ -95,7 +94,7 @@ namespace steppable::__internals::arithmetic
9594
* "1" if a is greater than b,
9695
* "0" if a is less than b.
9796
*/
98-
std::string compare(const std::string_view& _a, const std::string_view& _b, int steps = 2);
97+
std::string compare(const std::string& _a, const std::string& _b, int steps = 2);
9998

10099
/**
101100
* @brief Converts a string representation of a number from any base to decimal.
@@ -105,7 +104,7 @@ namespace steppable::__internals::arithmetic
105104
* @param[in] steps The number of steps to perform the conversion.
106105
* @return The converted number as a string.
107106
*/
108-
std::string decimalConvert(const std::string_view& _inputString, const std::string_view& baseString, int steps = 2);
107+
std::string decimalConvert(const std::string& _inputString, const std::string& baseString, int steps = 2);
109108

110109
/**
111110
* @brief Converts a string representation of a number from decimal to another one.
@@ -115,7 +114,7 @@ namespace steppable::__internals::arithmetic
115114
* @param[in] steps The number of steps to perform the conversion.
116115
* @return The converted number as a string.
117116
*/
118-
std::string baseConvert(const std::string_view& _number, const std::string_view& baseStr, int steps = 2);
117+
std::string baseConvert(const std::string& _number, const std::string& baseStr, int steps = 2);
119118

120119
/**
121120
* @brief Divides a string representation of a number by another string representation of a number.
@@ -126,10 +125,7 @@ namespace steppable::__internals::arithmetic
126125
* @param[in] decimals The number of decimal places in the result.
127126
* @return The quotient of the division as a string.
128127
*/
129-
std::string divide(const std::string_view& number,
130-
const std::string_view& divisor,
131-
int steps = 2,
132-
int decimals = 5);
128+
std::string divide(const std::string& number, const std::string& divisor, int steps = 2, int decimals = 5);
133129

134130
/**
135131
* Calculates the quotient and remainder of dividing the current remainder by the divisor.
@@ -148,7 +144,7 @@ namespace steppable::__internals::arithmetic
148144
*
149145
* @return The greatest common divisor of the two numbers.
150146
*/
151-
std::string getGCD(const std::string_view& _a, const std::string_view& _b);
147+
std::string getGCD(const std::string& _a, const std::string& _b);
152148

153149
/**
154150
* @brief Multiplies two string representations of numbers.
@@ -158,7 +154,7 @@ namespace steppable::__internals::arithmetic
158154
* @param[in] steps The number of steps to perform the multiplication.
159155
* @return The product of the two numbers as a string.
160156
*/
161-
std::string multiply(const std::string_view& a, const std::string_view& b, int steps = 2);
157+
std::string multiply(const std::string& a, const std::string& b, int steps = 2);
162158

163159
/**
164160
* @brief Raises a string representation of a number to a power.
@@ -168,7 +164,7 @@ namespace steppable::__internals::arithmetic
168164
* @param[in] steps The number of steps to perform the power operation.
169165
* @return The result of the power operation as a string.
170166
*/
171-
std::string power(std::string_view _number, const std::string_view& raiseTo, int steps = 2);
167+
std::string power(const std::string& _number, const std::string& raiseTo, int steps = 2);
172168

173169
/**
174170
* @brief Subtracts one string representation of a number from another string representation of a number.
@@ -179,7 +175,7 @@ namespace steppable::__internals::arithmetic
179175
* @param[in] noMinus Flag indicating whether to display a minus sign or not.
180176
* @return The difference between the two numbers as a string.
181177
*/
182-
std::string subtract(const std::string_view& a, const std::string_view& b, int steps = 2, bool noMinus = false);
178+
std::string subtract(const std::string& a, const std::string& b, int steps = 2, bool noMinus = false);
183179

184180
/**
185181
* @brief Takes the n-th root of a numer.
@@ -191,7 +187,7 @@ namespace steppable::__internals::arithmetic
191187
*
192188
* @return The result of the root operation.
193189
*/
194-
std::string root(const std::string& _number, const std::string& base, size_t decimals = 8);
190+
std::string root(const std::string& _number, const std::string& base, size_t decimals = 8, int steps = 0);
195191

196192
/**
197193
* @brief Converts a root operation into a surd.
@@ -540,7 +536,7 @@ namespace steppable::__internals::arithmetic
540536
* @param[in] predicate The predicate function to execute.
541537
*/
542538
template<typename Pred>
543-
void loop(const std::string_view& times, Pred predicate)
539+
void loop(const std::string& times, Pred predicate)
544540
{
545541
// We're done already!
546542
if (times == "0")
@@ -560,7 +556,7 @@ namespace steppable::__internals::arithmetic
560556
catch (std::exception& e)
561557
{
562558
output::error("loop", "Exception occurred in predicate."s);
563-
output::error("loop", "Exception message: %s"s, e.what());
559+
output::error("loop", "Exception message: {0}"s, { e.what() });
564560
}
565561
current = add(current, "1", 0);
566562
result = compare(current, times, 0);

include/format.hpp

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
#pragma once
4141

42-
#include <cstdarg>
4342
#include <string>
4443
#include <vector>
4544

@@ -49,72 +48,5 @@
4948
*/
5049
namespace steppable::__internals::format
5150
{
52-
// https://stackoverflow.com/a/49812356/14868780
53-
/**
54-
* @brief Formats a string using a variable number of arguments.
55-
*
56-
* This function takes a format string and a variable number of arguments,
57-
* and returns a formatted string. It uses the same format specifiers as
58-
* the standard library's `printf` function.
59-
*
60-
* @tparam CharT The character type of the string.
61-
* @param[in] sFormat The format string.
62-
* @param[in] ... The variable arguments.
63-
* @return The formatted string.
64-
*/
65-
template<typename CharT>
66-
std::basic_string<CharT> vFormat(const std::basic_string<CharT> sFormat, ...)
67-
{
68-
const CharT* const zcFormat = sFormat.c_str();
69-
70-
// Initialize a variable argument array
71-
va_list vaArgs; // NOLINT(cppcoreguidelines-init-variables)
72-
va_start(vaArgs, sFormat);
73-
74-
// Reliably acquire the size from a copy of the variable argument array
75-
// and a functionally reliable call to mock the formatting
76-
va_list vaCopy; // NOLINT(cppcoreguidelines-init-variables)
77-
va_copy(vaCopy, vaArgs);
78-
const int iLen = std::vsnprintf(nullptr, 0, zcFormat, vaCopy);
79-
va_end(vaCopy);
80-
81-
// Return a formatted string without risking memory mismanagement
82-
// and without assuming any compiler or platform specific behavior
83-
std::vector<CharT> formatted(iLen + 1);
84-
(void)std::vsnprintf(formatted.data(), formatted.size(), zcFormat, vaArgs);
85-
va_end(vaArgs);
86-
return std::string(formatted.data(), formatted.size());
87-
}
88-
89-
/**
90-
* @brief Formats a string using a format specifier and variable arguments.
91-
*
92-
* This function takes a format specifier and variable arguments, similar to the printf function,
93-
* and returns a formatted string. The format specifier is a string that may contain placeholders
94-
* for the variable arguments. The function uses the vsnprintf function to perform the formatting.
95-
*
96-
* @tparam CharT The character type of the string.
97-
* @param[in] sFormat The format specifier string.
98-
* @param[in] ... The variable arguments.
99-
* @return The formatted string.
100-
*/
101-
template<typename CharT>
102-
std::basic_string<CharT> vFormat(const CharT* sFormat, ...)
103-
{
104-
const CharT* const zcFormat = sFormat;
105-
106-
va_list vaArgs; // NOLINT(cppcoreguidelines-init-variables)
107-
va_start(vaArgs, sFormat);
108-
109-
va_list vaCopy; // NOLINT(cppcoreguidelines-init-variables)
110-
va_copy(vaCopy, vaArgs);
111-
const int iLen = std::vsnprintf(nullptr, 0, zcFormat, vaCopy); // NOLINT(clang-diagnostic-format-nonliteral)
112-
va_end(vaCopy);
113-
114-
std::vector<CharT> formatted(iLen + 1);
115-
static_cast<void>(std::vsnprintf(
116-
formatted.data(), formatted.size(), zcFormat, vaArgs)); // NOLINT(clang-diagnostic-format-nonliteral)
117-
va_end(vaArgs);
118-
return std::string(formatted.data(), formatted.size());
119-
}
51+
std::string format(const std::string& format, const std::vector<std::string>& args);
12052
} // namespace steppable::__internals::format

0 commit comments

Comments
 (0)