For a project I am working on, I wanted to add a light-weight markup language the could be parsed into one of Java’s AttributedString (a class used to display formatted strings). This would allow me to right human readable text, but display on the screen in various colors and fonts. I decided to use BBCode as it fit my needs and was relatively simple (although HTML was a close second).
I did not find any existing code that did the job so I wrote up my own parser. Below is the source code. It is not the most robust parser in the world, but it handles properly formatted strings just fine. Not all of the common BBCode tags are supported, although adding additional tags is usually just a matter of adding another if statement to the openTag method.



