Use lime.system.Locale instead of a new Language enum

This commit is contained in:
Joshua Granick
2018-10-31 15:12:14 -07:00
parent 0a08a82d0c
commit 344fb75bf8

View File

@@ -4,6 +4,7 @@ package lime.text;
import haxe.Utf8;
import lime._internal.unifill.Unifill;
import lime._internal.unifill.CodePoint;
import lime.system.Locale;
abstract UTF8String(String) from String to String {
@@ -212,9 +213,7 @@ abstract UTF8String(String) from String to String {
If `language` is specified, language-specific casing rules will be followed.
**/
public function toLowerCase (language:Language=null):String {
if(language == null) language = STANDARD;
public function toLowerCase (locale:Locale = null):String {
#if sys
@@ -229,9 +228,9 @@ abstract UTF8String(String) from String to String {
Utf8.iter (this, function (v) {
if(language != STANDARD)
if (language != null)
{
var v2 = toLowerCaseLanguageFixes(v,language);
var v2 = toLowerCaseLocaleFixes (v, locale);
if (v2 != v)
{
r.addChar (v2);
@@ -252,11 +251,12 @@ abstract UTF8String(String) from String to String {
}
private static function toLowerCaseLanguageFixes(v:Int,language:Language):Int
private static function toLowerCaseLocaleFixes (v:Int, locale:Locale):Int
{
return switch(language)
return switch (locale.language)
{
case TURKISH:
case "tr":
switch (v)
{
case 0xC4B0: 0x69; //İ-->i (large dotted İ to small i) //probably redundant and can be removed, presented here for logical symmtery for when genuine cases are needed
@@ -266,6 +266,7 @@ abstract UTF8String(String) from String to String {
}
}
/**
Returns the String itself.
**/
@@ -283,9 +284,7 @@ abstract UTF8String(String) from String to String {
If `language` is specified, language-specific casing rules will be followed.
**/
public function toUpperCase (language:Language=null):String {
if(language == null) language = STANDARD;
public function toUpperCase (locale:Locale = null):String {
#if sys
@@ -300,9 +299,9 @@ abstract UTF8String(String) from String to String {
Utf8.iter (this, function (v) {
if(language != STANDARD)
if (locale != null)
{
var v2 = toUpperCaseLanguageFixes(v,language);
var v2 = toUpperCaseLocaleFixes (v, locale);
if (v2 != v)
{
r.addChar (v2);
@@ -323,11 +322,12 @@ abstract UTF8String(String) from String to String {
}
private static function toUpperCaseLanguageFixes(v:Int,language:Language):Int
private static function toUpperCaseLocaleFixes (v:Int, locale:Locale):Int
{
return switch(language)
return switch (locale.language)
{
case TURKISH:
case "tr":
switch (v)
{
case 0x69: 0xC4B0; //i-->İ (small i to large dotted İ)
@@ -802,10 +802,3 @@ for (i in 0...32) map[0x118C0+i] = 0x118A0+i;
for (i in 0...34) map[0x1E922+i] = 0x1E900+i;
}
}
enum Language
{
STANDARD; //any language that doesn't have surprising results with casing
TURKISH; //turkish
//add more special case languages as necessary
}