MCPcopy Create free account
hub / github.com/ddnet/ddnet / CsvWrite

Function CsvWrite

src/engine/shared/csv.cpp:5–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <base/system.h>
4
5void CsvWrite(IOHANDLE File, int NumColumns, const char *const *ppColumns)
6{
7 for(int i = 0; i < NumColumns; i++)
8 {
9 if(i != 0)
10 {
11 io_write(File, ",", 1);
12 }
13 const char *pColumn = ppColumns[i];
14 int ColumnLength = str_length(pColumn);
15 if(!str_find(pColumn, "\"") && !str_find(pColumn, ","))
16 {
17 io_write(File, pColumn, ColumnLength);
18 continue;
19 }
20
21 int Start = 0;
22 io_write(File, "\"", 1);
23 for(int j = 0; j < ColumnLength; j++)
24 {
25 if(pColumn[j] == '"')
26 {
27 if(Start != j)
28 {
29 io_write(File, pColumn + Start, j - Start);
30 }
31 Start = j + 1;
32 io_write(File, "\"\"", 2);
33 }
34 }
35 if(Start != ColumnLength)
36 {
37 io_write(File, pColumn + Start, ColumnLength - Start);
38 }
39 io_write(File, "\"", 1);
40 }
41 io_write_newline(File);
42}

Callers 3

StoreSaveMethod · 0.85
StoreSaveMethod · 0.85
ExpectFunction · 0.85

Calls 4

io_writeFunction · 0.85
str_lengthFunction · 0.85
str_findFunction · 0.85
io_write_newlineFunction · 0.85

Tested by 1

ExpectFunction · 0.68