package org.supercsv.ext;

import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;


/**
 * @author T.TSUCHIE
 *
 */
public class Utils {
    
    public static String join(final String[] arrays, final String seperator) {
        
        final int len = arrays.length;
        if(arrays == null || len == 0) {
            return "";
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i=0; i < len; i++) {
            sb.append(arrays[i]);
            
            if(seperator != null && (i < len-1)) {
                sb.append(seperator);
            }
        }
        
        return sb.toString();
        
    }
    
    public static String join(final Collection<?> col, final String seperator) {
        
        final int size = col.size();
        if(col == null || size == 0) {
            return "";
        }
        
        StringBuilder sb = new StringBuilder();
        for(Iterator<?> itr = col.iterator(); itr.hasNext();) {
            final Object item = itr.next();
            sb.append(item.toString());
            
            if(seperator != null && itr.hasNext()) {
                sb.append(seperator);
            }
        }
        
        return sb.toString();
        
    }
    
    public static boolean isEmpty(final String value) {
        if(value == null || value.isEmpty()) {
            return true;
        }
        
        return false;
    }
    
    /**
     * `̃P[IuWFNgɕϊB
     * <p>A_[o[ŋ؂'ja_JP'𕪉āALocaleɓnB
     * @since 1.2
     * @param str
     * @return ̎̓ftHgP[ԂB
     */
    public static Locale getLocale(final String str) {
        
        if(isEmpty(str)) {
            return Locale.getDefault();
        }
        
        if(!str.contains("_")) {
            return new Locale(str);
        }
        
        final String[] split = str.split("_");
        if(split.length == 2) {
            return new Locale(split[0], split[1]);
            
        } else {
            return new Locale(split[0], split[1], split[2]);
        }
        
    }
}

@@ -1465,58 +1465,76 @@
   * 
-%60%CC%83P%5BIuWFNg%C9%95%CF%8AB%0A     * %3Cp%3EA_%5Bo%5B%C5%8B%D8%82
+%E6%96%87%E5%AD%97%E5%88%97%E5%BD%A2%E5%BC%8F%E3%81%AE%E3%83%AD%E3%82%B1%E3%83%BC%E3%83%AB%E3%82%92%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AB%E5%A4%89%E6%8F%9B%E3%81%99%E3%82%8B%E3%80%82%0A     * %3Cp%3E%E3%82%A2%E3%83%B3%E3%83%80%E3%83%BC%E3%83%90%E3%83%BC%E3%81%A7%E5%8C%BA%E5%88%87%E3%81%A3%E3%81%9F
 'ja_JP'
-%F0%95%AA%89%C4%81A
+%E3%82%92%E5%88%86%E8%A7%A3%E3%81%97%E3%81%A6%E3%80%81
 Locale
-%C9%93nB
+%E3%81%AB%E6%B8%A1%E3%81%99%E3%80%82
 %0A   
@@ -1585,18 +1585,28 @@
 urn 
-%CC%8E%CD%83ftHgP%5B%D4%82B
+%E5%BC%95%E6%95%B0%E3%81%8C%E7%A9%BA%E3%81%AE%E6%99%82%E3%81%AF%E3%83%87%E3%83%95%E3%82%A9%E3%83%AB%E3%83%88%E3%83%AD%E3%82%B1%E3%83%BC%E3%83%AB%E3%82%92%E8%BF%94%E3%81%99%E3%80%82
 %0A   

fix encoding