Instructions to the use of custom strings

Post Reply
Sami Ylismäki
Site Admin
Posts: 31
Joined: 16 Jan 2008, 23:13
VATSIM ID: 878340
Location: Helsinki, Finland
Contact:

Instructions to the use of custom strings

Post by Sami Ylismäki » 04 Feb 2008, 06:20

Custom strings as one of the key features of UniATIS is finally ready for use!

At the moment there are five different types of custom strings available: static, string, metar, url and replace. Static type carries no conditions and will be output everytime. URL type is pretty similar to the static, but is triggered only if it's one of the parameters in the URL sent to the generator. String type is a conditional that will be returned if an another string exist, does not exist or matches with a supplied text.

There is a 'debug' parameter available in the generator which will be helpful when setting up custom strings, especially with the string and metar conditionals. It will display alot of more and less useful raw information from the process of ATIS creation. To get it to work &debug must exist as one of the URL parameters sent to the generator.

A short guide to get started with:

All of the custom strings will be contained in the table of generally available strings, which is to say those will function just like any of the other %% strings on the table and can be used anywhere.

"static" will display it's contents at all times.
Parameters:
static:name:output


static = Defines the type of custom string. For the static string it's "static".
name = Name of the custom string. This should be the name only and nothing else. The string will be then available as %name% in the format and as %mname% in the settings.
output = The output of the string. Can be almost anything.

"url" will only be returned if it exists as a parameter in the URL. The parameter can be with and without a value.
Parameters:
url:name:output


url = Defines the type of custom string. For the URL string it's "url".
name = Name of the custom string. This should be the name only and nothing else. The string will be then available as %name% in the format and as %mname% in the settings. It will be also the name of parameter in the URL.
output = The output of the string. Use %url% to return the value sent in the URL to the generator. e.g. [some %url% string].

"string" will be returned if a string exist, does not exist or matches with a pattern.
Parameters:
string:name:string to match:pattern to match:output


string = Defines the type of custom string. For the STRING string it's "string".
name = Name of the custom string. This should be the name only and nothing else. The string will be then available as %name% in the format and as %mname% in the settings.
string to match = The name of the string to match with the pattern. Refer to the general string table available by the debug parameter to determine the available strings to match, also custom strings other than of the "string" type are possible to match with. Exclude % and the first m/t/b letter from the matched string.
pattern to match = This is either the text to match with the contents of a string or "*" or "-". To check that a string exists use the * as pattern. To check that a string does not exist use the - as the pattern.
output = The output of the string. Can be almost anything.

"metar" will be returned if a certain weather condition exists or matches with a given condition.
Parameters:
metar:name:pattern to match:output


metar = Defines the type of custom string. For the METAR string it's "metar".
name = Name of the custom string. This should be the name only and nothing else. The string will be then available as %name% in the format and as %mname% in the settings.
pattern to match = Pattern to match in the METAR.
output = The output of the string. Can be almost anything.

"replace" is used to match text to a string and replace contents of an another string or the same string with a supplied one
Parameters:
replace:string to match:string to replace:text to match:replacement text


replace = Defines the type of custom string. For the REPLACE function it's "replace".
string to match = String which contents should match with the text to match
string to replace = String to replace with replacement text if the content matches
text to match = Text to match in the contents string to match
replacement text = Text used to replace the contents of string to replace

Sami Ylismäki
Site Admin
Posts: 31
Joined: 16 Jan 2008, 23:13
VATSIM ID: 878340
Location: Helsinki, Finland
Contact:

Regular expressions

Post by Sami Ylismäki » 18 Feb 2008, 04:51

String, replace and metar custom functions support regular expressions.

A short guide to regular expression:

