// libphitech.cpp : Defines the functions for the static library.
//

#include "pch.h"
#include "framework.h"
#include "helpers.h"
#include "sierrachart.h"

#include <string>
#include <regex>
#include <vector>

namespace phitech
{
namespace helpers
{

    void string_to_datetime_vector(const std::string& datetime_string, std::vector<SCDateTime>& target)
	{
		std::vector<int> ints;
		std::regex pattern(R"(\d+)");

		std::smatch matches;
		std::string::const_iterator searchStart(datetime_string.cbegin());
		while (std::regex_search(searchStart, datetime_string.cend(), matches, pattern))
		{
			ints.push_back(std::stoi(matches.str(0)));
			searchStart = matches.suffix().first;
		}

		for (int i = 0; i + 6 <= ints.size(); i += 6)
		{
			SCDateTime current;
            current.SetDateTimeYMDHMS(ints[i], ints[i + 1], ints[i + 2], ints[i + 3],
                                          ints[i + 4], ints[i + 5]);
            target.push_back(current);
		}
	}

} // namespace helpers
} // namespace phitech
