ONE - On-device Neural Engine
Loading...
Searching...
No Matches
string_helpers.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
23#include <ostream>
24#include <string>
25#include <sstream>
26#include <vector>
27
28namespace
29{
30
31template <typename Arg> void _str(std::ostream &os, Arg &&arg) { os << std::forward<Arg>(arg); }
32
33template <typename Arg, typename... Args> void _str(std::ostream &os, Arg &&arg, Args &&...args)
34{
35 _str(os, std::forward<Arg>(arg));
36 _str(os, std::forward<Args>(args)...);
37}
38
39} // namespace
40
41namespace nnfw
42{
43namespace misc
44{
45
46inline std::vector<std::string> split(const std::string &s, char delim)
47{
48 std::stringstream ss(s);
49 std::string item;
50 std::vector<std::string> elems;
51 while (std::getline(ss, item, delim))
52 {
53 elems.push_back(item);
54 }
55 return elems;
56}
57
58template <typename... Args> std::string str(Args &&...args)
59{
60 std::stringstream ss;
61 _str(ss, std::forward<Args>(args)...);
62 return ss.str();
63}
64
65template <typename InputIt> std::string join(InputIt first, InputIt last, const std::string &concat)
66{
67 std::string ret;
68 if (first == last)
69 return ret;
70
71 ret += *first;
72 for (++first; first != last; ++first)
73 {
74 ret += concat;
75 ret += *first;
76 }
77 return ret;
78}
79
80} // namespace misc
81} // namespace nnfw
std::string join(InputIt first, InputIt last, const std::string &concat)
std::string str(Args &&...args)
std::vector< std::string > split(const std::string &s, char delim)
Definition topk_v2.h:30