- A search string without meta-characters will be searched from anywhere in the content
- Any displayed non-alphanumerical character must be preceeded with backslash '\', e.g. characters \*.?$^&()[]{}
- ^ must be used to match string to the content from the beginning
- $ must be used to match string to the content from the end
- A search string beginning with ^ and ending to $ means the content must match the search string exactly
- . is a wildcard character that will match any single character
- .* is a wildcard that will match any character of any lenght
- ( and ) are used to retrieve the pattern from the content and can be returned with $1 in the replacement text. Subsequent brackets will increase the $ count correctspondingly. $0 will return the whole match.
- ? is a conditional used after a searchable pattern. The preceeding pattern doesn't have to exist for the match to complete.
- [ and ] is used for character class definition, e.g. [0-9] will match any numerical pattern of one character OR as defined. [ABC] will match only letters A, B and C. Any character can be used.
- { and } is used to determine the lenght of subsequent characters in a pattern, e.g. [0-9]{2} will search for any numerical pattern with a lenght of two. [0-9]{1,2} will search for any numerical pattern with a lenght of one OR two. * without brackets can be used instead to match the pattern of any lenght.
- | is start of an alternative branch. the condition will be true if the pattern before or after the character is found in the string. Any number of these can be used in regular expression.


Examples:
EFHK - this will search for any occurance "EFHK" from anywhere in the searchable string, e.g. anyEFHKtext will be return as true.
[ ]EFHK[ ] - Same as the above, but with a single space in front and after the text, e.g "any EFHK text" will be returned as true while "anyEFHKtext" will not.
^EFHK$ - This will search for the same text but with the condition that it must be the only content of a searchable string. 1 to 1 match.
^EFHK - Works with the same principle as the above, but can be followed by subsequent characters after "EFHK".
EFHK$ - Same as the above vice-versa. EFHK can be preceeded by other characters.
(EFHK) - EFHK closed within brackets returns "EFHK" as $1 that can be passed into the replacement text. Other syntaxes can be used with this just as above.
(EFHK)(text) - Same as the above, but will return "EFHK" as $1 and "text" followed by it as $2. [ ] in between the patterns would match space.
\[ - matches [ character in the searched text. Same goes for other non-alphanumeric characters.
[EFHK] - This will NOT match "EFHK", but letters E, F, H and K in the searched text.
[EFHK]{3} - Same principle as in the above, but will seek for any combination of E,F,H and K in a group of three letters, e.g. FKH, EKH, EFH, KEF and so on.
[0-9]{1,2} - Exactly the same principle as in the above, but will search for numbers in the range of 0 to 99. Just {2} would search for numbers in the range of 00(,01,02,03..) to 99.
EFHK|EFTU|EFPO - Will return true if the searched text contains EFHK, EFTU or EFPO. Any number of alternatives is allowed.
(EFHK)|(EFTU)|(EFPO) - Same as the above, except the result will be returned as $1.

(.*)(122,8)\[\.\]$ - This pattern will match for "122,8[.]" as the last pattern the text, but which can be preceeded by anything. "122,8" will be returned as $2, while the preceeding text will be returned as $1. Pay attention to the use of \ with characters '[', ']' and '.'
Functional example of the above:
replace:mdepfreq:mdepfreq:(.*)(122,8)\[\.\]$:$1[UNICOM][on frequency]$2[.]
This will do the following:
[Attention!][Departure frequency for all departing aircraft is]122,8[.]
is replaced with
[Attention!][Departure frequency for all departing aircraft is][UNICOM][on frequency]122,8[.]


More information on the regular expression:
http://www.php.net/manual/en/reference. ... syntax.php
http://en.wikipedia.org/wiki/Regular_expression

Sami Ylismäki
Site Admin
Posts: 31
Joined: 16 Jan 2008, 23:13
VATSIM ID: 878340
Location: Helsinki, Finland
Contact:

Re: Instructions to the use of custom strings

Post by Sami Ylismäki » 27 Oct 2009, 02:44

Metar custom function now supports regular expression and instead of searching for weather from the decoded weather the search will now be done on the METAR itself. This will make the function much more flexible along with the regular expression pattern match.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest