utils.hpp 943 Bytes
/*
 * 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;
}