Project

General

Profile

Download (1.5 KB) Statistics
| Branch: | Revision:
eee13fa3 david.sorber
/********************************************************************
* CONFIDENTIAL - All source code is the propriety and confidential *
* information of David Sorber. *
* *
* Copyright 2024 David Sorber *
* Unpublished -- all rights reserved under the copyright laws *
* of the United States. *
********************************************************************/
#ifndef __COPYTOOL_UTILITIES_H_
#define __COPYTOOL_UTILITIES_H_

#include <string>
#include <vector>

static void tokenize(
const std::string& input,
const std::string& DELIMITER,
std::vector<std::string> &tokens)
{
size_t start = input.find_first_not_of(DELIMITER);
size_t end = start;

while (start != std::string::npos)
{
// Find next occurrence of delimiter
end = input.find(DELIMITER, start);

// Skip any DELIMITER chars that are immediately preceeded by a
// backslash (this allows the delimiter to be escaped)
while (end != 0 && (end < input.size() - 1) && input[end - 1] == '\\')
{
end = input.find(DELIMITER, end + 1);
}

// Push back the token found into vector
tokens.push_back(input.substr(start, end - start));

// Skip all occurrences of the delimiter to find new start
start = input.find_first_not_of(DELIMITER, end);
}
}

#endif