class UrlGenerator

A class that allows dynamic creation of URLs from a generator expression.

The UrlGenerator uses two parameters, an expression string and a template string. The expression is specified when constructing the UrlGenerator. The template is specified when executing it. An expression can consist of one or many iterators. The syntax of an iterator has the following format:

'NAME' '[' 'TYPE' ':' 'PARAMETERS' ']'

For example:

A[d:001-020]

This defines an iterator with the name 'A'. Names can only be a single character long. The iterator has the type 'd' (decimal) and runs from 1 to 20 (inclusive). Leading zeros indicate that the iterator will also generate leading zeros in the output. If using this expression with the following template:

http://www.test.com/[A]/[A].html

This will create 20 URLs looking like this:

http://www.test.com/001/001.html
http://www.test.com/020/020.html

You can use more than one iterator, for example:

A[d:001-020] B[d:1-5]

When used with template

http://www.test.com/[A]/[B].html

This will create two loops. The outer loop A runs from 1 to 20, the inner loop B runs from 1 to 5, resulting in 100 URLs. The decimal iterator also has an optional stepping parameter:

A[d:001-020+3]

This will step through the number sequence in steps of 3. The decimal iterator can have more than one range:

A[d:001-020,31-50,61-70]

This will result in a gap in the number sequence between 21 and 30 and again between 51 and 60. Another type of iterator is 'k' (constants). This iterator allows to define a list of arbitrary strings to use:

A[k:hello,world,good,bye]

When used with template

http://www.test.com/[A]/001.html

This will generate four URLs:

http://www.test.com/hello/001.html
http://www.test.com/world/001.html
http://www.test.com/good/001.html
http://www.test.com/bye/001.html

Of course this can be combined with the decimal iterator:

A[k:hello,world,good,bye] B[d:1-5]

You can use up to 26 iterators per expression.

Constructors

UrlGenerator (const string)Creates a new instance and compiles the given generator expression.

Methods

string[] Execute (const string)Executes the generator expression using the given URL template.

Properties

int Valid ()Returns true if the generator expression of this instance is valid.

Reference

method UrlGenerator (const string expression)

Creates a new instance and compiles the given generator expression.


method string[] Execute (const string template)

Executes the generator expression using the given URL template.

The generated URLs are returned as an array of strings. If this function fails, null is returned.


accessor int Valid ()

Returns true if the generator expression of this instance is valid.

If compiling the generator expression passed to the constructor has failed, this will return false.