guardBracketInText method

String guardBracketInText (String str, [ bool isRtlContext ])

Apply bracket guard to str using LRM and RLM. This is to address the problem of messy bracket display that frequently happens in RTL layout. This version works for both plain text and html, but in some cases is not as good as guardBracketInHtml. If isRtlContext is true, then we explicitly want to wrap in a span of RTL directionality, regardless of the estimated directionality.

Implementation

static String guardBracketInText(String str, [bool isRtlContext]) {
  var useRtl = isRtlContext == null ? hasAnyRtl(str) : isRtlContext;
  var mark = useRtl ? RLM : LRM;
  return _guardBracketHelper(str,
      new RegExp(r'(\(.*?\)+)|(\[.*?\]+)|(\{.*?\}+)|(<.*?>+)'), mark, mark);
}