MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / writeString

Function writeString

src/function/export/export_csv_function.cpp:70–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70static void writeString(BufferWriter* serializer, const ExportFuncBindData& bindData,
71 const uint8_t* strData, uint64_t strLen, bool forceQuote, std::atomic<bool>& parallelFlag) {
72 auto& exportCSVBindData = bindData.constCast<ExportCSVBindData>();
73 if (!forceQuote) {
74 forceQuote = requireQuotes(exportCSVBindData, strData, strLen, parallelFlag);
75 }
76 if (forceQuote) {
77 bool requiresEscape = false;
78 for (auto i = 0u; i < strLen; i++) {
79 if (strData[i] == exportCSVBindData.exportOption.quoteChar ||
80 strData[i] == exportCSVBindData.exportOption.escapeChar) {
81 requiresEscape = true;
82 break;
83 }
84 }
85
86 if (!requiresEscape) {
87 serializer->writeBufferData(exportCSVBindData.exportOption.quoteChar);
88 serializer->write(strData, strLen);
89 serializer->writeBufferData(exportCSVBindData.exportOption.quoteChar);
90 return;
91 }
92
93 std::string strValToWrite = std::string(reinterpret_cast<const char*>(strData), strLen);
94 strValToWrite = addEscapes(exportCSVBindData.exportOption.escapeChar,
95 exportCSVBindData.exportOption.escapeChar, strValToWrite);
96 if (exportCSVBindData.exportOption.escapeChar != exportCSVBindData.exportOption.quoteChar) {
97 strValToWrite = addEscapes(exportCSVBindData.exportOption.quoteChar,
98 exportCSVBindData.exportOption.escapeChar, strValToWrite);
99 }
100 serializer->writeBufferData(exportCSVBindData.exportOption.quoteChar);
101 serializer->writeBufferData(strValToWrite);
102 serializer->writeBufferData(exportCSVBindData.exportOption.quoteChar);
103 } else {
104 serializer->write(strData, strLen);
105 }
106}
107
108struct ExportCSVSharedState : public ExportFuncSharedState {
109 std::mutex mtx;

Callers 3

writeHeaderMethod · 0.85
writeRowsFunction · 0.85
writeStringMethod · 0.85

Calls 3

requireQuotesFunction · 0.85
addEscapesFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected