Beispiel #1
0
os::String Format_Ruby::GetIndentString( const os::String &line, bool useTabs, uint tabSize )
{
	if(line.size()==0)
		return "";

	uint white;
	for(white=0;white<line.size();++white)
		if(line[white]!=' ' && line[white]!='\t')			
			break;
			
	//TODO: ignore trailing whitespace
	if(line[line.size()-1]=='{' || line[line.size()-1]==':'){
		os::String pad;		
		if(useTabs)
			pad="\t";
		else
			pad.resize(tabSize, ' ');
			
		return os::String(line.const_str().substr(0, white))+pad;
	}else
		return line.const_str().substr(0, white);
}
Beispiel #2
0
//TODO: this method is slightly wrong. Fix it
void Format_Ruby::FindWords( const os::String &line, os::String &format )
{
	uint start=0, end;

	while(start<line.size() && (format[start]!=F_DEFAULT || !canStartIdentifier(line[start])))
		++start;

	end=start+1;
	while(end<line.size() && format[end]==F_DEFAULT && canContinueIdentifier(line[end]))
		++end;

	while(start<line.size()){
		os::String tmp=line.const_str().substr(start, end-start);

		int max=sizeof(keywords)/sizeof(keywords[0]);
		int min=0;
		int test=max/2;

		//binary search
		while(max-min>1){
			if(!strcmp(keywords[test], tmp.c_str()))
				break;
			if(tmp<keywords[test])
				max=test;
			else
				min=test;
			test=(max+min)/2;
		}
		if(!strcmp(keywords[test], tmp.c_str())){
			for(;start<end;++start)
				format[start]=F_KEYWORD;
		}

		start=end+1;

		while(start<line.size() && (format[start]!=F_DEFAULT || !canStartIdentifier(line[start])))
			++start;

		end=start+1;
		while(end<line.size() && format[end]==F_DEFAULT && canContinueIdentifier(line[end]))
			++end;
	}
}