Enhanced C#
Language of your choice: library documentation
Static Public Member Functions | List of all members
Loyc.Syntax.PrintHelpers Class Reference

Static methods that help to print literals, such as EscapeCStyle which escapes special characters with backslashes. More...


Source file:

Remarks

Static methods that help to print literals, such as EscapeCStyle which escapes special characters with backslashes.

Static Public Member Functions

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. Uses uppercase. More...
 
static string EscapeCStyle (UString s, EscapeC flags=EscapeC.Default)
 Escapes characters in a string using C style, e.g. the string "Foo\"
"</c> maps to <c>"Foo\"\
"
by default. More...
 
static string EscapeCStyle (UString s, EscapeC flags, char quoteType)
 Escapes characters in a string using C style. More...
 
static bool EscapeCStyle (int c, StringBuilder @out, EscapeC flags=EscapeC.Default, char quoteType='\0')
 Writes a character c to a StringBuilder, either as a normal character or as a C-style escape sequence. More...
 
static string IntegerToString (long value, string prefix="", int @base=10, int separatorInterval=3, char separatorChar='_')
 Converts an integer to a string, optionally with separator characters for readability. More...
 
static string IntegerToString (ulong value, string prefix="", int @base=10, int separatorInterval=3, char separatorChar='_')
 
static StringBuilder AppendIntegerTo (StringBuilder target, long value, string prefix="", int @base=10, int separatorInterval=3, char separatorChar='_')
 Same as IntegerToString(long, string, int, int, char) except that the target StringBuilder must be provided as a parameter. More...
 
static StringBuilder AppendIntegerTo (StringBuilder target, ulong value, string prefix="", int @base=10, int separatorInterval=3, char separatorChar='_')
 

Member Function Documentation

◆ AppendIntegerTo()

static StringBuilder Loyc.Syntax.PrintHelpers.AppendIntegerTo ( StringBuilder  target,
long  value,
string  prefix = "",
int @  base = 10,
int  separatorInterval = 3,
char  separatorChar = '_' 
)
inlinestatic

Same as IntegerToString(long, string, int, int, char) except that the target StringBuilder must be provided as a parameter.

Parameters
valueInteger to be converted
prefixA prefix to insert before the number, but after the '-' sign, if any (e.g. "0x" for hex). Use "" for no prefix.
baseNumber base (e.g. 10 for decimal, 2 for binary, 16 for hex). Must be in the range 2 to 36.
separatorIntervalNumber of digits in a group (use 0 or less to disable digit separators)
separatorCharDigit group separator
Returns
The target StringBuilder.

Referenced by Loyc.Syntax.PrintHelpers.IntegerToString().

◆ EscapeCStyle() [1/3]

static bool Loyc.Syntax.PrintHelpers.EscapeCStyle ( int  c,
StringBuilder @  out,
EscapeC  flags = EscapeC.Default,
char  quoteType = '\0' 
)
inlinestatic

Writes a character c to a StringBuilder, either as a normal character or as a C-style escape sequence.

Parameters
flagsSpecifies which characters should be escaped.
quoteTypeSpecifies a character that should always be escaped (typically one of ' " `)
Returns
true if an escape sequence was emitted, false if not.

EscapeC.HasLongEscape can be used to force a 6-digit unicode escape; this may be needed if the next character after this one is a digit.

◆ EscapeCStyle() [2/3]

static string Loyc.Syntax.PrintHelpers.EscapeCStyle ( UString  s,
EscapeC  flags,
char  quoteType 
)
inlinestatic

Escapes characters in a string using C style.

Parameters
flagsSpecifies which characters should be escaped.
quoteTypeSpecifies a character that should always be escaped (typically one of ' " `)

References Loyc.Syntax.PrintHelpers.EscapeCStyle(), Loyc.UString.InternalString, and Loyc.UString.Length.

◆ EscapeCStyle() [3/3]

static string Loyc.Syntax.PrintHelpers.EscapeCStyle ( UString  s,
EscapeC  flags = EscapeC.Default 
)
inlinestatic

Escapes characters in a string using C style, e.g. the string "Foo\"
"</c> maps to <c>"Foo\"\
"
by default.

Referenced by Loyc.Syntax.PrintHelpers.EscapeCStyle(), Loyc.Syntax.Lexing.BaseLexer< CharSrc >.PrintChar(), Loyc.Syntax.LiteralHandlerTable.TryParse(), and Loyc.Syntax.Les.Les2Lexer.UnescapeString().

◆ HexDigitChar()

static char Loyc.Syntax.PrintHelpers.HexDigitChar ( int  value)
inlinestatic

Gets the hex digit character for the specified value, or '?' if the value is not in the range 0...15. Uses uppercase.

◆ IntegerToString()

static string Loyc.Syntax.PrintHelpers.IntegerToString ( long  value,
string  prefix = "",
int @  base = 10,
int  separatorInterval = 3,
char  separatorChar = '_' 
)
inlinestatic

Converts an integer to a string, optionally with separator characters for readability.

Parameters
valueInteger to be converted
prefixA prefix to insert before the number, but after the '-' sign, if any (e.g. "0x" for hex). Use "" for no prefix.
baseNumber base (e.g. 10 for decimal, 2 for binary, 16 for hex). Must be in the range 2 to 36.
separatorIntervalNumber of digits in a group
separatorCharDigit group separator
Returns
The number as a string.

Example: IntegerToString(-1234567, "0", 10, 3, '\'') == "-01'234'567"

References Loyc.Syntax.PrintHelpers.AppendIntegerTo().