// This file is part of AspectC++.
// Copyright (C) 1999-2015  The AspectC++ developer team.
//                                                                
// This program is free software;  you can redistribute it and/or 
// modify it under the terms of the GNU General Public License as 
// published by the Free Software Foundation; either version 2 of 
// the License, or (at your option) any later version.            
//                                                                
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
// GNU General Public License for more details.                   
//                                                                
// You should have received a copy of the GNU General Public      
// License along with this program; if not, write to the Free     
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
// MA  02111-1307  USA                                            

#ifndef ACBASE_StringUtils_H
#define ACBASE_StringUtils_H

// Collection of string helper functions.

#include <string>

namespace ACBase {

  // Check if the given string only contains space
  // \param str The string to check.
  // \return True if there are only space characters in that string. */
  bool only_whitespace(const std::string &str);

  // Calculate a hash value for a string using the standard C++ algorithm.
  // \param str The input string.
  // \return The hash value. */
  size_t hash(const std::string &str);

  // Replace environment variables of the form ${ENVVAR} in the given string.
  // \param str A reference to the string containing the environment variables.
  // \return A reference to the input string with environment variables replaced by their values. */
  std::string& replace_environment_variables(std::string& str);

  // Check whether a given string starts with some other string
  // \param str The string that is check
  // \param prefix The potential prefix string
  // \return Result of the check
  bool starts_with(const std::string &str, const std::string &prefix);

  // Check whether a given string end with some other string
  // \param str The string that is check
  // \param prefix The potential suffix string
  // \return Result of the check
  bool ends_with(const std::string &str, const std::string &suffix);

  // replace a substring within a string
  // \param subject The string that shall be transformed
  // \param search The string that is searched inside 'subject'
  // \param replace The string that shall replace 'search'
  // \item is_id If true, the searched string is only replaced if the
  //             character before and after the matching substring is
  //             not in an identifier.
  //             (example: don't replace 'shortcut' by 'short intcut')
  void replace_in_string(std::string& subject, const std::string& search,
      const std::string& replace, bool is_id = false);

} // namespace ACBase

#endif /* ACBASE_StringUtils_H */
