/// @file octaneclass.cpp
/// Root class for most derived Octane classes
///
/// @remarks
/// It defines some generic methods available to all octane derived
///  parsers, models, coders, etc.
///
/// @author mouser
/// @date   2003.07.29
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// application includes
#include "octaneclass.hpp"
//---------------------------------------------------------------------------

using namespace std;

//---------------------------------------------------------------------------
bool OctaneClass::ParseParameter(const string &parametervalue, bool &param)
{
	// convert and store a bool parameter value
	// ATTN: this is case sensitive and should be changed to case-insensitive
	if (parametervalue == "true")
		param = true;
	else if (parametervalue == "false")
		param = false;
	else if (atoi(parametervalue.c_str()) == 0)
		param = false;
	else if (atoi(parametervalue.c_str()) == 1)
		param = true;
	else
		return false;
	return true;
}
//---------------------------------------------------------------------------



//---------------------------------------------------------------------------
void OctaneClass::NiceifyHighAsciiString(std::string &str)
{
	// walk through string and replace characters that print out weird (line newlines, tabs, backspaces)
	// with a single character.
	// ATTN: i would prefer to change this so that it outputs a non-lossy string using standard \0x01 type codes
	//  and write a helper function to convert from these to binary form, that way we could use this as an alternate
	//  text+human friendly data saving format.
	int count,length;
	unsigned char c;
	length=(int)(str.length());

	for (count=0;count<length;++count)
		{
		c=str[count];
		if (c<32)
			str[count]=1;
		}
}


std::string OctaneClass::PrefixNonEmptyString(const std::string headerstr, const std::string str)
{
	// prefix a non empty string with a header
	if (str!="")
		return headerstr+str;
	else
		return str;
}
//---------------------------------------------------------------------------

