//
//	Safe string operations for fixed-sized strings.
//
//	J. Nagle.
//	Animats
//	www.animats.com
//
//	License: LGPL
//
//	Classic C string operations for boost::char_string and boost::wchar_string
//
//
#ifndef BOOST_FIXED_STRING_CSTRING_HPP
#define BOOST_FIXED_STRING_CSTRING_HPP
#include <cstring>
#include <stddef.h>
#include <stdarg.h>
#include "boost_fixed_string.hpp"

//
//	These are classic names in the default name space for
//	backwards compatibility.  They're overloads on new
//	types, so they will not impact existing code.
//
//
// sprintf -- classic sprintf
//
int sprintf(boost::char_string_base& s, const char* fs ...)
{
    va_list args;
    va_start( args, fs );
    int ret = s.vsnprintf(fs, args );
    va_end( args );
    return(ret);
}

//
//	strcpy -- classic copy
//
const char* strcpy(boost::char_string_base& s1, const char* s2)
{
    s1.copy(s2);
    return(s1.c_str());
}
const char* strcpy(boost::char_string_base& s1, const boost::char_string_base& s2)
{
    s1.copy(s2.c_str());
    return(s1.c_str());
}
//
//	strcat  -- classic concatenate
//
const char* strcat(boost::char_string_base& s1, const char* s2)
{
    s1.append(s2);
    return(s1.c_str());
}
const char* strcat(boost::char_string_base& s1, const boost::char_string_base& s2)
{
    s1.append(s2.c_str());
    return(s1.c_str());
}
//
//	strlen  -- classic length
//
std::size_t strlen(boost::char_string_base& s)
{
    return(s.size());
}


//
// wsprintf -- classic sprintf
//
int sprintf(boost::wchar_string_base& s, const wchar_t* fs ...)
{
    va_list args;
    va_start( args, fs );
    int ret = s.vsnprintf(fs, args );
    va_end( args );
    return(ret);
}

//
//	wstrcpy -- classic copy
//
const wchar_t* wstrcpy(boost::wchar_string_base& s1, const wchar_t* s2)
{
    s1.copy(s2);
    return(s1.c_str());
}
const wchar_t* wstrcpy(boost::wchar_string_base& s1, const boost::wchar_string_base& s2)
{
    s1.copy(s2.c_str());
    return(s1.c_str());
}
//
//	wstrcat  -- classic concatenate
//
const wchar_t* wstrcat(boost::wchar_string_base& s1, const wchar_t* s2)
{
    s1.append(s2);
    return(s1.c_str());
}
const wchar_t* wstrcat(boost::wchar_string_base& s1, const boost::wchar_string_base& s2)
{
    s1.append(s2.c_str());
    return(s1.c_str());
}
//
//	strlen  -- classic length
//
std::size_t strlen(boost::wchar_string_base& s)
{
    return(s.size());
}
#endif
