public void protectTest() { StringHandler target = new StringHandler(); string actual = target.protectMixedQuotes("test \"str1\" - 'str2' data"); Assert.AreEqual(false, Regex.IsMatch(actual, RPattern.DoubleQuotesContent, RegexOptions.IgnorePatternWhitespace)); Assert.AreEqual(false, Regex.IsMatch(actual, RPattern.SingleQuotesContent, RegexOptions.IgnorePatternWhitespace)); }
/// <summary> /// Handler of mixed data SBE-Scripts /// Format: https://bitbucket.org/3F/vssolutionbuildevent/issue/22/#comment-12739932 /// </summary> /// <param name="data">mixed data</param> /// <param name="allowMSBuild">Allows post-processing with MSBuild or not. /// Some components can require immediate processing with evaluation, before passing control to next level. /// </param> /// <returns>prepared and evaluated data</returns> public string parse(string data, bool allowMSBuild) { lock (_lock) { _depthLevel = 0; postMSBuild = allowMSBuild; StringHandler hString = new StringHandler(); return(hString.recovery(parse(hString.protect(data), _depthLevel, hString))); } }
/// <param name="data">Mixed data</param> /// <param name="level">Nesting level</param> /// <param name="hString">Handler of strings if exists</param> /// <returns>Prepared and evaluated data</returns> protected string parse(string data, int level, StringHandler hString = null) { if (level >= DEPTH_LIMIT) { _depthLevel = 0; throw new LimitException("Nesting level of '{0}' reached. Aborted.", DEPTH_LIMIT); } var rcon = RPattern.Container; return(rcon.Replace(data, delegate(Match m) { string escape = m.Groups[1].Value; string raw = m.Groups[2].Value; if (escape.Length > 1) { Log.Trace("SBEScripts-Container: escape `{0}`", (raw.Length > 40)? raw.Substring(0, 40) + "..." : raw); return "#" + escapeMSBuildData(raw, true); } return selector((hString != null)? hString.recovery(raw) : raw); })); }
public void recoveryTest() { StringHandler target = new StringHandler(); string str = target.protectMixedQuotes("test \"str1\" - 'str2' data"); Assert.AreEqual("test \"str1\" - 'str2' data", target.recovery(str)); }
/// <param name="data">Mixed data</param> /// <param name="level">Nesting level</param> /// <param name="hString">Handler of strings if exists</param> /// <returns>Prepared and evaluated data</returns> protected string parse(string data, int level, StringHandler hString = null) { if(level >= DEPTH_LIMIT) { _depthLevel = 0; throw new LimitException("Nesting level of '{0}' reached. Aborted.", DEPTH_LIMIT); } var rcon = RPattern.Container; return rcon.Replace(data, delegate(Match m) { string escape = m.Groups[1].Value; string raw = m.Groups[2].Value; if(escape.Length > 1) { Log.Trace("SBEScripts-Container: escape `{0}`", (raw.Length > 40)? raw.Substring(0, 40) + "..." : raw); return "#" + escapeMSBuildData(raw, true); } return selector((hString != null)? hString.recovery(raw) : raw); }); }
/// <summary> /// Handler of mixed data SBE-Scripts /// Format: https://bitbucket.org/3F/vssolutionbuildevent/issue/22/#comment-12739932 /// </summary> /// <param name="data">mixed data</param> /// <param name="allowMSBuild">Allows post-processing with MSBuild or not. /// Some components can require immediate processing with evaluation, before passing control to next level. /// </param> /// <returns>prepared and evaluated data</returns> public string parse(string data, bool allowMSBuild) { lock(_lock) { _depthLevel = 0; postMSBuild = allowMSBuild; StringHandler hString = new StringHandler(); return hString.recovery(parse(hString.protect(data), _depthLevel, hString)); } }
/// <param name="data">Mixed data</param> /// <param name="level">Nesting level</param> /// <param name="hString">Handler of strings if exist</param> /// <returns>Prepared & evaluated data</returns> protected string parse(string data, int level, StringHandler hString = null) { if(level >= DEPTH_LIMIT) { _depthLevel = 0; throw new LimitException("Nesting level of '{0}' reached. Aborted.", DEPTH_LIMIT); } return Regex.Replace(data, ContainerPattern, delegate(Match m) { if(m.Groups[1].Value.Length > 1) { //escape Log.Debug("SBEScripts: escape - '{0}'", m.Groups[2].Value); return "#" + escapeMSBuildData(m.Groups[2].Value, true); } string raw = m.Groups[2].Value; Log.Trace("SBEScripts-data: to parse '{0}'", raw); if(hString != null) { return selector(hString.recovery(raw)); } return selector(raw); }, RegexOptions.IgnorePatternWhitespace); }