Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/common/libxml_utils.cc

Issue 2929: Some initial work on compiling chrome/common/ on Linux.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/json_value_serializer.cc ('k') | chrome/common/pref_member.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/libxml_utils.h" 5 #include "chrome/common/libxml_utils.h"
6
7 #include "base/compiler_specific.h"
6 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_util.h"
7 10
8 #include "libxml/xmlreader.h" 11 #include "libxml/xmlreader.h"
9 12
10 std::string XmlStringToStdString(const xmlChar* xmlstring) { 13 std::string XmlStringToStdString(const xmlChar* xmlstring) {
11 // xmlChar*s are UTF-8, so this cast is safe. 14 // xmlChar*s are UTF-8, so this cast is safe.
12 if (xmlstring) 15 if (xmlstring)
13 return std::string(reinterpret_cast<const char*>(xmlstring)); 16 return std::string(reinterpret_cast<const char*>(xmlstring));
14 else 17 else
15 return ""; 18 return "";
16 } 19 }
17 20
18 XmlReader::XmlReader() 21 XmlReader::XmlReader()
19 : reader_(NULL), 22 : reader_(NULL),
20 #pragma warning(suppress: 4355) // Okay to pass "this" here. 23 ALLOW_THIS_IN_INITIALIZER_LIST(
21 error_func_(this, &XmlReader::GenericErrorCallback) { 24 error_func_(this, &XmlReader::GenericErrorCallback)) {
22 } 25 }
23 26
24 XmlReader::~XmlReader() { 27 XmlReader::~XmlReader() {
25 if (reader_) 28 if (reader_)
26 xmlFreeTextReader(reader_); 29 xmlFreeTextReader(reader_);
27 } 30 }
28 31
29 /* static */ void XmlReader::GenericErrorCallback(void* context, 32 /* static */ void XmlReader::GenericErrorCallback(void* context,
30 const char* msg, ...) { 33 const char* msg, ...) {
31 va_list args; 34 va_list args;
32 va_start(args, msg); 35 va_start(args, msg);
33 char buffer[1 << 9];
34 vsnprintf_s(buffer, arraysize(buffer), _TRUNCATE, msg, args);
35 36
36 XmlReader* reader = static_cast<XmlReader*>(context); 37 XmlReader* reader = static_cast<XmlReader*>(context);
37 reader->errors_.append(buffer); 38 reader->errors_.append(StringPrintf(msg, args));
38 } 39 }
39 40
40 bool XmlReader::Load(const std::string& input) { 41 bool XmlReader::Load(const std::string& input) {
41 const int kParseOptions = 42 const int kParseOptions =
42 XML_PARSE_RECOVER | // recover on errors 43 XML_PARSE_RECOVER | // recover on errors
43 XML_PARSE_NONET; // forbid network access 44 XML_PARSE_NONET; // forbid network access
44 // TODO(evanm): Verify it's OK to pass NULL for the URL and encoding. 45 // TODO(evanm): Verify it's OK to pass NULL for the URL and encoding.
45 // The libxml code allows for these, but it's unclear what effect is has. 46 // The libxml code allows for these, but it's unclear what effect is has.
46 reader_ = xmlReaderForMemory(input.data(), static_cast<int>(input.size()), 47 reader_ = xmlReaderForMemory(input.data(), static_cast<int>(input.size()),
47 NULL, NULL, kParseOptions); 48 NULL, NULL, kParseOptions);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 xmlTextWriterSetIndent(writer_, 1); 135 xmlTextWriterSetIndent(writer_, 1);
135 xmlTextWriterStartDocument(writer_, NULL, NULL, NULL); 136 xmlTextWriterStartDocument(writer_, NULL, NULL, NULL);
136 } 137 }
137 138
138 void XmlWriter::StopWriting() { 139 void XmlWriter::StopWriting() {
139 xmlTextWriterEndDocument(writer_); 140 xmlTextWriterEndDocument(writer_);
140 xmlFreeTextWriter(writer_); 141 xmlFreeTextWriter(writer_);
141 writer_ = NULL; 142 writer_ = NULL;
142 } 143 }
143 144
OLDNEW
« no previous file with comments | « chrome/common/json_value_serializer.cc ('k') | chrome/common/pref_member.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698