Jelajahi Sumber

Added GetValue() convenience methods.

Brucey 2 tahun lalu
induk
melakukan
337eeb0236
2 mengubah file dengan 33 tambahan dan 12 penghapusan
  1. 1 1
      csv.mod/common.bmx
  2. 32 11
      csv.mod/csv.bmx

+ 1 - 1
csv.mod/common.bmx

@@ -36,7 +36,7 @@ Extern
 	Function bmx_csv_opts_set_options(opts:Byte Ptr, maxColumns:UInt, delimiter:Int, noQuotes:Int, insertHeaderRow:Byte Ptr, headerSpan:UInt, rowsToIgnore:UInt, keepEmptyHeaderRows:UInt)
 
 	Function zsv_new:Byte Ptr(opts:Byte Ptr)
-	Function zsv_get_cell:SCsvColumn(handle:Byte Ptr, index:Int)
+	Function zsv_get_cell:SCsvColumn(handle:Byte Ptr, index:Size_T)
 	Function zsv_cell_count:Size_T(handle:Byte Ptr)
 	Function zsv_abort(handle:Byte Ptr)
 	Function zsv_delete:ECsvStatus(handle:Byte Ptr)

+ 32 - 11
csv.mod/csv.bmx

@@ -71,7 +71,7 @@ Type TCsvParser
 
 	Method ReadHeader()
 		If NextRow() = ECsvStatus.row Then
-			Local count:Int = row.ColumnCount()
+			Local count:Size_T = row.ColumnCount()
 			Local header:TCsvHeader = New TCsvHeader(count)
 			For Local i:Int = 0 Until count
 				Local col:SCsvColumn = row.GetColumn(i)
@@ -229,32 +229,53 @@ Type TCsvRow
 	Public
 
 	Rem
-	bbdoc: Returns the number of cells in the row.
+	bbdoc: Returns the number of columns in the row.
 	End Rem
-	Method ColumnCount:Int()
+	Method ColumnCount:Size_T()
 		Return zsv_cell_count(zsvPtr)
 	End Method
 
 	Rem
-	bbdoc: Returns the cell at the given index.
+	bbdoc: Returns the column at the given index.
 	End Rem
-	Method GetColumn:SCsvColumn(index:Int)
+	Method GetColumn:SCsvColumn(index:Size_T)
 		Return zsv_get_cell(zsvPtr, index)
 	End Method
 
 	Rem
-	bbdoc: Returns the cell with the given column @name.
+	bbdoc: Returns the column at the given index.
+	End Rem
+	Method GetColumn:SCsvColumn(index:Int)
+		Return zsv_get_cell(zsvPtr, Size_T(index))
+	End Method
+
+	Rem
+	bbdoc: Returns the column with the given column @name.
 	End Rem
 	Method GetColumn:SCsvColumn(name:String)
 		If header Then
 			Local index:Int = header.IndexForName(name)
 			If index >= 0 Then
-				Return zsv_get_cell(zsvPtr, index)
+				Return zsv_get_cell(zsvPtr, Size_T(index))
 			End If
 		End If
 		Return Null
 	End Method
 
+	Rem
+	bbdoc: Returns the value of the column at the given @index.
+	End Rem
+	Method GetValue:String(index:Size_T)
+		Return zsv_get_cell(zsvPtr, index).GetValue()
+	End Method
+
+	Rem
+	bbdoc: Returns the value of the given column @name.
+	End Rem
+	Method GetValue:String(name:String)
+		Return GetColumn(name).GetValue()
+	ENd Method
+
 	Rem
 	bbdoc: Returns the header.
 	End Rem
@@ -276,7 +297,7 @@ Type TCsvHeader
 	Field map:TStringMap = New TStringMap
 
 	Private
-	Method New(count:Int)
+	Method New(count:Size_T)
 		cols = New String[count]
 	End Method
 
@@ -302,15 +323,15 @@ Type TCsvHeader
 	Rem
 	bbdoc: Returns the number of header columns.
 	End Rem
-	Method ColumnCount:Int()
+	Method ColumnCount:Size_T()
 		Return cols.Length
 	End Method
 
 	Rem
 	bbdoc: Returns the header for the given @index.
 	End Rem
-	Method GetHeader:String(index:Int)
-		If index >= 0 And index < cols.Length Then
+	Method GetHeader:String(index:Size_T)
+		If index < cols.Length Then
 			Return cols[index]
 		End If
 	End Method