/// <summary> /// Implement <see cref="IUnicodeMatcher"/> /// </summary> public virtual string ToPattern(bool escapeUnprintable) { StringBuffer result = new StringBuffer(); StringBuffer quoteBuf = new StringBuffer(); if (segmentNumber > 0) { // i.e., if this is a segment result.Append('('); } for (int i = 0; i < pattern.Length; ++i) { char keyChar = pattern[i]; // OK; see note (1) above IUnicodeMatcher m = data.LookupMatcher(keyChar); if (m == null) { Utility.AppendToRule(result, keyChar, false, escapeUnprintable, quoteBuf); } else { Utility.AppendToRule(result, m.ToPattern(escapeUnprintable), true, escapeUnprintable, quoteBuf); } } if (segmentNumber > 0) { // i.e., if this is a segment result.Append(')'); } // Flush quoteBuf out to result Utility.AppendToRule(result, -1, true, escapeUnprintable, quoteBuf); return(result.ToString()); }
/// <summary> /// Implement <see cref="IUnicodeMatcher"/> API. /// </summary> public virtual string ToPattern(bool escapeUnprintable) { StringBuilder result = new StringBuilder(); result.Append(matcher.ToPattern(escapeUnprintable)); if (minCount == 0) { if (maxCount == 1) { return(result.Append('?').ToString()); } else if (maxCount == MaxCount) { return(result.Append('*').ToString()); } // else fall through } else if (minCount == 1 && maxCount == MaxCount) { return(result.Append('+').ToString()); } result.Append('{'); result.Append(Utility.Hex(minCount, 1)); result.Append(','); if (maxCount != MaxCount) { result.Append(Utility.Hex(maxCount, 1)); } result.Append('}'); return(result.ToString()); }
/// <summary> /// Given a <paramref name="matcher"/> reference, which may be null, append its /// pattern as a literal to the given <paramref name="rule"/>. /// </summary> public static void AppendToRule(StringBuffer rule, IUnicodeMatcher matcher, bool escapeUnprintable, StringBuffer quoteBuf) { if (matcher != null) { AppendToRule(rule, matcher.ToPattern(escapeUnprintable), true, escapeUnprintable, quoteBuf); } }