// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   cLocaleUtils.java

package nitidus.util.locale;

import java.util.Locale;

public class cLocaleUtils
{

    public cLocaleUtils()
    {
    }

    public static Locale bestMatch(Locale locale, Locale alocale[])
    {
        Locale locale1 = null;
        for(int i = 0; i < alocale.length; i++)
        {
            Locale locale2 = alocale[i];
            if(score(locale, locale1) < score(locale, locale2))
                locale1 = locale2;
        }

        return locale1;
    }

    private static int score(Locale locale, Locale locale1)
    {
        if(locale == null || locale1 == null)
            return 0;
        int i = 0;
        if(locale.getLanguage().equals(locale1.getLanguage()))
            i += 4;
        if((locale.getCountry().trim().length() > 0 || i > 0) && locale.getCountry().equals(locale1.getCountry()))
            i += 2;
        if(i > 0 && locale.getVariant().equals(locale1.getVariant()))
            i++;
        return i;
    }

    public static Locale fromString(String s)
    {
        if(s == null || s.length() == 0)
            return null;
        String s1 = "";
        String s2 = "";
        String s3 = "";
        int i = s.indexOf('_');
        if(i == -1)
        {
            s1 = s;
        } else
        {
            s1 = s.substring(0, i);
            s = s.substring(i + 1);
            i = s.indexOf('_');
            if(i == -1)
            {
                s2 = s;
            } else
            {
                s2 = s.substring(0, i);
                s3 = s.substring(i + 1);
            }
        }
        return new Locale(s1, s2, s3);
    }
}
