src/Generic/tokens/SymbolSubstitutionMap.cpp
/**
 * @param file_name the file name of the initialization file.
 */
@param file_name the file name of the initialization file.
@param file_name the file name of the initialization file .
SymbolSubstitutionMap::SymbolSubstitutionMap(const char *file_name) {
	boost::scoped_ptr<UTF8InputStream> in_scoped_ptr(UTF8InputStream::build());
	UTF8InputStream& in(*in_scoped_ptr);
	in.open(file_name);
	std::wstring old_source;
	std::wstring new_source;
	while (!in.eof()) {
		std::getline(in, old_source);
		if (old_source.size() == 0)
			continue;
		if (old_source[old_source.size() - 1] == '\r') 
			old_source.resize(old_source.size() - 1);
		if (!in.eof()) {
			std::getline(in, new_source);
			if (new_source.size() == 0) {
				std::stringstream ss;
				ss << "Unexpected blank line in: " << file_name;
				throw UnexpectedInputException("SymbolSubstitutionMap::SymbolSubstitutionMap",
											   ss.str().c_str());
			}
			if (new_source[new_source.size() - 1] == '\r')
				new_source.resize(new_source.size() - 1);
			add(Symbol(old_source.c_str()), Symbol(new_source.c_str()));
		}
		else {
			std::stringstream ss;
			ss << "No replacement string specified for last entry in: " << file_name;
			in.close();
			throw UnexpectedInputException("SymbolSubstitutionMap::SymbolSubstitutionMap",
										   ss.str().c_str());
		}
	}
	in.close();
}
SymbolSubstitutionMap :: SymbolSubstitutionMap ( const char * file_name ) { boost :: scoped_ptr < UTF8InputStream > in_scoped_ptr ( UTF8InputStream :: build ( ) ) ; UTF8InputStream & in ( * in_scoped_ptr ) ; in . open ( file_name ) ; std :: wstring old_source ; std :: wstring new_source ; while ( ! in . eof ( ) ) { std :: getline ( in , old_source ) ; if ( old_source . size ( ) == 0 ) continue ; if ( old_source [ old_source . size ( ) - 1 ] == ' \r ' ) old_source . resize ( old_source . size ( ) - 1 ) ; if ( ! in . eof ( ) ) { std :: getline ( in , new_source ) ; if ( new_source . size ( ) == 0 ) { std :: stringstream ss ; ss << " " << file_name ; throw UnexpectedInputException ( " " , ss . str ( ) . c_str ( ) ) ; } if ( new_source [ new_source . size ( ) - 1 ] == ' \r ' ) new_source . resize ( new_source . size ( ) - 1 ) ; add ( Symbol ( old_source . c_str ( ) ) , Symbol ( new_source . c_str ( ) ) ) ; } else { std :: stringstream ss ; ss << " " << file_name ; in . close ( ) ; throw UnexpectedInputException ( " " , ss . str ( ) . c_str ( ) ) ; } } in . close ( ) ; }
@param file_name the file name of the initialization file.
@param file_name the file name of the initialization file .
// trim \r if it occurs
