This is a test post.
Now to try SyntaxHighlighter.
package org.tryki.utils
import java.io.{File, FileReader, LineNumberReader, Reader}
/**
* A very simple way of externalizing blocks of text for testing. A chunk file
* consists of an ignored header area, followed by one or more chunks. Each
* chunk has the name in square brackets, followed by the text. Lines beginning
* with '#' are also ignored. Example:
*
*
* This is ignored
*
* [foo]
* # A comment for this chunk; not included in text
* This is the value of the chunk named "foo"
*
* [bar]
* This is the value of the chunk named "bar"
*
*/
class ChunkFile(r: Reader)
{
def this(f: File) = this(new FileReader(f))
private val chunks =
{
val lnr = new LineNumberReader(r)
var x = 1
def read(section: String, value: String): Map[String,String] = {
val line = lnr.readLine()
if (line == null)
Map(section -> value)
else if (line.matches("^\\[.*\\]$"))
read(line.substring(1, line.length-1), "") + (section -> value)
else if (!line.startsWith("#"))
read(section, value + line + "\n")
else
read(section, value)
}
read("", "")
}
/**
* Return the named chunk, ornullif there was none in the
* text source with that name.
*/
def apply(name: String) =
chunks.getOrElse(name, null)
/**
* Return the names of all the chunks.
*/
def names = chunks.keys
}
That's the code.
0 comments:
Post a Comment