Пример #1
0
 private UTF8String toTitleCaseSlow() {
   StringBuffer sb = new StringBuffer();
   String s = toString();
   sb.append(s);
   sb.setCharAt(0, Character.toTitleCase(sb.charAt(0)));
   for (int i = 1; i < s.length(); i++) {
     if (sb.charAt(i - 1) == ' ') {
       sb.setCharAt(i, Character.toTitleCase(sb.charAt(i)));
     }
   }
   return fromString(sb.toString());
 }
  public static void decry() {
    try {
      BufferedReader bf = new BufferedReader(new FileReader("ciphertext.txt"));
      BufferedWriter wr = new BufferedWriter(new FileWriter("plaintext.txt"));
      char rkey[] = new char[26];
      for (char i = 'a'; i <= 'z'; i++) {
        if (key.charAt(i - 'a') > 'z' || key.charAt(i - 'a') < 'a') continue;
        rkey[key.charAt(i - 'a') - 'a'] = i;
      }
      System.out.println(rkey);
      StringBuffer strb;
      String str;
      while (((str = bf.readLine())) != null) {
        strb = new StringBuffer(str);
        // System.out.println(strb);
        // String ans;
        for (int i = 0; i < strb.length(); i++) {
          if (strb.charAt(i) >= 'a' && strb.charAt(i) <= 'z') {
            strb.setCharAt(i, rkey[strb.charAt(i) - 'a']);
          }
        }
        System.out.println(strb.toString());
        wr.write(strb.toString());
        wr.newLine();
      }
      // keyf.close();
      wr.close();
      bf.close();

    } catch (IOException e) {

    }
  }
Пример #3
0
  /**
   * Some String can be too long to be correctly displayed on the screen. Mainly when it is a path
   * to a file. This method truncate a String.
   *
   * @param longString The <code>String</code> to be truncated
   * @param maxLength The maximum length of the <code>String</code>
   * @return The truncated string
   */
  public static String getShortStringOf(String longString, int maxLength) {
    int len = longString.length();

    if (len <= maxLength) return longString;
    else if (longString.indexOf('\\') == -1 && longString.indexOf('/') == -1) {
      StringBuffer buff = new StringBuffer(longString.substring(longString.length() - maxLength));
      for (int i = 0; i < 3; i++) buff.setCharAt(i, '.');
      return buff.toString();
    } else {
      int first = len / 2;
      int second = first;

      for (int i = first - 1; i >= 0; i--) {
        if (longString.charAt(i) == '\\' || longString.charAt(i) == '/') {
          first = i;
          break;
        }
      }

      for (int i = second + 1; i < len; i++) {
        if (longString.charAt(i) == '\\' || longString.charAt(i) == '/') {
          second = i;
          break;
        }
      }

      loop:
      while ((len - (second - first)) > maxLength) {
        out:
        for (int i = first - 1; i >= 0; i--) {
          switch (longString.charAt(i)) {
            case '\\':
            case '/':
              first = i;
              break out;
          }
        }

        if ((len - (second - first)) < maxLength) break loop;

        out2:
        for (int i = second + 1; i < len; i++) {
          switch (longString.charAt(i)) {
            case '\\':
            case '/':
              second = i;
              break out2;
          }
        }
      }

      return longString.substring(0, first + 1) + "..." + longString.substring(second);

      // return longString.substring(0, maxLength / 2) + "..." +
      //       longString.substring(len - (maxLength / 2));
    }
  }
Пример #4
0
  boolean updateToLine(int x, int y, char ch) {
    try {
      // getLine
      StringBuffer currentLine = (StringBuffer) vectorLines.elementAt(y);

      currentLine.setCharAt(x - 1, ch);
      // setLine
      vectorLines.setElementAt(currentLine, y);

      return true;
    } catch (Exception ex) {
      System.out.println(ex.toString() + " in updateToLine()");
      return false;
    }
  }
Пример #5
0
  // identifier+: identifier* ;|}
  private int parseDeclaration() throws IOException {
    int token;

    if ((token = parseIdentifiers(':', false)) != IDENTIFIER) {
      return token;
    }
    // Make the property name to lowercase
    for (int counter = unitBuffer.length() - 1; counter >= 0; counter--) {
      unitBuffer.setCharAt(counter, Character.toLowerCase(unitBuffer.charAt(counter)));
    }
    callback.handleProperty(unitBuffer.toString());

    token = parseIdentifiers(';', true);
    callback.handleValue(unitBuffer.toString());
    return token;
  }
Пример #6
0
  /** Thanks to Teodor Danciu for this method (c) 2003 Teodor Danciu */
  public static String replaceTabWithBlank(String source) {
    String result = source;

    if (source != null && source.length() > 0) {
      StringBuffer sbuffer = new StringBuffer(source);

      int offset = 0;
      int pos = source.indexOf("\t", offset);
      while (pos >= 0) {
        sbuffer.setCharAt(pos, ' ');
        offset = pos + 1;
        pos = source.indexOf("\t", offset);
      }

      result = sbuffer.toString();
    }

    return result;
  }
Пример #7
0
 static String dirForFqcn(String fqcn) {
   int last_dot = fqcn.lastIndexOf('.');
   StringBuffer sb = new StringBuffer(fqcn.substring(0, last_dot + 1));
   for (int i = 0, len = sb.length(); i < len; ++i) if (sb.charAt(i) == '.') sb.setCharAt(i, '/');
   return sb.toString();
 }