Mercury library  1.0
Translation of CFG grammars into an object model (Bachelor's thesis).
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties
Classes | Static Public Member Functions | List of all members
Mercury.Extensions Class Reference

Provides extension methods for the Mercury library. More...

Static Public Member Functions

static bool Power2 (int x)
 Checks whether the given number is a power of two More...
 
static int IntegralPow (int a, uint exp)
 Computes an integral power of given number More...
 
static string UniqueCharSeq ()
 Creates a unique sequence of [A-Za-z] characters. More...
 
static string RandomString (int length, string init="")
 Creates a random [A-Za-z] string. More...
 
static string RandomString (string pattern)
 Creates a random string according to the pattern. The pattern can contain any characters that will remain unchanged, except the following which will be replaced:
. - a random [A-Za-z] character
% - a random digit
* - a unique sequence of [A-Za-z0-9] chars (useful when generating random names) More...
 
static IList< TokenTokenize (this string src)
 Uses defaultTokenizer (Mercury.Nucleus.Tokens.Tokenizer) to tokenize string More...
 
static string Unescape (this string src)
 Removes '\' from the string more efficiently than src.Where(x => x != '\') More...
 
static IMultiDictionary< TKey,
TValue > 
ToMultiDictionary< TSource, TKey, TValue > (this IEnumerable< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TValue > valueSelector)
 Creates a multidictionary from the sequence of values More...
 
static IMultiDictionary< TKey,
TSource > 
ToMultiDictionary< TSource, TKey > (this IEnumerable< TSource > source, Func< TSource, TKey > keySelector)
 Creates a MultiDictionary from the sequence of values More...
 
static T ElementAtOrLast< T > (this IReadOnlyList< T > source, int index)
 Returns the element specified by the index or the last element if the index is greater than number of elements More...
 

Detailed Description

Provides extension methods for the Mercury library.

Definition at line 12 of file Extensions.cs.

Member Function Documentation

static T Mercury.Extensions.ElementAtOrLast< T > ( this IReadOnlyList< T >  source,
int  index 
)
static

Returns the element specified by the index or the last element if the index is greater than number of elements

Template Parameters
TType of elements
Parameters
sourceThe source list
indexThe index
Returns
Element

Definition at line 233 of file Extensions.cs.

static int Mercury.Extensions.IntegralPow ( int  a,
uint  exp 
)
static

Computes an integral power of given number

Parameters
aInteger to exponentiate.
expThe exponent.
Returns
a to the power of exp .

Adapted from http://stackoverflow.com/a/383596

Definition at line 90 of file Extensions.cs.

static bool Mercury.Extensions.Power2 ( int  x)
static

Checks whether the given number is a power of two

Parameters
xThe number
Returns
true iff the number is power of 2

Definition at line 82 of file Extensions.cs.

static string Mercury.Extensions.RandomString ( int  length,
string  init = "" 
)
static

Creates a random [A-Za-z] string.

Parameters
lengthThe length of the string.
initInitial value. Not included in the length .
Returns
A string of random [A-Za-z] characters.

Definition at line 115 of file Extensions.cs.

static string Mercury.Extensions.RandomString ( string  pattern)
static

Creates a random string according to the pattern. The pattern can contain any characters that will remain unchanged, except the following which will be replaced:
. - a random [A-Za-z] character
% - a random digit
* - a unique sequence of [A-Za-z0-9] chars (useful when generating random names)

Parameters
patternThe pattern
Returns

Definition at line 135 of file Extensions.cs.

static IList<Token> Mercury.Extensions.Tokenize ( this string  src)
static

Uses defaultTokenizer (Mercury.Nucleus.Tokens.Tokenizer) to tokenize string

Parameters
srcthis string
Returns
token values

Definition at line 161 of file Extensions.cs.

static IMultiDictionary<TKey, TSource> Mercury.Extensions.ToMultiDictionary< TSource, TKey > ( this IEnumerable< TSource >  source,
Func< TSource, TKey >  keySelector 
)
static

Creates a MultiDictionary from the sequence of values

Template Parameters
TSourceThe type of the source value
TKeyThe type of the key
Parameters
sourceThe source sequence
keySelectorThe key selector function
Returns

Definition at line 216 of file Extensions.cs.

static IMultiDictionary<TKey, TValue> Mercury.Extensions.ToMultiDictionary< TSource, TKey, TValue > ( this IEnumerable< TSource >  source,
Func< TSource, TKey >  keySelector,
Func< TSource, TValue >  valueSelector 
)
static

Creates a multidictionary from the sequence of values

Template Parameters
TSourceThe type of the source values
TKeyThe type of the key
TValueThe type of the values
Parameters
sourceThe source enumeration
keySelectorThe key selector function
valueSelectorThe value selector function
Returns
The MultiDictionary

Definition at line 197 of file Extensions.cs.

static string Mercury.Extensions.Unescape ( this string  src)
static

Removes '\' from the string more efficiently than src.Where(x => x != '\')

Parameters
srcThe source string
Returns
The string without '\' characters

Definition at line 169 of file Extensions.cs.

static string Mercury.Extensions.UniqueCharSeq ( )
static

Creates a unique sequence of [A-Za-z] characters.

Returns
A unique equence.

Definition at line 108 of file Extensions.cs.


The documentation for this class was generated from the following file: