Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CCDB/src/CcdbApi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <chrono>
#include <TMessage.h>
#include <sstream>
#include <CommonUtils/StringUtils.h>

namespace o2
{
Expand Down Expand Up @@ -75,7 +76,9 @@ void CcdbApi::store(TObject* rootObject, std::string path, std::map<std::string,
struct curl_slist* headerlist = nullptr;
static const char buf[] = "Expect:";
// todo : what is the correct file name ?
string tmpFileName = string(rootObject->GetName()) + "_" + getTimestampString(getCurrentTimestamp()) + ".root";
string objectName = string(rootObject->GetName());
utils::trim(objectName);
string tmpFileName = objectName + "_" + getTimestampString(getCurrentTimestamp()) + ".root";
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "send",
Expand Down
24 changes: 3 additions & 21 deletions CCDB/test/testCcdbApi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <fcntl.h>
#include <TH1F.h>
#include <chrono>
#include <CommonUtils/StringUtils.h>

using namespace std;
using namespace o2::ccdb;
Expand Down Expand Up @@ -108,25 +109,6 @@ BOOST_AUTO_TEST_CASE(delete_test)
BOOST_CHECK(h2 == nullptr);
}

/// trim from start (in place)
/// https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
static inline void ltrim(std::string& s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
return !std::isspace(ch);
}));
}

/// trim from end (in place)
/// https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring
static inline void rtrim(std::string& s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
return !std::isspace(ch);
}).base(),
s.end());
}

void countItems(const string& s, int& countObjects, int& countSubfolders)
{
countObjects = 0;
Expand All @@ -135,8 +117,8 @@ void countItems(const string& s, int& countObjects, int& countSubfolders)
std::string line;
bool subfolderMode = false;
while (std::getline(ss, line, '\n')) {
ltrim(line);
rtrim(line);
o2::utils::ltrim(line);
o2::utils::rtrim(line);
if (line.length() == 0) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions Common/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Set(HEADERS
include/${MODULE_NAME}/BoostSerializer.h
include/${MODULE_NAME}/ShmManager.h
include/${MODULE_NAME}/RngHelper.h
include/${MODULE_NAME}/StringUtils.h
)

Set(LINKDEF src/CommonUtilsLinkDef.h)
Expand Down
84 changes: 84 additions & 0 deletions Common/Utils/include/CommonUtils/StringUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file StringUtils.h
/// \author Barthelemy von Haller
///

#ifndef ALICEO2_STRINGUTILS_H
#define ALICEO2_STRINGUTILS_H

namespace o2
{
namespace utils
{

// Code for trimming coming from https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring

/**
* Trim from start (in place)
* @param s
*/
static inline void ltrim(std::string& s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
return !std::isspace(ch);
}));
}

/** Trim from end (in place)
*
* @param s
*/
static inline void rtrim(std::string& s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
return !std::isspace(ch);
}).base(),
s.end());
}

/**
* Trim from both ends (in place)
* @param s
*/
static inline void trim(std::string& s)
{
ltrim(s);
rtrim(s);
}

/**
* Trim from start (copying)
* @param s
* @return
*/
static inline std::string ltrim_copy(std::string s)
{
ltrim(s);
return s;
}

/**
* Trim from end (copying)
* @param s
* @return
*/
static inline std::string rtrim_copy(std::string s)
{
rtrim(s);
return s;
}

} // namespace utils
} // namespace o2

#endif //ALICEO2_STRINGUTILS_H
2 changes: 2 additions & 0 deletions cmake/O2Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,12 @@ o2_define_bucket(
fairmq_bucket
pthread Core Tree XMLParser Hist Net RIO z
${CURL_LIBRARIES}
common_utils_bucket

INCLUDE_DIRECTORIES
${FAIRROOT_INCLUDE_DIR}
${ROOT_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/Common/Utils/include

SYSTEMINCLUDE_DIRECTORIES
${PROTOBUF_INCLUDE_DIR}
Expand Down