/// <summary> /// Initializes a new instance of the <see cref="ConstantStringToken"/> class. /// </summary> /// <param name="previousToken">The previous token.</param> /// <param name="anchored">if set to <c>true</c> [anchored].</param> /// <param name="searchValue">The constant string.</param> public ConstantStringToken([CanBeNull] PatternToken previousToken, bool anchored, [NotNull] string searchValue) { Assert.ArgumentNotNull(searchValue, "searchValue"); _previousToken = previousToken; _anchored = anchored; SearchValue = searchValue; }
/// <summary> /// Initializes a new instance of the <see cref="VariableReferenceToken"/> class. /// </summary> /// <param name="rootModel">The root model.</param> /// <param name="previousToken">The previous token.</param> /// <param name="anchored">if set to <c>true</c> [anchored].</param> /// <param name="variableName">Name of the variable.</param> public VariableReferenceToken([NotNull] RootModel rootModel, [CanBeNull] PatternToken previousToken, bool anchored, [NotNull] string variableName) : base(previousToken, anchored, string.Empty) { Assert.ArgumentNotNull(rootModel, "rootModel"); Assert.ArgumentNotNull(variableName, "variableName"); _rootModel = rootModel; _variableName = variableName; }
/// <summary> /// Sets the next token. /// </summary> /// <param name="patternToken">The pattern token to set as next token.</param> public void SetNextToken([NotNull] PatternToken patternToken) { Assert.ArgumentNotNull(patternToken, "patternToken"); NextToken = patternToken; }
public static PatternToken ParseWildcardString([NotNull] string target, [NotNull] RootModel rootModel) { Assert.ArgumentNotNullOrWhiteSpace(target, "target"); Assert.ArgumentNotNull(rootModel, "rootModel"); int position = 0; bool anchored = false; PatternToken rootToken = null; PatternToken previousToken = null; var sb = new StringBuilder(); if (target[0] == '^') { position++; anchored = true; } while (position < target.Length) { if (position < target.Length - 1) { if (target[position] == '%' && char.IsDigit(target[position + 1]) && target[position + 1] != '0') { var token = new WildcardToken(target[position + 1] - '0'); if (sb.Length != 0) { var constantToken = new ConstantStringToken(previousToken, anchored, sb.ToString()); sb.Clear(); if (previousToken != null) { previousToken.SetNextToken(constantToken); } previousToken = constantToken; if (rootToken == null) { rootToken = constantToken; } } position += 2; anchored = false; if (previousToken != null) { previousToken.SetNextToken(token); } previousToken = token; if (rootToken == null) { rootToken = token; } continue; } if (target[position] == '$') { var endPosition = target.IndexOf(' ', position); string variableName = endPosition >= position ? target.Substring(position + 1, endPosition - position - 1) : target.Substring(position + 1); if (sb.Length != 0) { var constantToken = new ConstantStringToken(previousToken, anchored, sb.ToString()); sb.Clear(); if (previousToken != null) { previousToken.SetNextToken(constantToken); } previousToken = constantToken; if (rootToken == null) { rootToken = constantToken; } anchored = true; } var token = new VariableReferenceToken(rootModel, previousToken, anchored, variableName); position += variableName.Length + 1; if (previousToken != null) { previousToken.SetNextToken(token); } previousToken = token; if (rootToken == null) { rootToken = token; } anchored = true; continue; } } sb.Append(target[position]); position++; } if (sb.Length != 0) { var constantToken = new ConstantStringToken(previousToken, anchored, sb.ToString()); sb.Clear(); if (previousToken != null) { previousToken.SetNextToken(constantToken); } if (rootToken == null) { rootToken = constantToken; } } return(rootToken ?? new FaultToken()); }