Blame src/utils.hpp

Packit 01d647
// ********************************************************* -*- C++ -*-
Packit 01d647
/*
Packit 01d647
 * Copyright (C) 2004-2018 Exiv2 authors
Packit 01d647
 * This program is part of the Exiv2 distribution.
Packit 01d647
 *
Packit 01d647
 * This program is free software; you can redistribute it and/or
Packit 01d647
 * modify it under the terms of the GNU General Public License
Packit 01d647
 * as published by the Free Software Foundation; either version 2
Packit 01d647
 * of the License, or (at your option) any later version.
Packit 01d647
 *
Packit 01d647
 * This program is distributed in the hope that it will be useful,
Packit 01d647
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 01d647
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 01d647
 * GNU General Public License for more details.
Packit 01d647
 *
Packit 01d647
 * You should have received a copy of the GNU General Public License
Packit 01d647
 * along with this program; if not, write to the Free Software
Packit 01d647
 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
Packit 01d647
 */
Packit 01d647
/*!
Packit 01d647
  @file    utils.hpp
Packit 01d647
  @brief   A collection of utility functions
Packit 01d647
  @author  Andreas Huggel (ahu)
Packit 01d647
           ahuggel@gmx.net
Packit 01d647
  @date    12-Dec-03, ahu: created
Packit 01d647
 */
Packit 01d647
#ifndef UTILS_HPP_
Packit 01d647
#define UTILS_HPP_
Packit 01d647
Packit 01d647
// *********************************************************************
Packit 01d647
// included header files
Packit 01d647
Packit 01d647
// + standard includes
Packit 01d647
#include <string>
Packit 01d647
Packit 01d647
// *********************************************************************
Packit 01d647
// namespace extensions
Packit 01d647
/*!
Packit 01d647
  @brief Contains utility classes and functions. Most of these are
Packit 01d647
         wrappers for common C functions that do not require pointers
Packit 01d647
         and memory considerations.
Packit 01d647
*/
Packit 01d647
namespace Util {
Packit 01d647
Packit 01d647
// *********************************************************************
Packit 01d647
// free functions
Packit 01d647
Packit 01d647
    /*!
Packit 01d647
      @brief Get the directory component from the \em path string.
Packit 01d647
             See %dirname(3).
Packit 01d647
Packit 01d647
      This function can handle Windows paths to some extent: c:\\bar should
Packit 01d647
      be fine, \\\\bigsrv\\foo also, but \\\\bigsrv alone doesn't work.
Packit 01d647
     */
Packit 01d647
    std::string dirname(const std::string& path);
Packit 01d647
Packit 01d647
    /*!
Packit 01d647
      @brief Get the filename component from the \em path string.
Packit 01d647
             See %basename(3). If the \em delsuffix parameter is true,
Packit 01d647
             the suffix will be removed.
Packit 01d647
Packit 01d647
      This function can handle Windows paths to some extent: c:\\bar should
Packit 01d647
      be fine, \\\\bigsrv\\foo also, but \\\\bigsrv alone doesn't work.
Packit 01d647
     */
Packit 01d647
    std::string basename(const std::string& path, bool delsuffix =false);
Packit 01d647
Packit 01d647
    /*!
Packit 01d647
      @brief Get the suffix from the path string. Normally, the suffix
Packit 01d647
             is the substring of the basename of path from the last '.'
Packit 01d647
             to the end of the string.
Packit 01d647
     */
Packit 01d647
    std::string suffix(const std::string& path);
Packit 01d647
Packit 01d647
    /*!
Packit 01d647
      @brief Convert a C string to a long value, which is returned in n.
Packit 01d647
             Returns true if the conversion is successful, else false.
Packit 01d647
             n is not modified if the conversion is unsuccessful. See strtol(2).
Packit 01d647
     */
Packit 01d647
    bool strtol(const char* nptr, long& n);
Packit 01d647
Packit 01d647
    /*!
Packit 01d647
      @brief Replaces all occurrences of \em searchText in the \em text string
Packit 01d647
             by \em replaceText.
Packit 01d647
     */
Packit 01d647
    void replace(std::string& text, const std::string& searchText, const std::string& replaceText);
Packit 01d647
Packit 01d647
}                                       // namespace Util
Packit 01d647
Packit 01d647
#endif                                  // #ifndef UTILS_HPP_