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
textstringThe full string.
startIndexintThe index to start the search from.
tagParsingUtility.TagInfoReference to a ParsingUtility.TagInfo. Will be set to the parsed tag if one is found.
typeParsingUtility.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
tagstringThe 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
textstringThe string to check.
startIndexintThe start index of the substring.
maxIndexintThe end index of the substring. Leave at default to set to length of
text.typeParsingUtility.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
tagstringThe string to check.
typeParsingUtility.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
textstringThe full string.
startIndexintStart index of the substring.
endIndexintEnd index of the substring.
tagParsingUtility.TagInfoReference to a ParsingUtility.TagInfo. Will be set to the parsed tag if successful.
typeParsingUtility.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.