-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbmwBESTTable.cpp
More file actions
83 lines (71 loc) · 2.59 KB
/
bmwBESTTable.cpp
File metadata and controls
83 lines (71 loc) · 2.59 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Created by lpcvoid on 2020-02-06.
//
#include "bmwBESTTable.h"
#include "../common/bmwStringHelper.hpp"
bool bmwBESTTable::TryGetDataCell(int32 row, int32 col, std::string *out_contents) {
if ((row >= 0) && (col >= 0)){
if (row >= table_data.size())
return false;
if (col >= table_data[row].size())
return false;
*out_contents = table_data[row][col];
return true;
}
return false;
}
uint32 bmwBESTTable::GetRowCount() {
return table_data.size();
}
int32 bmwBESTTable::GetColumnIndex(std::string name) {
//trim string
name = bmwStringHelper::trim(name);
for (int i = 0; i < table_head.size(); i++){
if (bmwStringHelper::uppercase(table_head[i]) == bmwStringHelper::uppercase(name))
return i;
}
return BMW_TABLE_NOT_FOUND;
}
bool bmwBESTTable::GetColumnRow_ColName_RowStr(std::string colname, std::string rowcontent, int32 *row_index) {
*row_index = BMW_TABLE_NOT_FOUND;
colname = bmwStringHelper::uppercase(colname);
int32 col_index = GetColumnIndex(colname);
if (col_index != BMW_TABLE_NOT_FOUND){
return GetColumnRow_ColIndx_RowStr(col_index, rowcontent, row_index);
}
return false;
}
bool bmwBESTTable::GetColumnRow_ColIndx_RowStr(int32 colname, std::string rowcontent, int32 *row_index) {
*row_index = BMW_TABLE_NOT_FOUND;
for (int i = 0; i < GetRowCount(); i++){
std::string entry;
if (TryGetDataCell(i,colname,&entry)){
entry = bmwStringHelper::uppercase(entry);
if (bmwStringHelper::is_numeric_string(rowcontent) && bmwStringHelper::is_numeric_string(entry)){
int32 i_rc = bmwStringHelper::to_integer<int32>(rowcontent);
int32 i_entry = bmwStringHelper::to_integer<int32>(entry);
if (i_rc == i_entry)
{
*row_index = i;
return true;
}
} else {
//not a hex number or number
rowcontent = bmwStringHelper::uppercase(rowcontent);
if (rowcontent == entry)
{
*row_index = i;
return true;
}
}
} else {
*row_index = (int32)(GetRowCount() -1); //return last row, for whatever reason
return false;
}
}
*row_index = (int32)(GetRowCount() -1);//return last row, for whatever reason
return false;
}
bool bmwBESTTable::GetColumnRow_ColName_ColValue(std::string colname, std::string colvalue, int32 *row_index) {
return false;
}