BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
getDelimiter.h
Go to the documentation of this file.
1#include <string>
2#include <fstream>
3
4inline char getDelimiter(const std::string& instanceFileOrString, size_t lineBreakPosition = std::string::npos) {
5 std::string header;
6 if ( lineBreakPosition == std::string::npos ) {
7 // no line break in instanceFileOrString so it must be a filename
8 // determine delimiter from file
9 std::ifstream file(instanceFileOrString);
10 if (file.is_open()) {
11 std::getline(file, header);
12 file.close();
13 }
14 else {
15 throw std::runtime_error("Unable to open file " + instanceFileOrString);
16 }
17 }
18 else {
19 // determine delimiter from first line of string
20 header = instanceFileOrString.substr(0,lineBreakPosition+1);
21 }
22
23 if ( header.contains(';') ) {
24 return ';';
25 }
26 if ( header.contains(',') ) {
27 return ',';
28 }
29 if ( header.contains('\t') ) {
30 return '\t';
31 }
32 throw std::runtime_error("Unable to determine delimiter for " + instanceFileOrString);
33}
char getDelimiter(const std::string &instanceFileOrString, size_t lineBreakPosition=std::string::npos)
Definition getDelimiter.h:4