package com.html5parser.tokenizerStates;

import org.omg.CORBA.PRIVATE_MEMBER;

import com.html5parser.classes.ASCIICharacter;
import com.html5parser.classes.ParserContext;
import com.html5parser.classes.Token;
import com.html5parser.classes.Token.TokenType;
import com.html5parser.classes.TokenizerContext;
import com.html5parser.classes.TokenizerState;
import com.html5parser.factories.TokenizerStateFactory;
import com.html5parser.interfaces.ITokenizerState;

public class RCDATA_end_tag_open_state implements ITokenizerState {
	@Override
	public  ParserContext process(ParserContext context) {
		TokenizerStateFactory factory = TokenizerStateFactory.getInstance();
		TokenizerContext tokenizerContext = context.getTokenizerContext();		
		int currentChar = tokenizerContext.getNextInputCharacter();
		tokenizerContext.setCurrentInputCharacter(currentChar);
		
		ASCIICharacter asciiCharacter = tokenizerContext.getCurrentASCIICharacter();
		
		switch(asciiCharacter){		
		
		case LATIN_CAPITAL_LETTER:
			/*Create a new end tag token, and set its tag name to the lowercase version of the 
			 * current input character (add 0x0020 to the character's code point). Append the 
			 * current input character to the temporary buffer. Finally, switch to the RCDATA 
			 * end tag name state. (Don't emit the token yet; further details will be filled 
			 * in before it is emitted.)
			 */
			currentChar += 0x0020;
			String addedChar = String.valueOf(Character.toChars(currentChar));
			Token token = new Token(TokenType.end_tag, addedChar);
			tokenizerContext.getTemporaryBuffer().concat(addedChar);
			tokenizerContext.setCurrentToken(token);
			tokenizerContext.setNextState(factory.getState(TokenizerState.Tag_name_state));
			break;
		case LATIN_SMALL_LETTER:
			String addedChar_1 = String.valueOf(Character.toChars(currentChar));
			Token token_2 = new Token(TokenType.end_tag, addedChar_1);
			tokenizerContext.getTemporaryBuffer().concat(addedChar_1);
			tokenizerContext.setCurrentToken(token_2);
			tokenizerContext.setNextState(factory.getState(TokenizerState.Tag_name_state));
			break;
		default:
			tokenizerContext.setNextState(factory.getState(TokenizerState.RCDATA_state));
			tokenizerContext.emitCurrentToken(new Token(TokenType.character, String.valueOf(0x003C)));
			tokenizerContext.emitCurrentToken(new Token(TokenType.character, String.valueOf(0x002F)));
			tokenizerContext.setFlagReconsumeCurrentInputCharacter(true);			
			break;
		}
		
		context.setTokenizerContext(tokenizerContext);
		
		return context;
		
	}

}

@@ -1799,16 +1799,330 @@
 ETTER:%0D%0A
+%09%09%09/* Create a new end tag token, and set its tag name to the current input character. %0D%0A%09%09%09 * Append the current input character to the temporary buffer. Finally, %0D%0A%09%09%09 * switch to the RCDATA end tag name state. (Don't emit the token yet; %0D%0A%09%09%09 * further details will be filled in before it is emitted.)%0D%0A%09%09%09 */%0D%0A
 %09%09%09Strin

add comments