Implemented app result and SelectionDialog (#96)
This commit is contained in:
committed by
GitHub
parent
4744565b0e
commit
6094b9c3f2
@@ -1,5 +1,7 @@
|
||||
#include "StringUtils.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace tt {
|
||||
|
||||
@@ -27,4 +29,47 @@ bool string_get_path_parent(const char* path, char* output) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> string_split(const std::string&input, const std::string&delimiter) {
|
||||
size_t token_index = 0;
|
||||
size_t delimiter_index;
|
||||
const size_t delimiter_length = delimiter.length();
|
||||
std::string token;
|
||||
std::vector<std::string> result;
|
||||
|
||||
while ((delimiter_index = input.find(delimiter, token_index)) != std::string::npos) {
|
||||
token = input.substr(token_index, delimiter_index - token_index);
|
||||
token_index = delimiter_index + delimiter_length;
|
||||
result.push_back(token);
|
||||
}
|
||||
|
||||
auto end_token = input.substr(token_index);
|
||||
if (!end_token.empty()) {
|
||||
result.push_back(end_token);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string string_join(const std::vector<std::string>& input, const std::string& delimiter) {
|
||||
std::stringstream stream;
|
||||
size_t size = input.size();
|
||||
|
||||
if (size == 0) {
|
||||
return "";
|
||||
} else if (size == 1) {
|
||||
return input.front();
|
||||
} else {
|
||||
auto iterator = input.begin();
|
||||
while (iterator != input.end()) {
|
||||
stream << *iterator;
|
||||
iterator++;
|
||||
if (iterator != input.end()) {
|
||||
stream << delimiter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace tt {
|
||||
|
||||
@@ -21,4 +23,23 @@ int string_find_last_index(const char* text, size_t from_index, char find);
|
||||
*/
|
||||
bool string_get_path_parent(const char* path, char* output);
|
||||
|
||||
/**
|
||||
* Splits the provided input into separate pieces with delimiter as separator text.
|
||||
* When the input string is empty, the output list will be empty too.
|
||||
*
|
||||
* @param input the input to split up
|
||||
* @param delimiter a non-empty string to recognize as separator
|
||||
*/
|
||||
std::vector<std::string> string_split(const std::string& input, const std::string& delimiter);
|
||||
|
||||
/**
|
||||
* Join a set of tokens into a single string, given a delimiter (separator).
|
||||
* If the input is an empty list, the result will be an empty string.
|
||||
* The delimeter is only placed inbetween tokens and not appended at the end of the resulting string.
|
||||
*
|
||||
* @param input the tokens to join together
|
||||
* @param delimiter the separator to join with
|
||||
*/
|
||||
std::string string_join(const std::vector<std::string>& input, const std::string& delimiter);
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user