| 68 | } |
| 69 | |
| 70 | static 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 | |
| 108 | struct ExportCSVSharedState : public ExportFuncSharedState { |
| 109 | std::mutex mtx; |
no test coverage detected