NCBI C++ ToolKit
csv_exporter.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: csv_exporter.cpp 36710 2016-10-26 16:51:44Z evgeniev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
37 
38 void CCSVExporter::Field(const string& value)
39 {
40  if (!m_NewRow)
41  m_OS << m_Delimiter;
42 
43  if (value.find(m_Delimiter) != string::npos) {
44  m_OS << m_Quote;
45 
46  string tmp = value;
47  for (;!tmp.empty();) {
48  size_t pos = tmp.find(m_Quote);
49  if (pos == string::npos) {
50  m_OS << tmp;
51  break;
52  }
53  else {
54  m_OS << tmp.substr(0, pos + 1) << m_Quote;
55  tmp = tmp.substr(pos + 1);
56  }
57  }
58 
59  m_OS << m_Quote;
60  }
61  else {
62  if (!m_QuoteAll)
63  m_OS << value;
64  else
65  m_OS << m_Quote << value << m_Quote;
66  }
67 
68  m_NewRow = false;
69 }
70 
71 void CCSVExporter::Field(const wxString& value)
72 {
73  Field(string(value.ToUTF8()));
74 }
75 
77 {
78  if (!m_NewRow)
79  m_OS << m_Delimiter;
80 
81  m_OS << value;
82  m_NewRow = false;
83 }
84 
86 {
87  if (!m_NewRow)
88  m_OS << m_Delimiter;
89 
90  m_OS << value;
91  m_NewRow = false;
92 }
93 
95 {
96  m_OS << NcbiEndl;
97  m_NewRow = true;
98 }
99 
CNcbiOstream & m_OS
void Field(const string &value)
static char tmp[3200]
Definition: utf8.c:42
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NcbiEndl
Definition: ncbistre.hpp:548
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Modified on Sun May 19 04:46:03 2024 by modify_doxy.py rev. 669887