-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patheHutils.cpp
More file actions
56 lines (50 loc) · 1.04 KB
/
eHutils.cpp
File metadata and controls
56 lines (50 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* eHutils.cpp
*
* Hang Su
* 2012-08 @ eH
*/
#include "eHutils.h"
#include "string.h"
#include "stdlib.h"
int* parseCSVstr2int(const char* csvstr, int* siz, int offset) {
/* if size is not given, first find it out*/
char delimiter = ',';
const char* ptr;
if(*siz==-1){
*siz=0;
ptr=strchr(csvstr,delimiter);
while(ptr!=NULL){
(*siz)++;
ptr = strchr(ptr+1,delimiter);
}
(*siz) += 1;
}
int* arr = new int[*siz];
char* endptr;
arr[0] = strtol(csvstr, &endptr, 10) + offset;
for(int i=1;i<*siz;i++) {
arr[i] = strtol(endptr+1, &endptr, 10) + offset;
}
return arr;
}
double* parseCSVstr2double(const char* csvstr, int *siz) { /* if size is not given, first find it out*/
char delimiter = ',';
const char* ptr;
if(*siz==-1){
*siz=0;
ptr=strchr(csvstr,delimiter);
while(ptr!=NULL){
(*siz)++;
ptr = strchr(ptr+1,delimiter);
}
(*siz) += 1;
}
double* arr = new double[*siz];
char* endptr;
arr[0] = strtod(csvstr, &endptr);
for(int i=1;i<*siz;i++) {
arr[i] = strtod(endptr+1, &endptr);
}
return arr;
}