' Returns a list with the headers found in the first line.
' If lowerCase is true, all values are shifted to lowercase.
Public Sub GetHeaders(Input As String, SeparatorChar As String, lowerCase As Boolean) As List ' Added by WM
Dim i As Int
SeparatorChar = SeparatorChar.CharAt(0)
Dim Result As List
Result.Initialize
If Input = "" Then Return Result
CurrentIndex = 0
Dim count As Int = ReadLine(Input, Null, True, SeparatorChar)
CurrentIndex = 0
Dim row(count) As String
ReadLine(Input, row, False, SeparatorChar)
For i = 0 To (row.Length - 1)
If lowerCase Then
Result.Add(row(i).ToLowerCase)
Else
Result.Add(row(i))
End If
Next
Return Result
End Sub
' Assumes the first row contains headers.
' Returns a list of maps. Each map contains, for all headers: key=header, value=value found in the data row.
' If lowerCase is true, all keys in the maps are shifted to lowercase.
Public Sub ParseToMaps(Input As String, SeparatorChar As String, lowerCase As Boolean) As List ' Added by WM
Dim headers As List = GetHeaders(Input, SeparatorChar, lowerCase)
Dim i As Int
SeparatorChar = SeparatorChar.CharAt(0)
Dim Result As List
Result.Initialize
If Input = "" Then Return Result
CurrentIndex = 0
Dim count As Int = ReadLine(Input, Null, True, SeparatorChar)
Do While CurrentIndex < Input.Length
Dim row(count) As String
ReadLine(Input, row, False, SeparatorChar)
Dim m As Map
m.Initialize
For i = 0 To (row.Length - 1)
m.Put(headers.Get(i).As(String), row(i))
Next
Result.Add(m)
Loop
Return Result
End Sub