Mercury library 1.0 Translation of CFG grammars into an object model (Bachelor's thesis).

- Main Page
- Packages
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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< Token > | Tokenize (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

  T | Type of elements

Parameters

  source | The source list
  index | The 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

  a | Integer to exponentiate.
  exp | The 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

  x | The 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

  length | The length of the string.
  init | Initial 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

  pattern | The 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

  src | this 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

  TSource | The type of the source value
  TKey | The type of the key

Parameters

  source | The source sequence
  keySelector | The 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

  TSource | The type of the source values
  TKey | The type of the key
  TValue | The type of the values

Parameters

  source | The source enumeration
  keySelector | The key selector function
  valueSelector | The 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

  src | The 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:

- Mercury/Mercury/Extensions.cs