// joycub V2 - an interpeter for the programming language Joy
// (c) 2004-2006 Sergey Zubkov 
// prototype.cc - prototype module to test out the new design considerations
static char RCSID[] ="$Id: string.cc,v 1.1 2006/02/27 18:50:34 cubbi Exp cubbi $";

#include <iostream>
#include "exceptions.h"
#include "string.h"
#include "char.h"

// global object counters (for memory debugging)
int string_type_count = 0;

JC_string::JC_string(const std::string& s) {
	for(unsigned int i=0; i<s.size(); i++) {
		if( s[i]=='\\' && i<s.size()-1) {
				string ss="  ";
				ss[0]=s[i];
				ss[1]=s[++i];
			contents.push_back(new JC_objref(new JC_char(ss)));
		} else {
			contents.push_back(new JC_objref(new JC_char(s[i])));
		}
	}
	string_type_count++;
};

//JC_string::JC_string(const JC_string& j) {
//	contents = j.contents;
//	string_type_count++;
//};

JC_string::~JC_string(void) {
	string_type_count--;
};

std::string JC_string::to_string(void) const {
	std::ostringstream s;
	for(vector<JC_objref*>::const_iterator it = contents.begin();
		it!=contents.end(); it++ ) {
		s << (*it)->to_char();
	}
	return s.str();
}
std::string JC_string::to_output_string(void) const {
	return "\""+to_string()+"\"";
}
void JC_string::debug_print(void) const {
	std::cout << to_string();
};

std::string JC_string::key(void) const { return to_string(); };

