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