예제 #1
1
  /** Takes a string and hides its extension */
  public static String hideExtension(final String str) {
    String[] arr = str.split("\\.");

    if (arr.length <= 1) return str; // there was no "." in str.

    StringBuilder sb = new StringBuilder("");
    for (int i = 0; i < arr.length - 1; ++i) {
      if (sb.length() > 0) sb.append(".");
      sb.append(arr[i]);
    }
    return sb.toString();
  }
예제 #2
1
 /**
  * Convert all special tags in a string to local URL (e.g [sprite: NameOfPony] =&gt;
  * file://path/to/local/sprite.png); allowed special tags are: sprite, type, movetype
  *
  * @return The converted string
  */
 public static String toLocalURL(final String msg) {
   StringBuilder converted = new StringBuilder();
   boolean parsingTag = false;
   boolean inTagName = true;
   StringBuilder tagName = new StringBuilder(10);
   StringBuilder tagArg = new StringBuilder(30);
   for (int i = 0; i < msg.length(); ++i) {
     char c = msg.charAt(i);
     switch (c) {
       case '[':
         if (!parsingTag) {
           parsingTag = true;
         } else {
           if (inTagName) tagName.append(c);
           else tagArg.append(c);
         }
         break;
       case ']':
         if (parsingTag) {
           parsingTag = false;
           converted.append(
               convertLocalURLTag(tagName.toString().trim(), tagArg.toString().trim()));
           tagName.setLength(0);
           tagArg.setLength(0);
           inTagName = true;
         } else {
           converted.append(c);
         }
         break;
       case ':':
         if (parsingTag) {
           if (inTagName) inTagName = false;
           else tagArg.append(c);
         } else {
           converted.append(c);
         }
         break;
       default:
         if (parsingTag) {
           if (inTagName) tagName.append(c);
           else tagArg.append(c);
         } else {
           converted.append(c);
         }
     }
   }
   return converted.toString();
 }