static int transformDictionaryWord(byte[] dst, int dstOffset, byte[] word, int wordOffset,
      int len, Transform transform) {
    int offset = dstOffset;

    // Copy prefix.
    byte[] string = transform.prefix;
    int tmp = string.length;
    int i = 0;
    // In most cases tmp < 10 -> no benefits from System.arrayCopy
    while (i < tmp) {
      dst[offset++] = string[i++];
    }

    // Copy trimmed word.
    int op = transform.type;
    tmp = WordTransformType.getOmitFirst(op);
    if (tmp > len) {
      tmp = len;
    }
    wordOffset += tmp;
    len -= tmp;
    len -= WordTransformType.getOmitLast(op);
    i = len;
    while (i > 0) {
      dst[offset++] = word[wordOffset++];
      i--;
    }

    if (op == UPPERCASE_ALL || op == UPPERCASE_FIRST) {
      int uppercaseOffset = offset - len;
      if (op == UPPERCASE_FIRST) {
        len = 1;
      }
      while (len > 0) {
        tmp = dst[uppercaseOffset] & 0xFF;
        if (tmp < 0xc0) {
          if (tmp >= 'a' && tmp <= 'z') {
            dst[uppercaseOffset] ^= (byte) 32;
          }
          uppercaseOffset += 1;
          len -= 1;
        } else if (tmp < 0xe0) {
          dst[uppercaseOffset + 1] ^= (byte) 32;
          uppercaseOffset += 2;
          len -= 2;
        } else {
          dst[uppercaseOffset + 2] ^= (byte) 5;
          uppercaseOffset += 3;
          len -= 3;
        }
      }
    }

    // Copy suffix.
    string = transform.suffix;
    tmp = string.length;
    i = 0;
    while (i < tmp) {
      dst[offset++] = string[i++];
    }

    return offset - dstOffset;
  }
@Test
  public void testCapitalize() {
    byte[] output = new byte[8];
    byte[] input = "qæप".getBytes(StandardCharsets.UTF_8);
    Transform transform = new Transform("[", WordTransformType.UPPERCASE_ALL, "]");
    Transform.transformDictionaryWord(output, 0, input, 0, input.length, transform);
    assertArrayEquals(output, "[QÆय]".getBytes(StandardCharsets.UTF_8));
  }