Table of Contents

Class ParsingUtility

Utility methods for text processing and parsing.

public static class ParsingUtility
Inheritance
ParsingUtility
Inherited Members

Methods

GetNextTag(string, int, ref TagInfo, TagType)

Get the next tag in text, starting from startIndex.

public static bool GetNextTag(string text, int startIndex, ref ParsingUtility.TagInfo tag, ParsingUtility.TagType type = TagType.Open | TagType.Close)

Parameters

text string

The full string.

startIndex int

The index to start the search from.

tag ParsingUtility.TagInfo

Reference to a ParsingUtility.TagInfo. Will be set to the parsed tag if one is found.

type ParsingUtility.TagType

The type of tag to get. Leave at default for either type.

Returns

bool

true if a next tag was found; false otherwise.

GetTagParametersDict(string)

Parses a string to a Dictionary<TKey, TValue>.
Pass in either a full tag string, e.g. <example=10 arg="value">, or the same but without the brackets (example=10 arg="value").
Note that this only does some basic checks on the validity of the input string; malformed strings may lead to errors.
Ideally use by passing in a parameterString.

public static Dictionary<string, string> GetTagParametersDict(string tag)

Parameters

tag string

The tag to parse the parameters of.

Returns

Dictionary<string, string>

The parsed string as Dictionary<TKey, TValue>.

Exceptions

ArgumentException

IsTag(string, int, int, TagType)

Checks if the given string contains a substring starting at startIndex, going up to maxIndex, that is a well formed tag.

public static bool IsTag(string text, int startIndex, int maxIndex = -1, ParsingUtility.TagType type = TagType.Open | TagType.Close)

Parameters

text string

The string to check.

startIndex int

The start index of the substring.

maxIndex int

The end index of the substring. Leave at default to set to length of text.

type ParsingUtility.TagType

Returns

bool

true if the given string contains a substring starting at startIndex, going up to maxIndex, that is a well formed tag; otherwise false.

IsTag(string, TagType)

Checks if the given string is a well-formed tag (of the given type, if supplied).

public static bool IsTag(string tag, ParsingUtility.TagType type = TagType.Open | TagType.Close)

Parameters

tag string

The string to check.

type ParsingUtility.TagType

The type of tag to check for. Leave default for either type.

Returns

bool

true if the given string is a tag (of the given type, if supplied); otherwise false.

TryParseTag(string, int, int, ref TagInfo, TagType)

Attempt to parse a tag from the substring of text given by startIndex and endIndex.

public static bool TryParseTag(string text, int startIndex, int endIndex, ref ParsingUtility.TagInfo tag, ParsingUtility.TagType type = TagType.Open | TagType.Close)

Parameters

text string

The full string.

startIndex int

Start index of the substring.

endIndex int

End index of the substring.

tag ParsingUtility.TagInfo

Reference to a ParsingUtility.TagInfo. Will be set to the parsed tag if successful.

type ParsingUtility.TagType

The type of tag to check for. Leave at default for either type.

Returns

bool

true if a tag was successfully parsed from the substring; false otherwise.