summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/common.cpp12
-rw-r--r--common/common.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/common/common.cpp b/common/common.cpp
index d42fa131..aa494291 100644
--- a/common/common.cpp
+++ b/common/common.cpp
@@ -1693,6 +1693,18 @@ std::vector<std::string> string_split(std::string input, char separator) {
return parts;
}
+std::string string_strip(const std::string & str) {
+ size_t start = 0;
+ size_t end = str.size();
+ while (start < end && std::isspace(str[start])) {
+ start++;
+ }
+ while (end > start && std::isspace(str[end - 1])) {
+ end--;
+ }
+ return str.substr(start, end - start);
+}
+
std::vector<llama_sampler_type> sampler_types_from_names(const std::vector<std::string> & names, bool allow_alt_names) {
std::unordered_map<std::string, llama_sampler_type> sampler_canonical_name_map {
{"top_k", llama_sampler_type::TOP_K},
diff --git a/common/common.h b/common/common.h
index 96a28a6c..eea63a11 100644
--- a/common/common.h
+++ b/common/common.h
@@ -196,6 +196,7 @@ bool validate_file_name(const std::string & filename);
std::vector<llama_sampler_type> sampler_types_from_names(const std::vector<std::string> & names, bool allow_alt_names);
std::vector<llama_sampler_type> sampler_types_from_chars(const std::string & names_string);
std::vector<std::string> string_split(std::string input, char separator);
+std::string string_strip(const std::string & str);
std::string sampler_type_to_name_string(llama_sampler_type sampler_type);
//