All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.commons.util.GlobUtils Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.commons.util;

/**
 * Utility functions for globs
 *
 * @author Tristan Tarrant
 * @since 9.2
 */

public final class GlobUtils {

   public static boolean isGlob(String s) {
      if (s == null) {
         return false;
      }
      for(int i = 0; i < s.length(); i++) {
         char ch = s.charAt(i);
         if (ch == '*' || ch == '?') {
            return true;
         }
      }
      return false;
   }

   public static String globToRegex(String glob) {
      StringBuilder s = new StringBuilder();
      for(int i = 0; i < glob.length(); i++) {
         final char c = glob.charAt(i);
         switch(c) {
            case '*':
               s.append(".*");
               break;
            case '?':
               s.append('.');
               break;
            case '.':
               s.append("\\.");
               break;
            case '\\':
               s.append("\\\\");
               break;
            default:
               s.append(c);
         }
      }
      return s.toString();

   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy