Line data Source code
1 : /*
2 : * DUNE DAQ modification notice:
3 : * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4 : * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5 : * Renamed since fork: yes (from src/Util.cxx to src/Util.cpp).
6 : *
7 : * Original copyright:
8 : * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
9 : * Licensed under the Apache License, Version 2.0.
10 : */
11 :
12 : #include <stdio.h>
13 :
14 : #include <ers/internal/Util.hpp>
15 : #include <ers/internal/macro.hpp>
16 :
17 : void
18 64 : ers::tokenize( const std::string & text,
19 : const std::string & separators,
20 : std::vector<std::string> & result )
21 : {
22 64 : std::string::size_type start_p, end_p;
23 64 : start_p = 0;
24 442 : do
25 : {
26 442 : end_p = text.find_first_of(separators,start_p);
27 442 : if (end_p == std::string::npos)
28 : {
29 64 : end_p = text.length();
30 : }
31 442 : result.push_back( text.substr( start_p, end_p - start_p ) );
32 442 : start_p = text.find_first_not_of( separators, end_p );
33 : }
34 442 : while( start_p != std::string::npos );
35 64 : }
36 :
37 : int
38 90 : ers::read_from_environment( const char * name, int default_value )
39 : {
40 90 : int value = default_value;
41 90 : const char * env = ::getenv( name );
42 90 : if ( env )
43 : {
44 0 : if ( sscanf( env, "%d", &value ) != 1 )
45 : {
46 0 : ERS_INTERNAL_ERROR( "Wrong value \"" << env
47 : << "\" is given for the \"" << name << "\" environment" )
48 : }
49 : }
50 90 : return value;
51 : }
52 :
53 : const char *
54 152 : ers::read_from_environment( const char * name, const char * default_value )
55 : {
56 152 : const char * env = ::getenv( name );
57 152 : return ( env ? env : default_value);
58 : }
59 :
60 :
61 :
|