Mercurial > minori
comparison src/string_utils.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Thu, 24 Aug 2023 23:11:38 -0400 |
| parents | 190ded9438c0 |
| children |
comparison
equal
deleted
inserted
replaced
| 6:1d82f6e04d7d | 7:07a9095eaeed |
|---|---|
| 1 /** | 1 /** |
| 2 * string_utils.cpp: Useful functions for manipulating strings | 2 * string_utils.cpp: Useful functions for manipulating strings |
| 3 * | 3 * |
| 4 * Every function in here *should* have a working wstring equivalent. | 4 * Every function in here *should* have a working wstring equivalent, |
| 5 * although we don't use wstrings anymore... | |
| 5 **/ | 6 **/ |
| 6 #include <vector> | 7 #include <vector> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <codecvt> | 9 #include <codecvt> |
| 9 #include <locale> | 10 #include <locale> |
| 10 #include "string_utils.h" | 11 #include "string_utils.h" |
| 11 | 12 |
| 12 /* It's actually pretty insane how the standard library still doesn't | |
| 13 have a function for this. Look at how simple this is. */ | |
| 14 std::string StringUtils::Implode(const std::vector<std::string>& vector, | 13 std::string StringUtils::Implode(const std::vector<std::string>& vector, |
| 15 const std::string& delimiter) { | 14 const std::string& delimiter) { |
| 15 if (vector.size() < 1) | |
| 16 return "-"; | |
| 16 std::string out = ""; | 17 std::string out = ""; |
| 17 for (unsigned long long i = 0; i < vector.size(); i++) { | 18 for (unsigned long long i = 0; i < vector.size(); i++) { |
| 18 out.append(vector.at(i)); | 19 out.append(vector.at(i)); |
| 19 if (i < vector.size()-1) | 20 if (i < vector.size()-1) |
| 20 out.append(delimiter); | 21 out.append(delimiter); |
