docs: private static void htmlEncode(final CharSequence unsafeStr, final boolean turnNewlineIntoBreak,
              final StringBuilder buf) {
          for (int i = 0, n = unsafeStr.length(); i < n; i++) {
              final char c = unsafeStr.charAt(i);
              switch (c) {
              case '&':
                  buf.append("&amp;");
                  break;
              case '<':
                  buf.append("&lt;");
                  break;
              case '>':
                  buf.append("&gt;");
                  break;
              case '"':
                  buf.append("&quot;");
                  break;
              case '\'':
                  buf.append("&#x27;"); // See http://goo.gl/FzoP6m
                  break;
              case '\\':
                  buf.append("&lsol;");
                  break;
              case '/':
                  buf.append("&#x2F;"); // '/' can be a dangerous char if attr values are not quoted
                  break;
              // Encode a few common characters that like to get screwed up in some charset/browser variants
              case '—':
                  buf.append("&mdash;");
                  break;
              case '–':
                  buf.append("&ndash;");
                  break;
              case '“':
                  buf.append("&ldquo;");
                  break;
              case '”':
                  buf.append("&rdquo;");
                  break;
              case '‘':
                  buf.append("&lsquo;");
                  break;
              case '’':
                  buf.append("&rsquo;");
                  break;
              case '«':
                  buf.append("&laquo;");
                  break;
              case '»':
                  buf.append("&raquo;");
                  break;
              case '£':
                  buf.append("&pound;");
                  break;
              case '©':
                  buf.append("&copy;");
                  break;
              case '®':
                  buf.append("&reg;");
                  break;
              case (char) 0x00A0:
                  buf.append("&nbsp;");
                  break;
              case '\n':
                  if (turnNewlineIntoBreak) {
                      buf.append("<br>");
                  } else {
                      buf.append(' '); // Newlines function as whitespace in HTML text
                  }
                  break;
              default:
                  if (c <= 32 || isUnicodeWhitespace(c)) {
                      buf.append(' ');
                  } else {
                      buf.append(c);
                  }
                  break;
              }
          }
      }