-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
|
||
#include <iomanip> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "../auxiliary/to_string.h" | ||
|
||
std::string ksi::to_string (const double x) | ||
{ | ||
std::stringstream ss; | ||
ss << std::scientific << x; | ||
return ss.str(); | ||
} | ||
|
||
std::string ksi::to_string (const int n, const unsigned int width) | ||
{ | ||
std::stringstream ss; | ||
ss << std::setw(width) << std::setfill('0') << n; | ||
return ss.str(); | ||
} | ||
|
||
std::string ksi::to_string (const std::vector<double> & numbers, const char sep) | ||
{ | ||
std::stringstream ss; | ||
auto size = numbers.size(); | ||
for (std::size_t i = 0; i < size - 1; ++i) | ||
{ | ||
ss << numbers[i] << sep; | ||
} | ||
if (size > 0) | ||
ss << numbers.back(); | ||
|
||
return ss.str(); | ||
} | ||
|
||
std::string ksi::to_string (const std::vector<int> & numbers, const unsigned int width, const char sep) | ||
{ | ||
std::stringstream ss; | ||
auto size = numbers.size(); | ||
for (std::size_t i = 0; i < size - 1; ++i) | ||
{ | ||
ss << std::setw(width) << std::setfill('0') << numbers[i] << sep; | ||
} | ||
if (size > 0) | ||
ss << std::setw(width) << std::setfill('0') << numbers.back(); | ||
|
||
return ss.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** @file */ | ||
|
||
#ifndef TO_STRING_H | ||
#define TO_STRING_H | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace ksi | ||
{ | ||
/* @return The function returns a string representation of a double value in the exponential form. | ||
* @author Krzysztof Siminski | ||
* @date 2023-10-09 */ | ||
std::string to_string (const double x); | ||
|
||
/* @return The function returns a string representation of an integer value with leading zeroes. | ||
* @author Krzysztof Siminski | ||
* @param n number to make a string for | ||
* @param width width of the window for an integer (filled with zeroes) | ||
* @date 2024-03-27 */ | ||
std::string to_string (const int n, const unsigned int width = 0); | ||
|
||
/* @return The function returns a string representation of a vector of ints with leading zeroes. | ||
* @author Krzysztof Siminski | ||
* @param numbers numbers to make a string for | ||
* @param width width of the window for an integer (filled with zeroes) | ||
* @param sep separator of numbers | ||
* @date 2024-03-29 */ | ||
std::string to_string (const std::vector<int> & numbers, const unsigned int width = 0, const char sep = '-'); | ||
|
||
/* @return The function returns a string representation of a vector of ints with leading zeroes. | ||
* @author Krzysztof Siminski | ||
* @param numbers numbers to make a string for | ||
* @param width width of the window for an integer (filled with zeroes) | ||
* @param sep separator of numbers | ||
* @date 2024-03-29 */ | ||
std::string to_string (const std::vector<double> & numbers, const char sep = '-'); | ||
} | ||
|
||
|
||
#endif |