ATLAS Offline Software
Loading...
Searching...
No Matches
XmlParser Namespace Reference

Classes

struct  XMLParserDeleter
 deleter for a unique_ptr<XML_Parser> More...

Typedefs

using XMLParserPtr = std::unique_ptr<std::remove_pointer_t<XML_Parser>, XMLParserDeleter>
 RAII XMLParser pointer.

Functions

std::string xmlFileName (const std::string &fname, const std::string &prefix="")
 find the xml file locally or on the datapath, return the full filename
bool debug_enabled ()
 true if XML debug mode is enabled in the environment
std::string label (const std::source_location loc=std::source_location::current())
 report function name in a string, for debugging
XMLParserPtr make_parser ()
 Create an RAII XMLParser pointer.
std::string rtrim (const XML_Char *s, int len)
 Trim newline from end of a XML_Char * , return the trimmed string as std::string.

Typedef Documentation

◆ XMLParserPtr

using XmlParser::XMLParserPtr = std::unique_ptr<std::remove_pointer_t<XML_Parser>, XMLParserDeleter>

RAII XMLParser pointer.

Definition at line 49 of file XMLParserUtilities.h.

Function Documentation

◆ debug_enabled()

bool XmlParser::debug_enabled ( )
inline

true if XML debug mode is enabled in the environment

Definition at line 29 of file XMLParserUtilities.h.

29 {
30 static const bool enabled = (std::getenv("XMLDEBUG") != nullptr);
31 return enabled;
32 }

◆ label()

std::string XmlParser::label ( const std::source_location loc = std::source_location::current())
inline

report function name in a string, for debugging

Definition at line 36 of file XMLParserUtilities.h.

36 {
37 return loc.function_name();
38 }

◆ make_parser()

XMLParserPtr XmlParser::make_parser ( )
inline

Create an RAII XMLParser pointer.

Definition at line 52 of file XMLParserUtilities.h.

52 {
53 XML_Parser p = XML_ParserCreate(nullptr);
54 if (!p) {
55 std::cout << "ExpatCoreParser::Couldn't allocate memory for parser" << std::endl;
56 std::abort();
57 }
58 return XMLParserPtr{p};
59 }
std::unique_ptr< std::remove_pointer_t< XML_Parser >, XMLParserDeleter > XMLParserPtr
RAII XMLParser pointer.

◆ rtrim()

std::string XmlParser::rtrim ( const XML_Char * s,
int len )
inline

Trim newline from end of a XML_Char * , return the trimmed string as std::string.

Definition at line 62 of file XMLParserUtilities.h.

62 {
63 while (len > 0 && s[len - 1] == '\n') {
64 --len;
65 }
66 return (len > 0) ? std::string{s, static_cast<std::size_t>(len)} : std::string{};
67 }

◆ xmlFileName()

std::string XmlParser::xmlFileName ( const std::string & fname,
const std::string & prefix )

find the xml file locally or on the datapath, return the full filename

Definition at line 19 of file XMLParserUtilities.cxx.

19 {
20 if (fs::exists(fname) ) return fname;
21 std::string fileWithPrefix = prefix + "/" + fname;
22 if (fs::exists(fileWithPrefix) ) return fileWithPrefix;
23 //
24 const char* xmlpathenv = std::getenv ("XMLPATH");
25 if (xmlpathenv == nullptr) return "";
26 std::string xmlpath = xmlpathenv;
27 std::string::size_type pos = 0;
28 std::string temp_name;
29 while (pos != std::string::npos){
30 std::string::size_type sep = xmlpath.find (":", pos);
31 if (sep == std::string::npos){
32 temp_name = xmlpath.substr (pos);
33 pos = std::string::npos;
34 } else {
35 temp_name = xmlpath.substr (pos, sep - pos);
36 pos = sep + 1;
37 }
38 if (temp_name.empty()) continue;
39 std::string last_temp_name = temp_name;
40 temp_name += "/";
41 temp_name += fname;
42 if (fs::exists (temp_name)) return temp_name;
43 // Test whether prefix is a relative path and if so use it
44 if (prefix != "" && '/' != prefix[0]) {
45 temp_name = std::move(last_temp_name);
46 temp_name += "/";
47 temp_name += prefix;
48 temp_name += "/";
49 temp_name += fname;
50 if (fs::exists (temp_name)) return temp_name;
51 }
52 }
53 return "";
54 }