code: public String make_id(String txt) {
      // id = string.lower()
      String id = txt.toLowerCase();
      // if not isinstance(id, unicode):
      // id = id.decode()
      // id = id.translate(_non_id_translate_digraphs)
      id = translate(id, nonIdTranslateDigraphs);
      // id = id.translate(_non_id_translate)
      id = translate(id, nonIdTranslate);
      // # get rid of non-ascii characters.
      // # 'ascii' lowercase to prevent problems with turkish locale.
      // id = unicodedata.normalize('NFKD', id).\
      // encode('ascii', 'ignore').decode('ascii')
      // # shrink runs of whitespace and replace by hyphen
      // id = _non_id_chars.sub('-', ' '.join(id.split()))
      id = id.replaceAll("\\s+", " ").replaceAll(nonIdChars, "-");
      // id = _non_id_at_ends.sub('', id)
      id = id.replaceAll(nonIdAtEnds, "");
      // return str(id)
      return id;
    }
docs: Our use case is
  {@code $ python -c "from docutils import nodes; print('term-'+nodes.make_id('QR'))" } , which
  returns {@code term-qr } i.e., identifiers conforming to the regular expression
  [a-z](-?[a-z0-9]+)*
  
  <p>
  But there is a requirement to use <em>pure</em> java for this task. So we clone the function
  here. python docutils is public domain.
  </p>
  
  @see http ://code.nabla.net/doc/docutils/api/docutils/nodes/docutils.nodes. make_id.html