Material localization support
[debian/openrocket] / core / src / net / sf / openrocket / l10n / L10N.java
index 878b3c41c3b5e64868045fc3e99d1585f3f9c889..351873bedc815493ebe075242df4904c91b70976 100644 (file)
@@ -1,8 +1,11 @@
 package net.sf.openrocket.l10n;
 
+import java.text.Normalizer;
 import java.util.Locale;
 import java.util.regex.Pattern;
 
+import net.sf.openrocket.util.Chars;
+
 /**
  * Helper methods for localization needs.
  * 
@@ -54,4 +57,27 @@ public final class L10N {
                return l;
        }
        
+       
+       public static String normalize(String text) {
+               text = Normalizer.normalize(text, Normalizer.Form.NFKD);
+               text = text.toLowerCase();
+               text = text.replaceAll("\\s+", " ");
+               text = text.trim();
+               
+               StringBuilder sb = new StringBuilder(text.length());
+               for (char c : text.toCharArray()) {
+                       if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) {
+                               sb.append(c);
+                       } else if (c == ' ' || c == '/' || c == Chars.FRACTION) {
+                               sb.append('_');
+                       }
+               }
+               text = sb.toString();
+               
+               text = text.replaceAll("^_+", "");
+               text = text.replaceAll("_+$", "");
+               
+               return text;
+       }
+       
 }