CreateToken() public static method

public static CreateToken ( int tokenType, float value ) : JSONToken
tokenType int
value float
return JSONToken
コード例 #1
0
ファイル: Tokenizer.cs プロジェクト: nobuyukinyuu/gdsFM
	JSONToken ParseNumberToken(int firstChar){
		int index = stringIndex-1;
		// First just get the full string
		while (character != ASCIICodes.CHR_SPACE && character != ASCIICodes.CHR_COMMA && 
               character != ASCIICodes.CHR_CLOSE_CURLY && character != ASCIICodes.CHR_CLOSE_SQUARE && character != ASCIICodes.CHR_NUL){
			NextChar();
		}
		if (character == ASCIICodes.CHR_NUL){
			ParseFailure("Unterminated Number");
			return JSONToken.CreateToken(JSONToken.TOKEN_UNKNOWN,null);
		}

		string numberString = jsonString.Slice(index,stringIndex-1);
		
		if (numberString.IndexOf(".") != -1 || numberString.IndexOf("e") != -1 || numberString.IndexOf("E") != -1){
		    return JSONToken.CreateToken(JSONToken.TOKEN_UNPARSED_FLOAT,numberString);
		} else {
			int value = ParseInteger(numberString);
			return JSONToken.CreateToken(JSONToken.TOKEN_INTEGER,value);
		} 
	}
コード例 #2
0
ファイル: Tokenizer.cs プロジェクト: nobuyukinyuu/gdsFM
	public JSONToken NextToken(){
		JSONToken retToken=null;
		SkipIgnored();

        switch (character){
			case ASCIICodes.CHR_OPEN_CURLY:
				retToken = JSONToken.CreateToken(JSONToken.TOKEN_OPEN_CURLY,"{");
                break;
			case ASCIICodes.CHR_CLOSE_CURLY:
				retToken = JSONToken.CreateToken(JSONToken.TOKEN_CLOSE_CURLY,"}");
                break;
			case ASCIICodes.CHR_OPEN_SQUARE:
				retToken = JSONToken.CreateToken(JSONToken.TOKEN_OPEN_SQUARE,"[");
                break;
			case ASCIICodes.CHR_CLOSE_SQUARE:
				retToken = JSONToken.CreateToken(JSONToken.TOKEN_CLOSE_SQUARE,"]");
                break;
			case ASCIICodes.CHR_COMMA:
				retToken = JSONToken.CreateToken(JSONToken.TOKEN_COMMA,",");
                break;
			case ASCIICodes.CHR_COLON:
				retToken = JSONToken.CreateToken(JSONToken.TOKEN_COLON,":");
                break;
			case ASCIICodes.CHR_LOWER_T:
				if (String.Compare(jsonString.Slice(stringIndex,stringIndex+3), "rue") == 0){
					stringIndex += 3;
					retToken = JSONToken.CreateToken(JSONToken.TOKEN_TRUE,"true");
				}
                break;
			case ASCIICodes.CHR_LOWER_F:
				if (String.Compare(jsonString.Slice(stringIndex,stringIndex+4), "alse") == 0){
					stringIndex += 4;
					retToken = JSONToken.CreateToken(JSONToken.TOKEN_FALSE,"false");
				}
                break;
			case ASCIICodes.CHR_LOWER_N:
				if (String.Compare(jsonString.Slice(stringIndex,stringIndex+3),"ull") == 0){
					stringIndex += 3;
					retToken = JSONToken.CreateToken(JSONToken.TOKEN_NULL,"null");
				}
                break;
			case ASCIICodes.CHR_DOUBLE_QUOTE:
				int startIndex = stringIndex;
        		int endIndex = jsonString.IndexOf("\"",stringIndex);
                while (endIndex != -1 && jsonString[endIndex-1] == ASCIICodes.CHR_BACKSLASH){
                    endIndex = jsonString.IndexOf("\"",endIndex+1);
                }
                if (endIndex == -1){
                    ParseFailure("Unterminated string");
                }
				
                retToken = JSONToken.CreateToken(JSONToken.TOKEN_STRING,jsonString.Slice(startIndex,endIndex));
				stringIndex = endIndex+1;
                break;
						
			default:
				// Is it a Number?
				if (character == ASCIICodes.CHR_HYPHEN || IsDigit(character)){
					return ParseNumberToken(character); // We return here because ParseNumberToken moves the token pointer forward
				} else if (character == ASCIICodes.CHR_NUL) {
					retToken = null; // End of string so just leave// 
				}
                break;								
		}

		if (retToken == null){
			ParseFailure("Unknown token, character: " + character.ToString());
			retToken = JSONToken.CreateToken(JSONToken.TOKEN_UNKNOWN,null);
		} else {
			NextChar();
		}
		return retToken;

	}