-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSVParser.py
More file actions
118 lines (94 loc) · 3.24 KB
/
Copy pathCSVParser.py
File metadata and controls
118 lines (94 loc) · 3.24 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python
# coding=utf-8
import sys
import zipfile
import shutil
import os
import os.path
import json
from . import FileUtil
class CSVParser():
KEY_WORD_YINHAO = "\""
KEY_WORD_YINHAO2 = "”"
KEY_WORD_SPLIT = ","
KEY_WORD_CANCEL = "#"
rootJson = None
fileJson = ""
# 当前行数组
listLine = []
# 整个内容表
listTable = []
def ReadData(self,text):
self.SplitAllLine(text)
def SplitAllLine(self,text):
list = text.split("\n")
index = 0
for i in range(0, len(list)):
strline = list[i]
if len(strline) > 0:
# 注释
if strline[0:1]==self.KEY_WORD_CANCEL:
continue
v_new = strline.replace("\r", "")
self.SplitLine(v_new)
index = index+1
}
def SplitLine(self,text):
list = []
pos = 0
# 是否有分割符
ishas_split = False
yinhao_pos_start = -1
yinhao_pos_end = -1
strYinhao = ""
for i in range(0, len(text)):
word = text[i:i+1]
if yinhao_pos_start >= 0:
# //skip 引号
if i <= yinhao_pos_end and i != str.length - 1 :
continue
if word == self.KEY_WORD_SPLIT:
ishas_split = True
# //substring:pos to (i-1)
len = (i - 1) - pos + 1
strtmp = str.substr(pos, len)
# //Debug.Log("SplitLine:" + strtmp)
list.append(strtmp)
pos = i + 1
if (word == self.KEY_WORD_YINHAO) or (word == self.KEY_WORD_YINHAO2):
strYinhao = word
skip_step = 0
# //查找下一个引号
# //"亲,好玩,现在就去赞一个?","Pro, fun, and now to praise a?"
# postmp = text.indexOf(strYinhao, i + 1)
strtmp = text[i+1:]
postmp = strtmp.find(strYinhao)
if postmp >= 0:
yinhao_pos_start = i
yinhao_pos_end = postmp
skip_step = postmp - i + 1
# // i += skip_step
if i == len(text) - 1 :
if ishas_split == True:
# //添加最后一个分割符后的子串
len = i - pos + 1
strtmp = text[pos:pos+len]
# //Debug.Log("SplitLine:" + strtmp)
list.append(strtmp)
else:
# //整个
list.append(str)
# index = 0
# for (let value of list) {
# // Debug.Log("SplitLine list=" + value)
# index++
# }
self.listTable.append(list)
def GetText(self,row,col):
# ret = ""
# list = self.listTable[row]
# ret = list[col]
return self.listTable[row][col]
def GetRowCount(self):
return len(self.listTable)
mainCSVParser = CSVParser()