code: public static int calcUtfLength(String str) {
          final int strlen = str.length();
          int utflen = 0;
          for (int i = 0; i < strlen; i++) {
              int c = str.charAt(i);
              if ((c >= 0x0001) && (c <= 0x007F)) {
                  utflen++;
              } else if (c > 0x07FF) {
                  utflen += 3;
              } else {
                  utflen += 2;
              }
          }
          return utflen;
      }
docs: Returns the length in bytes of a string's UTF-8 encoding.
  
  @param str The string to measure.
  @return The length in bytes of a string's UTF-8 encoding.