utils.hpp
943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* File: utils.hpp
* Created Date: Thursday February 17th 2022
* Author: yangzilong (yangzilong@objecteye.com)
* Description:
* -----
* Last Modified: Thursday, 17th February 2022 6:24:24 pm
* Modified By: yangzilong (yangzilong@objecteye.com>)
* -----
* Copyright 2022
*/
#pragma once
#include <string>
#include <vector>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
std::vector<std::string> split_string(const std::string &input, const std::string &delim)
{
if (input.empty())
return {};
std::size_t pos = 0;
std::string src = input;
std::vector<std::string> ret(0);
while (std::string::npos != (pos = src.find(delim, 0)))
{
ret.emplace_back(std::move(src.substr(0, pos)));
pos += delim.length();
src = src.substr(pos, src.length() - pos);
}
ret.emplace_back(std::move(src.substr(0, src.length())));
return ret;
}