Enhanced C#
Language of your choice: library documentation
|
Contains global functions that don't belong in any specific class. More...
Contains global functions that don't belong in any specific class.
Note: helper methods for parsing and printing tokens and hex digits have been moved to Loyc.Syntax.ParseHelpers.
Public static fields | |
static readonly object | BoxedFalse = false |
Singleton false cast to object. | |
static readonly object | BoxedTrue = true |
Singleton true cast to object. | |
static readonly object | BoxedVoid = new @void() |
Singleton void cast to object. | |
Public Member Functions | |
delegate void | ActionRefT< T > (ref T arg) |
Static Public Member Functions | |
static void | Swap< T > (ref T a, ref T b) |
static void | Swap (ref dynamic a, ref dynamic b) |
static bool | SortPair< T > (ref T lo, ref T hi, Comparison< T > comp) |
static bool | SortPair< T > (ref T lo, ref T hi) |
static bool | IsOneOf< T > (this T value, T item1, T item2) |
static bool | IsOneOf< T > (this T value, T item1, T item2, T item3) |
static bool | IsOneOf< T > (this T value, T item1, T item2, T item3, T item4) |
static bool | IsOneOf< T > (this T value, T item1, T item2, T item3, T item4, T item5) |
static bool | IsOneOf< T > (this T value, params T[] set) |
static T | With< T > (this T obj, Action< T > action) |
Calls action(obj) , then returns the same object. More... | |
static T | With< T > (this T obj, ActionRefT< T > action) |
Calls action(ref obj) , then returns the same object. More... | |
static T | With< T > (this T obj, Func< T, T > action) |
Returns action(obj) . This is similar to the other overload of this method, except that the action has a return value. More... | |
static R | Do< T, R > (this T obj, Func< T, R > action) |
Returns action(obj) . This method lets you embed statements in any expression. More... | |
static bool | True< T > (T value) |
Returns true. This method has no effect; it is used to do an action in a conditional expression. More... | |
static bool | True (Action action) |
This method simply calls the delegate provided and returns true. It is used to do an action in a conditional expression. More... | |
static Comparison< T > | ToComparison< T > () |
Gets a Comparison<T> for the specified type. More... | |
static Func< T, T, int > | ToComparisonFunc< T > () |
static Comparison< T > | ToComparison< T > (IComparer< T > pred) |
Converts an IComparer<T> to a Comparison<T>. More... | |
static Func< T, T, int > | ToComparisonFunc< T > (IComparer< T > pred) |
Converts an IComparer<T> to a Func(T,T,int). More... | |
static List< string > | SplitCommandLineArguments (string listString) |
static string | MakeValidFileName (string text, char? replacement='_', bool fancy=true) |
Replaces characters in text that are not allowed in file names with the specified replacement character. More... | |
static bool | Verify (bool condition) |
Same as Debug.Assert except that the argument is evaluated even in a Release build. More... | |
static string | BareHtmlEntityNameForAscii (char c) |
Gets a bare HTML entity name for an ASCII character, or null if there is no entity name for the given character, e.g. BareHtmlEntityNameForAscii('"') == "quot" . More... | |
static int | CountOnes (byte x) |
Returns the number of bits that are set in the specified integer. More... | |
static int | CountOnes (int x) |
Returns the number of bits that are set in the specified integer. More... | |
static int | CountOnes (uint x) |
static double | Int64BitsToDouble (long bits) |
static long | DoubleToInt64Bits (double value) |
static int | Log2Floor (uint x) |
static int | Log2Floor (int x) |
Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9 More... | |
static double | ShiftLeft (double num, int amount) |
static double | ShiftRight (double num, int amount) |
static int | DecodeBase64Digit (char digit, string digit62="+-.~", string digit63="/_,") |
static char | EncodeBase64Digit (int digit, char digit62='+', char digit63='/') |
static WordWrapCharType | GetWordWrapCharType (int c) |
This function controls the default character categorization used by overloads of WordWrap(string, int, Func<int, WordWrapCharType>). More... | |
static List< string > | WordWrap (string paragraph, int lineWidth) |
Breaks a paragraph into lines using a simple word-wrapping algorithm. More... | |
static List< string > | WordWrap (IEnumerable< Pair< int, int >> paragraph, int lineWidth, Func< int, WordWrapCharType > getCharType=null) |
Breaks a paragraph into lines using a simple word-wrapping algorithm. More... | |
static bool | IsInRangeExcludeHi (this int num, int lo, int hi) |
Returns true if num is between lo and hi , excluding hi but not lo . More... | |
static bool | IsInRange (this int num, int lo, int hi) |
Returns true if num is between lo and hi . More... | |
static int | PutInRange (this int n, int min, int max) |
Returns num clamped to the range min and max . More... | |
static bool | IsInRangeExcludeHi (this uint num, uint lo, uint hi) |
Returns true if num is between lo and hi , excluding hi but not lo . More... | |
static bool | IsInRange (this uint num, uint lo, uint hi) |
Returns true if num is between lo and hi . More... | |
static uint | PutInRange (this uint n, uint min, uint max) |
Returns num clamped to the range min and max . More... | |
static bool | IsInRangeExcludeHi (this long num, long lo, long hi) |
Returns true if num is between lo and hi , excluding hi but not lo . More... | |
static bool | IsInRange (this long num, long lo, long hi) |
Returns true if num is between lo and hi . More... | |
static long | PutInRange (this long n, long min, long max) |
Returns num clamped to the range min and max . More... | |
static bool | IsInRangeExcludeHi (this ulong num, ulong lo, ulong hi) |
Returns true if num is between lo and hi , excluding hi but not lo . More... | |
static bool | IsInRange (this ulong num, ulong lo, ulong hi) |
Returns true if num is between lo and hi . More... | |
static ulong | PutInRange (this ulong n, ulong min, ulong max) |
Returns num clamped to the range min and max . More... | |
static bool | IsInRangeExcludeHi (this float num, float lo, float hi) |
Returns true if num is between lo and hi , excluding hi but not lo . More... | |
static bool | IsInRange (this float num, float lo, float hi) |
Returns true if num is between lo and hi . More... | |
static float | PutInRange (this float n, float min, float max) |
Returns num clamped to the range min and max . More... | |
static bool | IsInRangeExcludeHi (this double num, double lo, double hi) |
Returns true if num is between lo and hi , excluding hi but not lo . More... | |
static bool | IsInRange (this double num, double lo, double hi) |
Returns true if num is between lo and hi . More... | |
static double | PutInRange (this double n, double min, double max) |
Returns num clamped to the range min and max . More... | |
static bool | IsInRangeExcludeHi< T > (this T num, T lo, T hi) |
static bool | IsInRange< T > (this T num, T lo, T hi) |
static T | PutInRange< T > (this T n, T min, T max) |
|
inlinestatic |
Gets a bare HTML entity name for an ASCII character, or null if there is no entity name for the given character, e.g. BareHtmlEntityNameForAscii('"') == "quot"
.
The complete entity name is an ampersand (&) plus BareHtmlEntityNameForAscii(c) + ";"
. Some HTML entities have multiple names; this function returns one of them. There is a name in this table for all ASCII punctuation characters.
Referenced by Loyc.Ecs.EcsValidators.SanitizeIdentifier().
|
inlinestatic |
Returns the number of bits that are set in the specified integer.
Referenced by Loyc.G.Log2Floor().
|
inlinestatic |
Returns the number of bits that are set in the specified integer.
This is a duplicate of MathEx.CountOnes() needed by Loyc.Collections, which does not have a reference to Loyc.Math.dll which contains MathEx. However this uses a compact SWAR implementation, whereas Loyc.Math uses a potentially faster lookup table.
References Loyc.G.CountOnes().
Referenced by Loyc.G.CountOnes().
|
inlinestatic |
Returns action(obj)
. This method lets you embed statements in any expression.
|
inlinestatic |
This function controls the default character categorization used by overloads of WordWrap(string, int, Func<int, WordWrapCharType>).
|
inlinestatic |
Returns true if num
is between lo
and hi
.
|
inlinestatic |
Returns true if num
is between lo
and hi
.
|
inlinestatic |
Returns true if num
is between lo
and hi
.
|
inlinestatic |
Returns true if num
is between lo
and hi
.
|
inlinestatic |
Returns true if num
is between lo
and hi
.
|
inlinestatic |
Returns true if num
is between lo
and hi
.
|
inlinestatic |
Returns true if num
is between lo
and hi
, excluding hi
but not lo
.
|
inlinestatic |
Returns true if num
is between lo
and hi
, excluding hi
but not lo
.
|
inlinestatic |
Returns true if num
is between lo
and hi
, excluding hi
but not lo
.
|
inlinestatic |
Returns true if num
is between lo
and hi
, excluding hi
but not lo
.
|
inlinestatic |
Returns true if num
is between lo
and hi
, excluding hi
but not lo
.
|
inlinestatic |
Returns true if num
is between lo
and hi
, excluding hi
but not lo
.
|
inlinestatic |
Returns the floor of the base-2 logarithm of x. e.g. 1024 -> 10, 1000 -> 9
The return value is -1 for an input that is zero or negative.
Some processors have a dedicated instruction for this operation, but the .NET framework provides no access to it.
References Loyc.G.Log2Floor().
|
inlinestatic |
Replaces characters in text
that are not allowed in file names with the specified replacement character.
text | Text to make into a valid filename. The same string is returned if it is valid already. |
replacement | Replacement character, or null to simply remove bad characters. |
fancy | Whether to replace quotes and slashes with the non-ASCII characters ” and ⁄. |
|
inlinestatic |
Returns num
clamped to the range min
and max
.
|
inlinestatic |
Returns num
clamped to the range min
and max
.
|
inlinestatic |
Returns num
clamped to the range min
and max
.
|
inlinestatic |
Returns num
clamped to the range min
and max
.
|
inlinestatic |
Returns num
clamped to the range min
and max
.
|
inlinestatic |
Returns num
clamped to the range min
and max
.
|
inlinestatic |
Gets a Comparison<T> for the specified type.
This method is optimized and does not allocate on every call.
T | : | IComparable<T> |
|
inlinestatic |
Converts an IComparer<T> to a Comparison<T>.
|
inlinestatic |
Converts an IComparer<T> to a Func(T,T,int).
|
inlinestatic |
This method simply calls the delegate provided and returns true. It is used to do an action in a conditional expression.
|
inlinestatic |
Returns true. This method has no effect; it is used to do an action in a conditional expression.
value | Ignored. |
|
inlinestatic |
Same as Debug.Assert
except that the argument is evaluated even in a Release build.
Referenced by Loyc.Collections.MSet< Symbol >.Toggle(), and Loyc.Syntax.Les.Les2Lexer.UnescapeString().
|
inlinestatic |
Calls action(obj)
, then returns the same object.
This is the plain-C# equivalent of the with(obj)
statement. Compared to the Enhanced C# statement, With()
is disadvantageous since it requires a memory allocation to create the closure in many cases, as well as a delegate invocation that probably will not be inlined.
Caution: you cannot mutate mutable structs with this method. Call the other overload of this method if you will be modifying a mutable struct.
Foo(new Person() { Name = "John Doe" }.With(p => p.Commit(dbConnection)));
|
inlinestatic |
Calls action(ref obj)
, then returns the same object.
|
static |
Returns action(obj)
. This is similar to the other overload of this method, except that the action has a return value.
|
inlinestatic |
Breaks a paragraph into lines using a simple word-wrapping algorithm.
paragraph | A sequence of characters that will be treated as a paragraph to be broken into lines as necessary. The first item in each pair is a 21-bit unicode character; the second item is the width of that character, e.g. in pixels. The width must be non-negative and no more than half of int.MaxValue. |
lineWidth | Line width. The unit used here is the same as the unit of the second item in each pair, e.g. pixels. |
getCharType | A function that determines how a character is relevant to the wrapping operation; see WordWrapCharType. This function accepts 21-bit unicode characters from paragraph . |
This algorithm may be unsuitable for some non-English languages, in which adjacent characters do not have independent widths because of the way they combine. It may still be useful if you only need to make sure lines don't get too long.
Characters higher than 0xFFFF are converted into UTF-16 surrogate pairs.
Whitespace characters at the end of a line are not counted toward the line length limit. As a result, strings in the output list can be longer than lineWidth
unless you trim off spaces afterward.
If the input contains a newline character, a line break occurs but the newline is preserved, e.g. "Foo\nBar" causes output like { "Foo\n", "Bar" }. Depending on how you intend to use the output, you may need to trim the newline from the end.
By default, lines can be broken at the soft hyphen '\u00AD', in which case it is advisable for the caller to replace the trailing '\u00AD' with '-' before drawing to ensure that the hyphen is actually displayed on the screen. For simplicity, this replacement is not part of the wrapping algorithm itself.
|
inlinestatic |
Breaks a paragraph into lines using a simple word-wrapping algorithm.
paragraph | Text to be broken apart if necessary. |
lineWidth | Line width in characters. |
The other overload of this function is more flexible, e.g. it supports variable-width characters.
This algorithm may be unsuitable for some non-English languages, in which adjacent characters do not have independent widths because of the way they combine. It may still be useful if you only need to make sure lines don't get too long.
Whitespace characters (including tabs and zero-width spaces) at the end of a line are not counted toward the line length limit. As a result, strings in the output list can be longer than lineWidth
unless you trim spaces afterward.
If the input contains a newline character, a line break occurs but the newline is preserved, e.g. "Ann\nBob" causes output like { "Ann\n", "Bob" }. Depending on how you intend to use the output, you may need to trim the newline from the end.
By default, lines can be broken at the soft hyphen '\u00AD', in which case it is advisable for the caller to replace the trailing '\u00AD' with '-' before drawing to ensure that the hyphen is actually displayed on the screen. For simplicity, this replacement is not part of the wrapping algorithm itself.