Beispiel #1
0
 private static String firstCharOnlyToUpper(String word) {
   return (word.isEmpty())
       ? word
       : new StringBuilder(word.length())
           .append(Ascii.toUpperCase(word.charAt(0)))
           .append(Ascii.toLowerCase(word.substring(1)))
           .toString();
 }
Beispiel #2
0
 @Override
 String convert(CaseFormat format, String s) {
   if (format == LOWER_HYPHEN) {
     return Ascii.toLowerCase(s.replace('_', '-'));
   }
   if (format == LOWER_UNDERSCORE) {
     return Ascii.toLowerCase(s);
   }
   return super.convert(format, s);
 }
Beispiel #3
0
 @Override
 String convert(CaseFormat format, String s) {
   if (format == LOWER_UNDERSCORE) {
     return s.replace('-', '_');
   }
   if (format == UPPER_UNDERSCORE) {
     return Ascii.toUpperCase(s.replace('-', '_'));
   }
   return super.convert(format, s);
 }
Beispiel #4
0
  /**
   * Returns true if the message bytes starts with the specified string.
   *
   * @param s the string
   * @param pos The start position
   */
  public boolean startsWithIgnoreCase(String s, int pos) {
    switch (type) {
      case T_STR:
        if (strValue == null) return false;
        if (strValue.length() < pos + s.length()) return false;

        for (int i = 0; i < s.length(); i++) {
          if (Ascii.toLower(s.charAt(i)) != Ascii.toLower(strValue.charAt(pos + i))) {
            return false;
          }
        }
        return true;
      case T_CHARS:
        return charC.startsWithIgnoreCase(s, pos);
      case T_BYTES:
        return byteC.startsWithIgnoreCase(s, pos);
      default:
        return false;
    }
  }
Beispiel #5
0
 // hash ignoring case
 private int hashIgnoreCase() {
   int code = 0;
   switch (type) {
     case T_STR:
       for (int i = 0; i < strValue.length(); i++) {
         code = code * 37 + Ascii.toLower(strValue.charAt(i));
       }
       return code;
     case T_CHARS:
       return charC.hashIgnoreCase();
     case T_BYTES:
       return byteC.hashIgnoreCase();
     default:
       return 0;
   }
 }
Beispiel #6
0
  /**
   * Returns numeric value (as bytes) from an input hex array.
   *
   * <p>Example :
   *
   * <pre>
   *  Input  : (byte)0x61,(byte)0x62,(byte)0x33,(byte)0x34,(byte)0x35,(byte)0x36,(byte)0x41,(byte)0x42 ( i.e. 12345678 )
   *  Output : (byte)0x0A,(byte)0x0B,(byte)0x03,(byte)0x04,(byte)0x05,(byte)0x06,(byte)0x0A,(byte)0x0B
   * </pre>
   *
   * @param blkIN input Ascii numeric byte array
   * @return numeric value as bytes
   * @exception java.lang.IllegalArgumentException if an illegal value arrives
   */
  public static byte[] getNumericValue(byte[] blkIN) throws IllegalArgumentException {

    if (!Ascii.isNumericHex(blkIN))
      throw new IllegalArgumentException(
          "Ascii.getNumericValue - is not an numeric (hex) byte array");
    byte[] blkdummy = new byte[blkIN.length];
    for (int i = 0; i < blkIN.length; i++) {
      byte abyte = blkIN[i];
      if (abyte >= 0x30 && abyte <= 0x39) {
        blkdummy[i] = (byte) (blkIN[i] - 0x30); // for '0' to '9'
      } else if (abyte >= 0x41 && abyte <= 0x46) {
        blkdummy[i] = (byte) (blkIN[i] - 0x41 + 0x0A); // for 'A' to 'F'
      } else if (abyte >= 0x61 && abyte <= 0x66) {
        blkdummy[i] = (byte) (blkIN[i] - 0x61 + 0x0A); // for 'a' to 'f'
      }
    }
    return blkdummy;
  }
Beispiel #7
0
 @Override
 String normalizeWord(String word) {
   return Ascii.toUpperCase(word);
 }
Beispiel #8
0
 private String normalizeFirstWord(String word) {
   return (this == LOWER_CAMEL) ? Ascii.toLowerCase(word) : normalizeWord(word);
 }