MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / parse_

Method parse_

src/openms/source/FORMAT/XMLFile.cpp:108–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106 }
107
108 void XMLFile::parse_(const String & filename, XMLHandler * handler)
109 {
110 // ensure handler->reset() is called to save memory (in case the XMLFile
111 // reader, e.g. FeatureXMLFile, is used again)
112 XMLCleaner_ clean(handler);
113
114 StringManager sm;
115 //try to open file
116 if (!File::exists(filename))
117 {
118 throw Exception::FileNotFound(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename);
119 }
120
121 // initialize parser
122 try
123 {
124 xercesc::XMLPlatformUtils::Initialize();
125 }
126 catch (const xercesc::XMLException & toCatch)
127 {
128 throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
129 "", String("Error during initialization: ") + StringManager().convert(toCatch.getMessage()));
130 }
131
132
133 // peak ahead into the file: is it bzip2 or gzip compressed?
134 String bz;
135 {
136 std::ifstream file(filename.c_str());
137 char tmp_bz[3];
138 file.read(tmp_bz, 2);
139 tmp_bz[2] = '\0';
140 bz = String(tmp_bz);
141 }
142
143 unique_ptr<xercesc::InputSource> source;
144
145 char g1 = 0x1f;
146 char g2 = 0;
147 g2 |= 1 << 7;
148 g2 |= 1 << 3;
149 g2 |= 1 << 1;
150 g2 |= 1 << 0;
151 //g2 = static_cast<char>(0x8b); // can make troubles if it is casted to 0x7F which is the biggest number signed char can save
152 if ((bz[0] == 'B' && bz[1] == 'Z') || (bz[0] == g1 && bz[1] == g2))
153 {
154 source.reset(new CompressedInputSource(sm.convert(filename).c_str(), bz));
155 }
156 else
157 {
158 source.reset(new xercesc::LocalFileInputSource(sm.convert(filename).c_str()));
159 }
160 // what if no encoding given http://xerces.apache.org/xerces-c/apiDocs-3/classInputSource.html
161 if (!enforced_encoding_.empty())
162 {
163 static const XMLCh* s_enc = xercesc::XMLString::transcode(enforced_encoding_.c_str());
164 source->setEncoding(s_enc);
165 }

Callers 1

loadMethod · 0.80

Calls 8

parseFunction · 0.85
StringClass · 0.50
convertMethod · 0.45
getMessageMethod · 0.45
readMethod · 0.45
resetMethod · 0.45
emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected