Class FormatStringParser
Use this class to parse format control strings that you intend to use with string.Format or one of the Write or WriteLine methods of a stream object, such as a Console or TextWriter. Properties and methods report on its attributes, including its FormaItems, and errors flagged by the parser.
Inheritance
Namespace: WizardWrx.FormatStringEngine
Assembly: WizardWrx.FormatStringEngine.dll
Syntax
public class FormatStringParser : object
Constructors
| Improve this Doc View SourceFormatStringParser()
Create the empty parser.
Declaration
public FormatStringParser()
FormatStringParser(String)
Create the parser and set the initial value of its FormatString property.
Declaration
public FormatStringParser(string pstrFormatString)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrFormatString | Pass a reference to the format control string that you want parsed. Since the constructor parses the string, the properties are set, and all that remains for you to do is evaluate them. |
Fields
| Improve this Doc View SourceESCAPED_ITEM_BEGIN
To include a literal opening brace (that is, one that you want to appear in the completed string), it must be escaped, which is accomplished by including a pair of them where you want one to appear.
Declaration
public const string ESCAPED_ITEM_BEGIN = null
Field Value
Type | Description |
---|---|
System.String |
ESCAPED_ITEM_END
To include a literal closing brace (that is, one that you want to appear in the completed string), it must be escaped, which is accomplished by including a pair of them where you want one to appear.
Declaration
public const string ESCAPED_ITEM_END = null
Field Value
Type | Description |
---|---|
System.String |
ITEM_BEGIN
One left French brace is assumed to be the beginning of a new format item.
Declaration
public const char ITEM_BEGIN = null
Field Value
Type | Description |
---|---|
System.Char |
Remarks
To disable this interpretation, and have the left French brace appear in the output, use a ESCAPED_ITEM_BEGIN string.
ITEM_END
One right French brace is assumed to be the end of the format item.
Declaration
public const char ITEM_END = null
Field Value
Type | Description |
---|---|
System.Char |
Remarks
To disable this interpretation, and have the right French brace appear in the output, use a ESCAPED_ITEM_END string.
ITEM_HAS_ALIGNMENT_ATTRIBUTE
When one appears within French braces that are not escaped, a comma indicates an alignment and minimum width are specified. The documentation of a composite format string refers to this as the Alignment component.
Declaration
public const char ITEM_HAS_ALIGNMENT_ATTRIBUTE = null
Field Value
Type | Description |
---|---|
System.Char |
ITEM_HAS_FORMAT_STRING_ATTRIBUTE
When one appears within French braces, a colon indicates a format string, to be applied to the item is specified. The documentation of a composite format string refers to this as the Format String component.
Declaration
public const char ITEM_HAS_FORMAT_STRING_ATTRIBUTE = null
Field Value
Type | Description |
---|---|
System.Char |
ITEM_IS_LEFT_ALIGNED
Since a negative number signifies left alignment, the presence of a minus sign immediately following the comma acts as a switch.
Declaration
public const char ITEM_IS_LEFT_ALIGNED = null
Field Value
Type | Description |
---|---|
System.Char |
ITEM_IS_RIGHT_ALIGNED
Since a negative number signifies left alignment, the presence of a plus sign immediately following the comma acts as a dummy switch.
Declaration
public const char ITEM_IS_RIGHT_ALIGNED = null
Field Value
Type | Description |
---|---|
System.Char |
NO_ERRORS
The FormatStringErrorCount returns this value when the FormatStringErrors collection is null. The collection remains so unless at least one error is found in the string.
Declaration
public const int NO_ERRORS = null
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
| Improve this Doc View SourceFormatItems
Gets the collection of FormatItems found in the string.
Declaration
public FormatItemsCollection FormatItems { get; }
Property Value
Type | Description |
---|---|
FormatItemsCollection |
FormatString
Get or set the value of the FormatString property, from which all other properties are derived.
Declaration
public string FormatString { get; set; }
Property Value
Type | Description |
---|---|
System.String |
FormatStringErrorCount
Gets the count of errors found in the format string.
Declaration
public int FormatStringErrorCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
This convenience property exists because the FormatStringErrors collection is null unless at least one error was found in the format string.
FormatStringErrors
Gets the list of errors, which may be null.
Declaration
public List<FormatStringError> FormatStringErrors { get; }
Property Value
Type | Description |
---|---|
List<FormatStringError> |
HighestFormatItemIndex
Gets the higest format item index number.
Declaration
public int HighestFormatItemIndex { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
The array of format items must contains at least this many items, plus one.