//==============================================================================
/*
    Software License Agreement (BSD License)
    Copyright (c) 2003-2016, CHAI3D.
    (www.chai3d.org)

    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
    copyright notice, this list of conditions and the following
    disclaimer in the documentation and/or other materials provided
    with the distribution.

    * Neither the name of CHAI3D nor the names of its contributors may
    be used to endorse or promote products derived from this software
    without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

*/
//==============================================================================

//------------------------------------------------------------------------------
#ifndef CStringH
#define CStringH
//------------------------------------------------------------------------------
#include <string>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <sstream>
//------------------------------------------------------------------------------


#include "CMaths.h"
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
namespace chai3d {
//------------------------------------------------------------------------------

//==============================================================================
/*!
    \file       CString.h
    \ingroup    system

    \brief
    Implements utility functions for manipulating strings.
*/
//==============================================================================

//------------------------------------------------------------------------------
/*!
    \addtogroup system
*/
//------------------------------------------------------------------------------

//==============================================================================
/*!
    This function computes the length of an __ANSI string__ of up to 255 characters.
    If the end of the string cannot be found, then -1 is returned as a result.

    \param  a_input  Input __ANSI string__. (Pointer to first character).

    \return Length of input string, otherwise -1.
*/
//==============================================================================
int cStrLength(const char* a_input)
{
    return (int)(strlen(a_input));
}


//=================================================================================
/*!
    This function converts a __boolean__ into a __string__.

    \param  a_value  Input value of type __boolean__.

    \return Converted value into __string__ format.
*/
//=================================================================================
std::string cStr(const bool a_value)
{
    std::string result;
    if (a_value)
    {
        result = "true";
    }
    else
    {
        result = "false";
    }
    return (result);
}


//=================================================================================
/*!
    This function converts an __integer__ into a __string__.

    \param  a_value  Input value of type __integer__.

    \return Converted value into __string__ format.
*/
//==============================================================================
std::string cStr(const int a_value)
{
    std::ostringstream result;
    result << a_value;
    return (result.str());
}


//==============================================================================
/*!
    This function converts an __unsigned integer__ into a __string__.

    \param  a_value  Input value of type __unsigned integer__.

    \return Converted value into __string__ format.
*/
//==============================================================================
std::string cStr(const unsigned int a_value)
{
    std::ostringstream result;
    result << a_value;
    return (result.str());
}


//==============================================================================
/*!
    This function converts a __float__ into a __string__.

    \param  a_value      Input value of type __float__.
    \param  a_precision  Number of digits displayed after the decimal point.

    \return Converted value into __string__ format.
*/
//==============================================================================
std::string cStr(const float a_value, const unsigned int a_precision)
{
    std::ostringstream result;
    result << std::fixed << std::setprecision(a_precision) << a_value;
    return (result.str());
}


//==============================================================================
/*!
    This function converts a __double__ into a __string__.

    \param  a_value      Input value of type __double__.
    \param  a_precision  Number of digits displayed after the decimal point.

    \return Converted value into __string__ format.
*/
//==============================================================================
std::string cStr(const double a_value, const unsigned int a_precision)
{
    std::ostringstream result;
    result << std::fixed << std::setprecision(a_precision) << a_value;
    return (result.str());
}


//==============================================================================
/*!
    This function converts a __string__ into __lowercase__.

    \param  a_input  Input string to be converted.

    \return Converted __string__.
*/
//==============================================================================
std::string cStrToLower(const std::string& a_input)
{
    std::string result = a_input;
    std::transform(result.begin(), result.end(), result.begin(), ::tolower);
    return (result);
}

//------------------------------------------------------------------------------
} // namespace chai3d
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
#endif
//------------------------------------------------------------------------------
