Class ParsingUtility
- Namespace
- TMPEffects.TextProcessing
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
stringThe full string.
startIndex
intThe index to start the search from.
tag
ParsingUtility.TagInfoReference to a ParsingUtility.TagInfo. Will be set to the parsed tag if one is found.
type
ParsingUtility.TagTypeThe 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
stringThe tag to parse the parameters of.
Returns
- Dictionary<string, string>
The parsed string as Dictionary<TKey, TValue>.
Exceptions
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
stringThe string to check.
startIndex
intThe start index of the substring.
maxIndex
intThe 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 tomaxIndex
, 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
stringThe string to check.
type
ParsingUtility.TagTypeThe 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
stringThe full string.
startIndex
intStart index of the substring.
endIndex
intEnd index of the substring.
tag
ParsingUtility.TagInfoReference to a ParsingUtility.TagInfo. Will be set to the parsed tag if successful.
type
ParsingUtility.TagTypeThe 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.