Contains global functions that don't belong in any specific class.
|
static void | Swap< T > (ref T a, ref T b) |
|
static bool | IsOneOf< T > (this T value, params T[] set) |
|
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 Pair< T1, T2 > | Pair< T1, T2 > (T1 a, T2 b) |
|
static Triplet< T1, T2, T3 > | Triplet< T1, T2, T3 > (T1 a, T2 b, T3 c) |
|
static bool | Verify (bool condition) |
| Same as Debug.Assert except that the argument is evaluated even in a Release build. More...
|
|
static void | Require (bool condition) |
|
static void | Require (bool condition, string msg) |
|
static bool | TryParseHex (UString s, out int value) |
|
static int | TryParseHex (ref UString s, out int value) |
|
static int | HexDigitValue (char c) |
| Gets the integer value for the specified hex digit, or -1 if the character is not a hex digit. More...
|
|
static int | Base36DigitValue (char c) |
|
static char | HexDigitChar (int value) |
| Gets the hex digit character for the specified value, or '?' if the value is not in the range 0...15. More...
|
|
static string | EscapeCStyle (UString s, EscapeC flags=EscapeC.Default) |
|
static string | EscapeCStyle (UString s, EscapeC flags, char quoteType) |
|
static bool | EscapeCStyle (char c, StringBuilder @out, EscapeC flags=EscapeC.Default, char quoteType= '\0') |
|
static string | UnescapeCStyle (string s) |
| Unescapes a string that uses C-style escape sequences, e.g. "\n\r" becomes "
". More...
|
|
static string | UnescapeCStyle (string s, int index, int length, bool removeUnnecessaryBackslashes) |
| Unescapes a string that uses C-style escape sequences, e.g. "\n\r" becomes "
". More...
|
|
static char | UnescapeChar (ref UString s) |
|
static char | UnescapeChar (string s, ref int i) |
| Unescapes a single character of a string, e.g. int = 3; UnescapeChar("foo\\n", ref i) == '
' . Returns the character at 'index' if it is not a backslash, or if it is a backslash but no escape sequence could be discerned. More...
|
|
static PushedTLV< T > | PushTLV< T > (ThreadLocalVariable< T > variable, T newValue) |
| Helper function for a using statement that temporarily modifies a thread-local variable. More...
|
|
static bool | TryParseInt (string s, ref int index, out int result, int radix=10, bool skipSpaces=true) |
| Tries to parse a string to an integer. Unlike Int32.TryParse(string, out int), this method allows parsing to start at any point in the string, it allows non-numeric data after the number, and it can parse numbers that are not in base 10. More...
|
|
static bool | TryParseInt (ref UString s, out int result, int radix=10, ParseFlag flags=0) |
|
static bool | TryParseInt (ref UString input, out long result, int radix=10, ParseFlag flags=0) |
|
static bool | TryParseUInt (ref UString s, out ulong result, int radix=10, ParseFlag flags=0) |
|
static bool | TryParseFloatParts (ref UString source, int radix, out bool negative, out ulong mantissa, out int exponentBaseR, out int exponentBase2, out int exponentBase10, out int numDigits, ParseFlag flags=0) |
| Low-level method that identifies the parts of a float literal of arbitrary base (typically base 2, 10, or 16) with no prefix or suffix, such as 2.Cp0 (which means 2.75 in base 16). More...
|
|
static bool | TryParseFloatParts (ref UString source, int radix, out bool negative, out ulong mantissa, out int exponentBase2, out int exponentBase10, out int numDigits, ParseFlag flags=0) |
| Parses the parts of a floating-point string. See the other overload for details. More...
|
|
static double | TryParseDouble (ref UString source, int radix, ParseFlag flags=0) |
| Parses a string to a double-precision float, returning NaN on failure or an infinity value on overflow. More...
|
|
static float | TryParseFloat (ref UString source, int radix, ParseFlag flags=0) |
| Parses a string to a single-precision float, returning NaN on failure or an infinity value on overflow. More...
|
|
static int | SkipSpaces (string s, int index) |
| Gets the index of the first non-space character after the specified index. More...
|
|
static UString | SkipSpaces (UString s) |
| Returns a string with any spaces and tabs removed from the beginning. 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. '"'=>"quot" . More...
|
|
static bool Loyc.G.TryParseFloatParts |
( |
ref UString |
source, |
|
|
int |
radix, |
|
|
out bool |
negative, |
|
|
out ulong |
mantissa, |
|
|
out int |
exponentBaseR, |
|
|
out int |
exponentBase2, |
|
|
out int |
exponentBase10, |
|
|
out int |
numDigits, |
|
|
ParseFlag |
flags = 0 |
|
) |
| |
|
inlinestatic |
Low-level method that identifies the parts of a float literal of arbitrary base (typically base 2, 10, or 16) with no prefix or suffix, such as 2.Cp0
(which means 2.75 in base 16).
- Parameters
-
radix | Base of the number to parse; must be between 2 and 36. |
mantissa | Integer magnitude of the number. |
exponentBase2 | Base-2 exponent to apply, as specified by the 'p' suffix, or 0 if there is no 'p' suffix.. |
exponentBase10 | Base-10 exponent to apply, as specified by the 'e' suffix, or 0 if there is no 'e' suffix.. |
exponentBaseR | Base-radix exponent to apply. This number is based on the front part of the number only (not including the 'p' or 'e' suffix). Negative values represent digits after the decimal point, while positive numbers represent 64-bit overflow. For example, if the input is 12.3456 with radix=10 , the output will be mantissa=123456 and exponentBaseR=-4 . If the input is 0123_4567_89AB_CDEF_1234.5678 with radix=16 , the mantissa overflows, and the result is mantissa = 0x1234_5678_9ABC_DEF1 with exponentBaseR=3 . |
numDigits | Set to the number of digits in the number, not including the exponent part. |
flags | Alters parsing behavior, see ParseFlags. |
The syntax required is
( '+'|'-' )?
( Digits ('.' Digits?)? | '.' Digits )
( ('p'|'P') ('-'|'+')? DecimalDigits+ )?
( ('e'|'E') ('-'|'+')? DecimalDigits+ )?
where Digits refers to one digits in the requested base, possibly including underscores or spaces if the flags allow it; similarly, DecimalDigits refers to base-10 digits and is also affected by the flags.
Returns false if there was an error interpreting the input.
To keep the parser relatively simple, it does not roll back in case of error the way the int parser does. For example, given the input "23p", the 'p' is consumed and causes the method to return false, even though the parse could have been successful if it had ignored the 'p'.
References Loyc.G.SkipSpaces(), and Loyc.G.TryParseInt().
Referenced by Loyc.G.TryParseDouble(), Loyc.G.TryParseFloat(), and Loyc.G.TryParseFloatParts().