Back to project page BestBoard.
The source code is released under:
MIT License
If you think the Android project BestBoard listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package digitalgarden.bestboard; //from w w w.j a v a 2 s .c o m import java.io.IOException; import java.io.StringReader; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import digitalgarden.magicmerlin.scribe.Scribe; import digitalgarden.magicmerlin.utils.Tokenizer; public class TokenizerTest extends Activity { private TextView text; private EditText edit; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tokenizer_test); text = (TextView) findViewById( R.id.text ); edit = (EditText) findViewById( R.id.edit ); findViewById( R.id.button ).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { StringReader reader = new StringReader( edit.getText().toString() ); text.setText("Tokens:\n"); try { Tokenizer tokenizer = new Tokenizer( reader ); int type; while (true) { type = tokenizer.nextToken(); if ( type == Tokenizer.TYPE_EOF ) { text.setText( text.getText() + " EOF"); break; } if ( type == Tokenizer.TYPE_EOL ) { text.setText( text.getText() + " EOL\n"); continue; } if (type == Tokenizer.TYPE_STRING ) { text.setText( text.getText() + "String: " + tokenizer.getStringToken() + "; "); Scribe.note( "String: " + tokenizer.getStringToken() ); } else if (type == Tokenizer.TYPE_KEYWORD ) { text.setText( text.getText() + "Keyword: " + tokenizer.getStringToken() + " = 0x" + Long.toHexString( tokenizer.getIntegerToken() ) + "L; "); Scribe.note("Keyword: " + tokenizer.getStringToken() + " = 0x" + Long.toHexString( tokenizer.getIntegerToken() ) + "L"); } else if (type == Tokenizer.TYPE_INTEGER ) { text.setText( text.getText() + "Long: " + tokenizer.getStringToken() + " = " + tokenizer.getIntegerToken() + " ("+ Long.toHexString(tokenizer.getIntegerToken()).toUpperCase() + "h); "); Scribe.note("Long: " + tokenizer.getStringToken() + " = " + tokenizer.getIntegerToken() + " ("+ Long.toHexString(tokenizer.getIntegerToken()).toUpperCase() + "h)"); } else if (type == Tokenizer.TYPE_FRACTION ) { text.setText( text.getText() + "Double: " + tokenizer.getStringToken() + " = " + tokenizer.getDoubleToken() + "; "); Scribe.note("Double: " + tokenizer.getStringToken() + " = " + tokenizer.getDoubleToken() ); } else if (type == Tokenizer.TYPE_CHARACTER ) { text.setText( text.getText() + "Character: [" + tokenizer.getStringToken() + "] = " + Long.toHexString( tokenizer.getIntegerToken() ) + "; "); Scribe.note("Character: [" + tokenizer.getStringToken() + "] = " + Long.toHexString( tokenizer.getIntegerToken() )); } else { text.setText( text.getText() + "Unknown type; "); Scribe.error("Unknown type; "); } } } catch (IOException e) { text.setText( text.getText() + "READ ERROR: " + e.toString()); Scribe.error("READ ERROR: " + e.toString()); } } }); } }