code: @Override
      public String toReplacerPattern(boolean escapeUnprintable) {
          StringBuffer rule = new StringBuffer();
          StringBuffer quoteBuf = new StringBuffer();
  
          int cursor = cursorPos;
  
          // Handle a cursor preceding the output
          if (hasCursor && cursor < 0) {
              while (cursor++ < 0) {
                  Utility.appendToRule(rule, '@', true, escapeUnprintable, quoteBuf);
              }
              // Fall through and append '|' below
          }
  
          for (int i=0; i<output.length(); ++i) {
              if (hasCursor && i == cursor) {
                  Utility.appendToRule(rule, '|', true, escapeUnprintable, quoteBuf);
              }
              char c = output.charAt(i); // Ok to use 16-bits here
  
              UnicodeReplacer r = data.lookupReplacer(c);
              if (r == null) {
                  Utility.appendToRule(rule, c, false, escapeUnprintable, quoteBuf);
              } else {
                  StringBuffer buf = new StringBuffer(" ");
                  buf.append(r.toReplacerPattern(escapeUnprintable));
                  buf.append(' ');
                  Utility.appendToRule(rule, buf.toString(),
                                       true, escapeUnprintable, quoteBuf);
              }
          }
  
          // Handle a cursor after the output.  Use > rather than >= because
          // if cursor == output.length() it is at the end of the output,
          // which is the default position, so we need not emit it.
          if (hasCursor && cursor > output.length()) {
              cursor -= output.length();
              while (cursor-- > 0) {
                  Utility.appendToRule(rule, '@', true, escapeUnprintable, quoteBuf);
              }
              Utility.appendToRule(rule, '|', true, escapeUnprintable, quoteBuf);
          }
          // Flush quoteBuf out to result
          Utility.appendToRule(rule, -1,
                               true, escapeUnprintable, quoteBuf);
  
          return rule.toString();
      }
docs: UnicodeReplacer API