Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang/test/Analysis/csv2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def csv_to_json_dict(csv_filepath):
"""
try:
with open(csv_filepath, "r", encoding="utf-8") as csvfile:
reader = csv.reader(csvfile)
reader = csv.reader(csvfile, skipinitialspace=True)

# Read the header row (column names)
try:
Expand All @@ -58,19 +58,19 @@ def csv_to_json_dict(csv_filepath):
json.dumps({}, indent=2)
return

other_column_names = [name.strip() for name in header[1:]]
header_length = len(header)

data_dict = {}

for row in reader:
if len(row) != len(header):
if len(row) != header_length:
raise csv.Error("Inconsistent CSV file")
exit(1)

key = row[0]
value_map = {}

for i, col_name in enumerate(other_column_names):
for i, col_name in enumerate(header[1:]):
# +1 to skip the first column
value_map[col_name] = row[i + 1].strip()

Expand Down
Loading