<commit_before>//-----------------------------------------------------------------------bl-
//--------------------------------------------------------------------------
// 
// GRINS - General Reacting Incompressible Navier-Stokes 
//
// Copyright (C) 2010-2013 The PECOS Development Team
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Version 2.1 GNU Lesser General
// Public License as published by the Free Software Foundation.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc. 51 Franklin Street, Fifth Floor,
// Boston, MA  02110-1301  USA
//
//-----------------------------------------------------------------------el-


#ifndef GRINS_STRING_UTILS_H
#define GRINS_STRING_UTILS_H

// libMesh
#include "libmesh/libmesh_common.h"

// C++
#include <sstream>
#include <string>
#include <vector>

namespace GRINS
{
  template <typename T>
  inline
  T string_to_T(const std::string& input)
  {
    std::istringstream converter(input);
    T returnval;
    converter >> returnval;
    libmesh_assert(!converter.fail());
    return returnval;
  }

  /*!
    Split on colon, and return name, int value pair.
    Taken from FIN-S for XML parsing.
   */
  inline
  std::pair<std::string, int> split_string_int_on_colon(const std::string &token)
  {
    std::pair<std::string, int> ret = std::make_pair(std::string(), 0);
    std::string::size_type colon_position = token.find(":");
    libmesh_assert (colon_position != std::string::npos);
    ret.first  = token.substr(0, colon_position);
    ret.second = std::atoi(token.substr(colon_position + 1).c_str());
    return ret;
  }


  /*!
    Split on colon, and return name, double value pair.
    Taken from FIN-S for XML parsing.
   */
  inline
  std::pair<std::string, double> split_string_double_on_colon(const std::string &token)
  {
    std::pair<std::string, double> ret = std::make_pair(std::string(), 0.0);
    std::string::size_type colon_position = token.find(":");
    libmesh_assert (colon_position != std::string::npos);
    ret.first  = token.substr(0, colon_position);
    ret.second = std::atof(token.substr(colon_position + 1).c_str());
    return ret;
  }


  /*!
    Taken from FIN-S for XML parsing.
   */
  inline
  int SplitString(const std::string& input, 
		  const std::string& delimiter, 
		  std::vector<std::string>& results, 
		  bool includeEmpties = true)
  {
    using std::vector;
    using std::string;
    
    int iPos = 0;
    int newPos = -1;
    int sizeS2 = (int)delimiter.size();
    int isize = (int)input.size();
    
    if( 
       ( isize == 0 )
       ||
       ( sizeS2 == 0 )
	)
      {
	return 0;
      }

    vector<int> positions;

    newPos = input.find (delimiter, 0);

    if( newPos < 0 )
      { 
	return 0; 
      }<commit_msg>Fix SplitString function for the case where there's one entry and no delimiters.<commit_after>//-----------------------------------------------------------------------bl-
//--------------------------------------------------------------------------
// 
// GRINS - General Reacting Incompressible Navier-Stokes 
//
// Copyright (C) 2010-2013 The PECOS Development Team
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the Version 2.1 GNU Lesser General
// Public License as published by the Free Software Foundation.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc. 51 Franklin Street, Fifth Floor,
// Boston, MA  02110-1301  USA
//
//-----------------------------------------------------------------------el-


#ifndef GRINS_STRING_UTILS_H
#define GRINS_STRING_UTILS_H

// libMesh
#include "libmesh/libmesh_common.h"

// C++
#include <sstream>
#include <string>
#include <vector>

namespace GRINS
{
  template <typename T>
  inline
  T string_to_T(const std::string& input)
  {
    std::istringstream converter(input);
    T returnval;
    converter >> returnval;
    libmesh_assert(!converter.fail());
    return returnval;
  }

  /*!
    Split on colon, and return name, int value pair.
    Taken from FIN-S for XML parsing.
   */
  inline
  std::pair<std::string, int> split_string_int_on_colon(const std::string &token)
  {
    std::pair<std::string, int> ret = std::make_pair(std::string(), 0);
    std::string::size_type colon_position = token.find(":");
    libmesh_assert (colon_position != std::string::npos);
    ret.first  = token.substr(0, colon_position);
    ret.second = std::atoi(token.substr(colon_position + 1).c_str());
    return ret;
  }


  /*!
    Split on colon, and return name, double value pair.
    Taken from FIN-S for XML parsing.
   */
  inline
  std::pair<std::string, double> split_string_double_on_colon(const std::string &token)
  {
    std::pair<std::string, double> ret = std::make_pair(std::string(), 0.0);
    std::string::size_type colon_position = token.find(":");
    libmesh_assert (colon_position != std::string::npos);
    ret.first  = token.substr(0, colon_position);
    ret.second = std::atof(token.substr(colon_position + 1).c_str());
    return ret;
  }


  /*!
    Taken from FIN-S for XML parsing.
   */
  inline
  int SplitString(const std::string& input, 
		  const std::string& delimiter, 
		  std::vector<std::string>& results, 
		  bool includeEmpties = true)
  {
    using std::vector;
    using std::string;
    
    int iPos = 0;
    int newPos = -1;
    int sizeS2 = (int)delimiter.size();
    int isize = (int)input.size();
    
    if( 
       ( isize == 0 )
       ||
       ( sizeS2 == 0 )
	)
      {
	return 0;
      }

    vector<int> positions;

    newPos = input.find (delimiter, 0);

    /* We already checked if the input size was zero, so if we didn't
       find any delimiters, we assume that there is exactly one entry
       in the input and just return that. */
    /*! \todo We should probably try and trim white space in this case */
    if( newPos == input.npos )
      { 
        results.push_back(input);

        // We found 1 entry
        return 1;
      }
{'fraction_non_alphanumeric': 0.17870439314966494, 'fraction_numerical': 0.01131794489947878, 'mean_word_length': 2.3748743718592964, 'pattern_counts': {'":': 4, '<': 24, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2223689', 'n_tokens_mistral': 2099, 'n_tokens_neox': 1984, 'n_words': 630}