guardBracketInHtml method

String guardBracketInHtml (String str, [ bool isRtlContext ])

Apply bracket guard to str using html span tag. This is to address the problem of messy bracket display that frequently happens in RTL layout. If isRtlContext is true, then we explicitly want to wrap in a span of RTL directionality, regardless of the estimated directionality.


static String guardBracketInHtml(String str, [bool isRtlContext]) {
  var useRtl = isRtlContext == null ? hasAnyRtl(str) : isRtlContext;
  RegExp matchingBrackets =
      new RegExp(r'(\(.*?\)+)|(\[.*?\]+)|(\{.*?\}+)|(<.*?(>)+)');
  return _guardBracketHelper(str, matchingBrackets,
      '<span dir=${useRtl? "rtl" : "ltr"}>', '</span>');